Set SO_KEEPALIVE option on native git:// sockets. Signed-off-by: Michal Ludvig Index: git-1.4.0/connect.c =================================================================== --- git-1.4.0.orig/connect.c +++ git-1.4.0/connect.c @@ -331,7 +331,7 @@ static int git_tcp_connect_sock(char *ho char *colon, *end; char *port = STR(DEFAULT_GIT_PORT); struct addrinfo hints, *ai0, *ai; - int gai; + int gai, option; if (host[0] == '[') { end = strchr(host + 1, ']'); @@ -363,6 +363,10 @@ static int git_tcp_connect_sock(char *ho ai->ai_socktype, ai->ai_protocol); if (sockfd < 0) continue; + + option = 1; + setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &option, sizeof(option)); + if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) { close(sockfd); sockfd = -1; @@ -392,7 +396,7 @@ static int git_tcp_connect_sock(char *ho struct hostent *he; struct sockaddr_in sa; char **ap; - unsigned int nport; + unsigned int nport, option; if (host[0] == '[') { end = strchr(host + 1, ']'); @@ -433,6 +437,9 @@ static int git_tcp_connect_sock(char *ho sa.sin_port = htons(nport); memcpy(&sa.sin_addr, *ap, he->h_length); + option = 1; + setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &option, sizeof(option)); + if (connect(sockfd, (struct sockaddr *)&sa, sizeof sa) < 0) { close(sockfd); sockfd = -1;