Skip to content

Instantly share code, notes, and snippets.

@lorenzhs
Created April 6, 2014 08:55
Show Gist options
  • Save lorenzhs/10003301 to your computer and use it in GitHub Desktop.
Save lorenzhs/10003301 to your computer and use it in GitHub Desktop.
WeeChat Relay TCP keepalive interval
diff --git a/src/plugins/relay/relay-server.c b/src/plugins/relay/relay-server.c
index 900ecf9..c64bcaa 100644
--- a/src/plugins/relay/relay-server.c
+++ b/src/plugins/relay/relay-server.c
@@ -29,6 +29,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
+#include <netinet/tcp.h>
#include <arpa/inet.h>
#include "../weechat-plugin.h"
@@ -455,6 +456,21 @@ relay_server_create_socket (struct t_relay_server *server)
return 0;
}
+ /* set option TCP_KEEPINTVL to 120 seconds */
+ set = 120;
+ if (setsockopt (server->sock, SOL_TCP, TCP_KEEPINTVL,
+ (void *) &set, sizeof (set)) < 0)
+ {
+ weechat_printf (NULL,
+ _("%s%s: cannot set socket option \"%s\" to %d: "
+ "error %d %s"),
+ weechat_prefix ("error"), RELAY_PLUGIN_NAME,
+ "TCP_KEEPINTVL", set, errno, strerror (errno));
+ close (server->sock);
+ server->sock = -1;
+ return 0;
+ }
+
/* bind */
if (bind (server->sock, (struct sockaddr *)ptr_addr, addr_size) < 0)
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment