diff options
author | Junio C Hamano <gitster@pobox.com> | 2011-12-20 04:06:32 +0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-12-20 04:06:32 +0400 |
commit | 85878dd0c929dde5d91411b57ef9f2d696cbc7d8 (patch) | |
tree | b33e93553f443aae00ffb3fcb324cdb867eea1b1 | |
parent | 7f1068e21e5840fca0787f0925e62148b2f873ed (diff) | |
parent | e47a8583a20256851e7fc882233e3bd5bf33dc6e (diff) |
Merge branch 'ew/keepalive'
* ew/keepalive:
enable SO_KEEPALIVE for connected TCP sockets
-rw-r--r-- | connect.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -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"); |