@@ -104,6 +104,10 @@ static struct {
104
104
};
105
105
#endif
106
106
107
+ static long curl_tcp_keepidle = -1 ;
108
+ static long curl_tcp_keepintvl = -1 ;
109
+ static long curl_tcp_keepcnt = -1 ;
110
+
107
111
enum proactive_auth {
108
112
PROACTIVE_AUTH_NONE = 0 ,
109
113
PROACTIVE_AUTH_IF_CREDENTIALS ,
@@ -438,11 +442,11 @@ static int http_options(const char *var, const char *value,
438
442
return 0 ;
439
443
}
440
444
if (!strcmp ("http.lowspeedlimit" , var )) {
441
- curl_low_speed_limit = ( long ) git_config_int (var , value , ctx -> kvi );
445
+ curl_low_speed_limit = git_config_int (var , value , ctx -> kvi );
442
446
return 0 ;
443
447
}
444
448
if (!strcmp ("http.lowspeedtime" , var )) {
445
- curl_low_speed_time = ( long ) git_config_int (var , value , ctx -> kvi );
449
+ curl_low_speed_time = git_config_int (var , value , ctx -> kvi );
446
450
return 0 ;
447
451
}
448
452
@@ -557,6 +561,19 @@ static int http_options(const char *var, const char *value,
557
561
return 0 ;
558
562
}
559
563
564
+ if (!strcmp ("http.keepaliveidle" , var )) {
565
+ curl_tcp_keepidle = git_config_int (var , value , ctx -> kvi );
566
+ return 0 ;
567
+ }
568
+ if (!strcmp ("http.keepaliveinterval" , var )) {
569
+ curl_tcp_keepintvl = git_config_int (var , value , ctx -> kvi );
570
+ return 0 ;
571
+ }
572
+ if (!strcmp ("http.keepalivecount" , var )) {
573
+ curl_tcp_keepcnt = git_config_int (var , value , ctx -> kvi );
574
+ return 0 ;
575
+ }
576
+
560
577
/* Fall back on the default ones */
561
578
return git_default_config (var , value , ctx , data );
562
579
}
@@ -704,11 +721,6 @@ static int has_proxy_cert_password(void)
704
721
return 1 ;
705
722
}
706
723
707
- static void set_curl_keepalive (CURL * c )
708
- {
709
- curl_easy_setopt (c , CURLOPT_TCP_KEEPALIVE , 1 );
710
- }
711
-
712
724
/* Return 1 if redactions have been made, 0 otherwise. */
713
725
static int redact_sensitive_header (struct strbuf * header , size_t offset )
714
726
{
@@ -1242,7 +1254,18 @@ static CURL *get_curl_handle(void)
1242
1254
}
1243
1255
init_curl_proxy_auth (result );
1244
1256
1245
- set_curl_keepalive (result );
1257
+ curl_easy_setopt (result , CURLOPT_TCP_KEEPALIVE , 1 );
1258
+
1259
+ if (curl_tcp_keepidle > -1 )
1260
+ curl_easy_setopt (result , CURLOPT_TCP_KEEPIDLE ,
1261
+ curl_tcp_keepidle );
1262
+ if (curl_tcp_keepintvl > -1 )
1263
+ curl_easy_setopt (result , CURLOPT_TCP_KEEPINTVL ,
1264
+ curl_tcp_keepintvl );
1265
+ #ifdef GIT_CURL_HAVE_CURLOPT_TCP_KEEPCNT
1266
+ if (curl_tcp_keepcnt > -1 )
1267
+ curl_easy_setopt (result , CURLOPT_TCP_KEEPCNT , curl_tcp_keepcnt );
1268
+ #endif
1246
1269
1247
1270
return result ;
1248
1271
}
@@ -1256,10 +1279,30 @@ static void set_from_env(char **var, const char *envname)
1256
1279
}
1257
1280
}
1258
1281
1282
+ static void set_long_from_env (long * var , const char * envname )
1283
+ {
1284
+ const char * val = getenv (envname );
1285
+ if (val ) {
1286
+ long tmp ;
1287
+ char * endp ;
1288
+ int saved_errno = errno ;
1289
+
1290
+ errno = 0 ;
1291
+ tmp = strtol (val , & endp , 10 );
1292
+
1293
+ if (errno )
1294
+ warning_errno (_ ("failed to parse %s" ), envname );
1295
+ else if (* endp || endp == val )
1296
+ warning (_ ("failed to parse %s" ), envname );
1297
+ else
1298
+ * var = tmp ;
1299
+
1300
+ errno = saved_errno ;
1301
+ }
1302
+ }
1303
+
1259
1304
void http_init (struct remote * remote , const char * url , int proactive_auth )
1260
1305
{
1261
- char * low_speed_limit ;
1262
- char * low_speed_time ;
1263
1306
char * normalized_url ;
1264
1307
struct urlmatch_config config = URLMATCH_CONFIG_INIT ;
1265
1308
@@ -1338,12 +1381,8 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)
1338
1381
1339
1382
set_from_env (& user_agent , "GIT_HTTP_USER_AGENT" );
1340
1383
1341
- low_speed_limit = getenv ("GIT_HTTP_LOW_SPEED_LIMIT" );
1342
- if (low_speed_limit )
1343
- curl_low_speed_limit = strtol (low_speed_limit , NULL , 10 );
1344
- low_speed_time = getenv ("GIT_HTTP_LOW_SPEED_TIME" );
1345
- if (low_speed_time )
1346
- curl_low_speed_time = strtol (low_speed_time , NULL , 10 );
1384
+ set_long_from_env (& curl_low_speed_limit , "GIT_HTTP_LOW_SPEED_LIMIT" );
1385
+ set_long_from_env (& curl_low_speed_time , "GIT_HTTP_LOW_SPEED_TIME" );
1347
1386
1348
1387
if (curl_ssl_verify == -1 )
1349
1388
curl_ssl_verify = 1 ;
@@ -1370,6 +1409,10 @@ void http_init(struct remote *remote, const char *url, int proactive_auth)
1370
1409
ssl_cert_password_required = 1 ;
1371
1410
}
1372
1411
1412
+ set_long_from_env (& curl_tcp_keepidle , "GIT_TCP_KEEPIDLE" );
1413
+ set_long_from_env (& curl_tcp_keepintvl , "GIT_TCP_KEEPINTVL" );
1414
+ set_long_from_env (& curl_tcp_keepcnt , "GIT_TCP_KEEPCNT" );
1415
+
1373
1416
curl_default = get_curl_handle ();
1374
1417
}
1375
1418
0 commit comments