http: use curl's tcp keepalive if available
Commita15d069
taught git to use curl's SOCKOPTFUNCTION hook to turn on TCP keepalives. However, modern versions of curl have a TCP_KEEPALIVE option, which can do this for us. As an added bonus, the curl code knows how to turn on keepalive for a much wider variety of platforms. The only downside to using this option is that not everybody has a new enough curl. Let's split our keepalive options into three conditionals: 1. With curl 7.25.0 and newer, we rely on curl to do it right. 2. With older curl that still knows SOCKOPTFUNCTION, we use the code froma15d069
. 3. Otherwise, we are out of luck, and the call is a no-op. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
a15d069a19
commit
47ce115370
24
http.c
24
http.c
@ -233,7 +233,13 @@ static int has_cert_password(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* curl 7.25.0 has CURLOPT_TCP_KEEPALIVE, too, but we support older curl */
|
#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)
|
static int sockopt_callback(void *client, curl_socket_t fd, curlsocktype type)
|
||||||
{
|
{
|
||||||
int ka = 1;
|
int ka = 1;
|
||||||
@ -251,6 +257,18 @@ static int sockopt_callback(void *client, curl_socket_t fd, curlsocktype type)
|
|||||||
return 0; /* CURL_SOCKOPT_OK only exists since curl 7.21.5 */
|
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)
|
static CURL *get_curl_handle(void)
|
||||||
{
|
{
|
||||||
CURL *result = curl_easy_init();
|
CURL *result = curl_easy_init();
|
||||||
@ -316,9 +334,7 @@ static CURL *get_curl_handle(void)
|
|||||||
if (curl_http_proxy)
|
if (curl_http_proxy)
|
||||||
curl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy);
|
curl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy);
|
||||||
|
|
||||||
#if LIBCURL_VERSION_NUM >= 0x071000
|
set_curl_keepalive(result);
|
||||||
curl_easy_setopt(result, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user