From dae5d4a8009dc11babe1f23cfcd0741a2f05437b Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Mon, 16 Nov 2015 09:52:05 +0100 Subject: [PATCH] Set SO_KEEPALIVE on the socket so that we don't hang forever --- src/main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.c b/src/main.c index 16fe9b7..773fa8e 100644 --- a/src/main.c +++ b/src/main.c @@ -93,6 +93,14 @@ static void sk_set_reuseaddr (int fd) perror("setsockopt SO_REUSEADDR"); } +static void sk_set_keepalive (int fd) +{ + int val = 1; + + if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val))==-1) + perror("setsockopt SO_KEEPALIVE"); +} + #ifdef TCP_CONGESTION static void sk_set_congestion (int fd, const char *name) { @@ -733,6 +741,7 @@ int main (int argc, char **argv) sk_set_nodelay(sock.fd); fd_set_nonblock(sock.fd); + sk_set_keepalive(sock.fd); sk_set_congestion(sock.fd, congestion); switch (gt_setup_crypto(&ctx, sock.fd, listener)) {