Skip to content

Commit

Permalink
Enable TCP keepalive on the core device
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sbourdeauducq committed Aug 13, 2015
1 parent a1c7efd commit f2911d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
4 changes: 4 additions & 0 deletions soc/runtime/liblwip/lwipopts.h
Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions soc/runtime/net_server.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit f2911d6

Please sign in to comment.