enable TCP keepalived
parent
5c8ec91711
commit
e365ceb024
12
src/main.c
12
src/main.c
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue