From: Junio C Hamano Date: Mon, 28 Oct 2013 17:43:24 +0000 (-0700) Subject: Merge branch 'ew/keepalive' X-Git-Tag: v1.8.5-rc0~23 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/bb2fd90c7bbb4261aa1800a4c35b06dc5116a647?hp=--cc Merge branch 'ew/keepalive' * ew/keepalive: http: use curl's tcp keepalive if available http: enable keepalive on TCP sockets --- bb2fd90c7bbb4261aa1800a4c35b06dc5116a647 diff --cc http.c index f3e1439d58,6359526196..0ddb164a6f --- a/http.c +++ b/http.c @@@ -249,17 -219,56 +249,53 @@@ static void init_curl_http_auth(CURL *r static int has_cert_password(void) { - if (ssl_cert_password != NULL) - return 1; if (ssl_cert == NULL || ssl_cert_password_required != 1) return 0; - /* Only prompt the user once. */ - ssl_cert_password_required = -1; - ssl_cert_password = git_getpass("Certificate Password: "); - if (ssl_cert_password != NULL) { - ssl_cert_password = xstrdup(ssl_cert_password); - return 1; - } else - return 0; + if (!cert_auth.password) { + cert_auth.protocol = xstrdup("cert"); + cert_auth.username = xstrdup(""); + cert_auth.path = xstrdup(ssl_cert); + credential_fill(&cert_auth); + } + 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(); @@@ -322,16 -331,11 +358,18 @@@ if (curl_ftp_no_epsv) curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0); - if (curl_http_proxy) +#ifdef CURLOPT_USE_SSL + if (curl_ssl_try) + curl_easy_setopt(result, CURLOPT_USE_SSL, CURLUSESSL_TRY); +#endif + + if (curl_http_proxy) { curl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy); + curl_easy_setopt(result, CURLOPT_PROXYAUTH, CURLAUTH_ANY); + } + set_curl_keepalive(result); + return result; }