Enable TCP keepalive on the core device

Automatically runs the idle experiment a few seconds after the master stops responding.

Thanks Florent for figuring out TCP_KEEPIDLE_DEFAULT needed to be set in addition to the other options.

Closes #31
This commit is contained in:
Sebastien Bourdeauducq 2015-08-13 18:32:37 +08:00
parent a1c7efd0ae
commit f2911d67b7
2 changed files with 14 additions and 7 deletions

View File

@ -105,6 +105,10 @@ a lot of data that needs to be copied, this should be set high. */
/* ---------- TCP options ---------- */
#define LWIP_TCP 1
#define LWIP_TCP_KEEPALIVE 1
#define TCP_KEEPIDLE_DEFAULT 1250
#define TCP_KEEPINTVL_DEFAULT 1000
#define TCP_KEEPCNT_DEFAULT 3
#define TCP_TTL 255
/* Controls if TCP should queue segments that arrive out of

View File

@ -60,14 +60,16 @@ static void net_server_close(struct net_server_connstate *cs, struct tcp_pcb *pc
active_pcb = NULL;
}
/* lwip loves to call back with broken pointers. Prevent that. */
tcp_arg(pcb, NULL);
tcp_recv(pcb, NULL);
tcp_sent(pcb, NULL);
tcp_err(pcb, NULL);
if(pcb) {
/* lwip loves to call back with broken pointers. Prevent that. */
tcp_arg(pcb, NULL);
tcp_recv(pcb, NULL);
tcp_sent(pcb, NULL);
tcp_err(pcb, NULL);
tcp_close(pcb);
}
cs_free(cs);
tcp_close(pcb);
}
static err_t net_server_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
@ -155,7 +157,7 @@ static void net_server_err(void *arg, err_t err)
struct net_server_connstate *cs;
cs = (struct net_server_connstate *)arg;
cs_free(cs);
net_server_close(cs, NULL);
}
static struct tcp_pcb *listen_pcb;
@ -177,6 +179,7 @@ static err_t net_server_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
void net_server_init(void)
{
listen_pcb = tcp_new();
listen_pcb->so_options |= SOF_KEEPALIVE;
tcp_bind(listen_pcb, IP_ADDR_ANY, 1381);
listen_pcb = tcp_listen(listen_pcb);
tcp_accept(listen_pcb, net_server_accept);