about summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-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));