summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-10-28 10:43:24 -0700
committerJunio C Hamano <gitster@pobox.com>2013-10-28 10:43:24 -0700
commitbb2fd90c7bbb4261aa1800a4c35b06dc5116a647 (patch)
tree74073fb08244782e90ebd71ba7e1ab6f4bdc8266
parent2d99baab2f054926a1b26f7854fc50b701151bd7 (diff)
parent47ce115370cba8ebfced696f9997e718c465435d (diff)
downloadgit-bb2fd90c7bbb4261aa1800a4c35b06dc5116a647.tar.gz
Merge branch 'ew/keepalive'
* ew/keepalive: http: use curl's tcp keepalive if available http: enable keepalive on TCP sockets
-rw-r--r--http.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/http.c b/http.c
index f3e1439d58..0ddb164a6f 100644
--- a/http.c
+++ b/http.c
@@ -260,6 +260,42 @@ static int has_cert_password(void)
return 1;
}
+#if LIBCURL_VERSION_NUM >= 0x071900
+static void set_curl_keepalive(CURL *c)
+{
+ curl_easy_setopt(c, CURLOPT_TCP_KEEPALIVE, 1);
+}
+
+#elif LIBCURL_VERSION_NUM >= 0x071000
+static int sockopt_callback(void *client, curl_socket_t fd, curlsocktype type)
+{
+ int ka = 1;
+ int rc;
+ socklen_t len = (socklen_t)sizeof(ka);
+
+ if (type != CURLSOCKTYPE_IPCXN)
+ return 0;
+
+ rc = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&ka, len);
+ if (rc < 0)
+ warning("unable to set SO_KEEPALIVE on socket %s",
+ strerror(errno));
+
+ return 0; /* CURL_SOCKOPT_OK only exists since curl 7.21.5 */
+}
+
+static void set_curl_keepalive(CURL *c)
+{
+ curl_easy_setopt(c, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
+}
+
+#else
+static void set_curl_keepalive(CURL *c)
+{
+ /* not supported on older curl versions */
+}
+#endif
+
static CURL *get_curl_handle(void)
{
CURL *result = curl_easy_init();
@@ -332,6 +368,8 @@ static CURL *get_curl_handle(void)
curl_easy_setopt(result, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
}
+ set_curl_keepalive(result);
+
return result;
}