diff options
author | tiptorrent development team <tiptorrent@soleta.eu> | 2021-09-18 21:25:30 +0200 |
---|---|---|
committer | tiptorrent development team <tiptorrent@soleta.eu> | 2021-09-18 21:25:30 +0200 |
commit | e365ceb02448ad19362c1d8bfd3e48536afa9097 (patch) | |
tree | e8d6fc6318ea0f5bcb264482d66b0286109f58bc | |
parent | 5c8ec91711f4cc1a52c499f0b1adfb0d10754cdd (diff) |
enable TCP keepalived
-rw-r--r-- | src/main.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -24,6 +24,7 @@ #include <sys/time.h> #include <limits.h> #include <syslog.h> +#include <netinet/tcp.h> #define TIP_TORRENT_PORT 9999 @@ -325,8 +326,14 @@ static void tip_client_connect_cb(struct ev_loop *loop, struct ev_io *io, int ev ev_io_start(tip_main_loop, &cli->io); } +#define TIP_TCP_KEEPALIVE_IDLE 60 +#define TIP_TCP_KEEPALIVE_INTL 30 +#define TIP_TCP_KEEPALIVE_CNT 4 + static int tip_client_connect(const char *addr) { + int intl = TIP_TCP_KEEPALIVE_INTL, cnt = TIP_TCP_KEEPALIVE_CNT; + int on = 1, idle = TIP_TCP_KEEPALIVE_IDLE; struct tip_client *cli = &_cli; int remote_fd; int flags; @@ -337,6 +344,11 @@ static int tip_client_connect(const char *addr) if (remote_fd < 0) return -1; + setsockopt(remote_fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(int)); + setsockopt(remote_fd, IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(int)); + setsockopt(remote_fd, IPPROTO_TCP, TCP_KEEPINTVL, &intl, sizeof(int)); + setsockopt(remote_fd, IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(int)); + flags = fcntl(remote_fd, F_GETFL); flags |= O_NONBLOCK; ret = fcntl(remote_fd, F_SETFL, flags); |