summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-12-28 11:32:36 -0800
committerJunio C Hamano <gitster@pobox.com>2011-12-28 11:32:36 -0800
commit2cb1ff9ac35ff043e377f78e36a57422a6846485 (patch)
tree22e4c7269435e3d224605989e4c652f89355244a
parent474294963eb968da7a06650a65a4d17b4bde3ad2 (diff)
parente47a8583a20256851e7fc882233e3bd5bf33dc6e (diff)
downloadgit-2cb1ff9ac35ff043e377f78e36a57422a6846485.tar.gz
Merge branch 'ew/keepalive' into maint
* ew/keepalive: enable SO_KEEPALIVE for connected TCP sockets
-rw-r--r--connect.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/connect.c b/connect.c
index 51990fa0cb..d0f59ef0de 100644
--- a/connect.c
+++ b/connect.c
@@ -175,6 +175,15 @@ static void get_host_and_port(char **host, const char **port)
}
}
+static void enable_keepalive(int sockfd)
+{
+ int ka = 1;
+
+ if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &ka, sizeof(ka)) < 0)
+ fprintf(stderr, "unable to set SO_KEEPALIVE on socket: %s\n",
+ strerror(errno));
+}
+
#ifndef NO_IPV6
static const char *ai_name(const struct addrinfo *ai)
@@ -239,6 +248,8 @@ static int git_tcp_connect_sock(char *host, int flags)
if (sockfd < 0)
die("unable to connect to %s:\n%s", host, error_message.buf);
+ enable_keepalive(sockfd);
+
if (flags & CONNECT_VERBOSE)
fprintf(stderr, "done.\n");
@@ -312,6 +323,8 @@ static int git_tcp_connect_sock(char *host, int flags)
if (sockfd < 0)
die("unable to connect to %s:\n%s", host, error_message.buf);
+ enable_keepalive(sockfd);
+
if (flags & CONNECT_VERBOSE)
fprintf(stderr, "done.\n");