Skip to content

Commit f2911d6

Browse files
committedAug 13, 2015
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
1 parent a1c7efd commit f2911d6

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed
 

Diff for: ‎soc/runtime/liblwip/lwipopts.h

+4
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ a lot of data that needs to be copied, this should be set high. */
105105

106106
/* ---------- TCP options ---------- */
107107
#define LWIP_TCP 1
108+
#define LWIP_TCP_KEEPALIVE 1
109+
#define TCP_KEEPIDLE_DEFAULT 1250
110+
#define TCP_KEEPINTVL_DEFAULT 1000
111+
#define TCP_KEEPCNT_DEFAULT 3
108112
#define TCP_TTL 255
109113

110114
/* Controls if TCP should queue segments that arrive out of

Diff for: ‎soc/runtime/net_server.c

+11-8
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,16 @@ static void net_server_close(struct net_server_connstate *cs, struct tcp_pcb *pc
6060
active_pcb = NULL;
6161
}
6262

63-
/* lwip loves to call back with broken pointers. Prevent that. */
64-
tcp_arg(pcb, NULL);
65-
tcp_recv(pcb, NULL);
66-
tcp_sent(pcb, NULL);
67-
tcp_err(pcb, NULL);
68-
63+
if(pcb) {
64+
/* lwip loves to call back with broken pointers. Prevent that. */
65+
tcp_arg(pcb, NULL);
66+
tcp_recv(pcb, NULL);
67+
tcp_sent(pcb, NULL);
68+
tcp_err(pcb, NULL);
69+
70+
tcp_close(pcb);
71+
}
6972
cs_free(cs);
70-
tcp_close(pcb);
7173
}
7274

7375
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)
155157
struct net_server_connstate *cs;
156158

157159
cs = (struct net_server_connstate *)arg;
158-
cs_free(cs);
160+
net_server_close(cs, NULL);
159161
}
160162

161163
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)
177179
void net_server_init(void)
178180
{
179181
listen_pcb = tcp_new();
182+
listen_pcb->so_options |= SOF_KEEPALIVE;
180183
tcp_bind(listen_pcb, IP_ADDR_ANY, 1381);
181184
listen_pcb = tcp_listen(listen_pcb);
182185
tcp_accept(listen_pcb, net_server_accept);

0 commit comments

Comments
 (0)
Please sign in to comment.