diff mbox series

[5/5] http: don't hardcode the value of CURL_SOCKOPT_OK

Message ID patch-5.5-4f42c0e48b0-20210908T152807Z-avarab@gmail.com (mailing list archive)
State Superseded
Headers show
Series post-v2.33 "drop support for ancient curl" follow-up | expand

Commit Message

Ævar Arnfjörð Bjarmason Sept. 8, 2021, 3:31 p.m. UTC
Use the new git-curl-compat.h header to define CURL_SOCKOPT_OK to its
known value if we're on an older curl version that doesn't have it. It
was hardcoded in http.c in a15d069a198 (http: enable keepalive on TCP
sockets, 2013-10-12).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 git-curl-compat.h | 11 +++++++++++
 http.c            |  2 +-
 2 files changed, 12 insertions(+), 1 deletion(-)

Comments

Junio C Hamano Sept. 9, 2021, 11:15 p.m. UTC | #1
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> +/**
> + * CURL_SOCKOPT_OK was added in 7.21.5, released in April 2011.
> + */
> +#ifndef CURL_SOCKOPT_OK
> +#define CURL_SOCKOPT_OK 0
> +#endif
> +
>  /**
>   * CURLOPT_TCP_KEEPALIVE was added in 7.25.0, released in March 2012.
>   */
> diff --git a/http.c b/http.c
> index e38fcc34d64..c40439d39ce 100644
> --- a/http.c
> +++ b/http.c
> @@ -533,7 +533,7 @@ static int sockopt_callback(void *client, curl_socket_t fd, curlsocktype type)
>  	if (rc < 0)
>  		warning_errno("unable to set SO_KEEPALIVE on socket");
>  
> -	return 0; /* CURL_SOCKOPT_OK only exists since curl 7.21.5 */
> +	return CURL_SOCKOPT_OK;
>  }

This is much better than the one in the previous round where an
extra CPP macro with GIT_CURL_SOCKOPT_OK_AVAILABLE or some other
name was used to conditionally return 0 or CURL_SOCKOPT_OK.
Junio C Hamano Sept. 9, 2021, 11:22 p.m. UTC | #2
Junio C Hamano <gitster@pobox.com> writes:

> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>
>> +/**
>> + * CURL_SOCKOPT_OK was added in 7.21.5, released in April 2011.
>> + */
>> +#ifndef CURL_SOCKOPT_OK
>> +#define CURL_SOCKOPT_OK 0
>> +#endif
>> +
>>  /**
>>   * CURLOPT_TCP_KEEPALIVE was added in 7.25.0, released in March 2012.
>>   */
>> diff --git a/http.c b/http.c
>> index e38fcc34d64..c40439d39ce 100644
>> --- a/http.c
>> +++ b/http.c
>> @@ -533,7 +533,7 @@ static int sockopt_callback(void *client, curl_socket_t fd, curlsocktype type)
>>  	if (rc < 0)
>>  		warning_errno("unable to set SO_KEEPALIVE on socket");
>>  
>> -	return 0; /* CURL_SOCKOPT_OK only exists since curl 7.21.5 */
>> +	return CURL_SOCKOPT_OK;
>>  }
>
> This is much better than the one in the previous round where an
> extra CPP macro with GIT_CURL_SOCKOPT_OK_AVAILABLE or some other
> name was used to conditionally return 0 or CURL_SOCKOPT_OK.

I hit <send> a bit too early.

Because the git-curl-compat.h header file is primarily to hold the
GIT_CURL_HAVE_CURL_BLAH CPP macros, the fallback definition of
CURL_SOCKOPT_OK added by this patch looks somewhat out of place.
Doing so in http.c would be perfectly OK, though.
diff mbox series

Patch

diff --git a/git-curl-compat.h b/git-curl-compat.h
index 2bba7adefa6..bfa85711511 100644
--- a/git-curl-compat.h
+++ b/git-curl-compat.h
@@ -17,6 +17,10 @@ 
  * GIT_CURL_HAVE_X_and_Y, where the "Y" in "X_and_Y" is only the part
  * of the symbol name that "X" and "Y" don't have in common.
  *
+ * We may also define a missing CURL_* symbol to its known value, if
+ * doing so is sufficient to add support for it to older versions that
+ * don't have it.
+ *
  * We avoid comparisons against LIBCURL_VERSION_NUM, enterprise
  * distros have been known to backport symbols to their older curl
  * versions.
@@ -25,6 +29,13 @@ 
  * introduced, oldest first, in the official version of cURL library.
  */
 
+/**
+ * CURL_SOCKOPT_OK was added in 7.21.5, released in April 2011.
+ */
+#ifndef CURL_SOCKOPT_OK
+#define CURL_SOCKOPT_OK 0
+#endif
+
 /**
  * CURLOPT_TCP_KEEPALIVE was added in 7.25.0, released in March 2012.
  */
diff --git a/http.c b/http.c
index e38fcc34d64..c40439d39ce 100644
--- a/http.c
+++ b/http.c
@@ -533,7 +533,7 @@  static int sockopt_callback(void *client, curl_socket_t fd, curlsocktype type)
 	if (rc < 0)
 		warning_errno("unable to set SO_KEEPALIVE on socket");
 
-	return 0; /* CURL_SOCKOPT_OK only exists since curl 7.21.5 */
+	return CURL_SOCKOPT_OK;
 }
 
 static void set_curl_keepalive(CURL *c)