summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-05-15 10:07:14 -0400
committerJune McEnroe <june@causal.agency>2020-05-18 14:30:21 -0400
commit1e52d207aca21c8fa39f99fdf3ce559af6370ae2 (patch)
treeacee50a73d022e910ab1e622ed84988aaaeb0f16
parentAdd server send queueing with time interval (diff)
downloadpounce-1e52d207aca21c8fa39f99fdf3ce559af6370ae2.tar.gz
pounce-1e52d207aca21c8fa39f99fdf3ce559af6370ae2.zip
Enable TCP keepalive with half-hour idle
Since we swallow IRC PINGs, a client connection can go hours idle on a
quiet network. On my home internet, at least, these connections seem to
get silently dropped.
-rw-r--r--compat.h4
-rw-r--r--local.c8
2 files changed, 12 insertions, 0 deletions
diff --git a/compat.h b/compat.h
index d471a8f..01ef10c 100644
--- a/compat.h
+++ b/compat.h
@@ -35,3 +35,7 @@ uint32_t arc4random_uniform(uint32_t upper_bound);
 #ifndef SIGINFO
 #define SIGINFO SIGUSR2
 #endif
+
+#ifdef __APPLE__
+#define TCP_KEEPIDLE TCP_KEEPALIVE
+#endif
diff --git a/local.c b/local.c
index 0a140e6..50e49d5 100644
--- a/local.c
+++ b/local.c
@@ -20,6 +20,7 @@
 #include <limits.h>
 #include <netdb.h>
 #include <netinet/in.h>
+#include <netinet/tcp.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -218,6 +219,13 @@ struct tls *localAccept(int *fd, int bind) {
 	int error = setsockopt(*fd, SOL_SOCKET, SO_NOSIGPIPE, &yes, sizeof(yes));
 	if (error) err(EX_OSERR, "setsockopt");
 
+	error = setsockopt(*fd, SOL_SOCKET, SO_KEEPALIVE, &yes, sizeof(yes));
+	if (error) err(EX_OSERR, "setsockopt");
+
+	int idle = 15 * 60;
+	error = setsockopt(*fd, IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle));
+	if (error) err(EX_OSERR, "setsockopt");
+
 	struct tls *client;
 	error = tls_accept_socket(server, &client, *fd);
 	if (error) errx(EX_SOFTWARE, "tls_accept_socket: %s", tls_error(server));