X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=connect.c;h=c8d0ea5d75e89a6b15b62e7057e97947036e11ea;hb=7a5638a1597da222dde484074392223d8daebd15;hp=2a0a0401af6e070125f1ae6d97004f4036af35f6;hpb=bab8d28e774c255a326ad5592af6351e4925efcb;p=git.git diff --git a/connect.c b/connect.c index 2a0a0401a..c8d0ea5d7 100644 --- a/connect.c +++ b/connect.c @@ -151,6 +151,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) @@ -215,6 +224,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"); @@ -288,6 +299,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");