diff mbox series

[v2,8/8] http: don't hardcode the value of CURL_SOCKOPT_OK

Message ID patch-v2-8.8-465ab33ebda-20210910T105523Z-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. 10, 2021, 11:04 a.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 | 16 ++++++++++++++++
 http.c            |  2 +-
 2 files changed, 17 insertions(+), 1 deletion(-)

Comments

Jeff King Sept. 10, 2021, 3:17 p.m. UTC | #1
On Fri, Sep 10, 2021 at 01:04:33PM +0200, Ævar Arnfjörð Bjarmason wrote:

> 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).

Thanks for splitting this one out. I agree it's unlike the rest.

> +/**
> + * CURL_SOCKOPT_OK was added in 7.21.5, released in April 2011.
> + *
> + * This should be safe as CURL_SOCKOPT_OK has always been a macro, not
> + * an enum field (checked on curl version 7.78.0, released on July 19,
> + * 2021). Even if that were to change the value of "0" for "OK" is
> + * unlikely to change.
> + */
> +#ifndef CURL_SOCKOPT_OK
> +#define CURL_SOCKOPT_OK 0
> +#endif

I agree this is probably fine if it later becomes an enum. But it would
be easy enough to just do the version-number check here, wouldn't it?
That would be even safer, and using the #ifndef doesn't really buy us
much. We still have to annotate the version and date in a comment as you
did, because we want to know when it is time to drop support.

-Peff
diff mbox series

Patch

diff --git a/git-curl-compat.h b/git-curl-compat.h
index 7ad87e89ed5..3d162730aaf 100644
--- a/git-curl-compat.h
+++ b/git-curl-compat.h
@@ -20,10 +20,26 @@ 
  * GIT_CURL_HAVE_X. If multiple similar symbols with the same prefix
  * were defined in the same version we pick one and check for that name.
  *
+ * 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.
+ *
  * Keep any symbols in date order of when their support was
  * introduced, oldest first, in the official version of cURL library.
  */
 
+/**
+ * CURL_SOCKOPT_OK was added in 7.21.5, released in April 2011.
+ *
+ * This should be safe as CURL_SOCKOPT_OK has always been a macro, not
+ * an enum field (checked on curl version 7.78.0, released on July 19,
+ * 2021). Even if that were to change the value of "0" for "OK" is
+ * unlikely to change.
+ */
+#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 94eefe97089..d7c20493d7f 100644
--- a/http.c
+++ b/http.c
@@ -537,7 +537,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)