diff options
Diffstat (limited to 'src')
-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); |