net module: Server timeout support

As per @djphoenix's version on the ESP8266 side.
This commit is contained in:
Johny Mattsson 2016-12-30 15:39:07 +11:00
parent 334ba08131
commit 6bce18f9ac
1 changed files with 6 additions and 4 deletions

View File

@ -52,6 +52,7 @@ typedef struct lnet_userdata {
union { union {
struct { struct {
int cb_accept_ref; int cb_accept_ref;
int timeout;
} server; } server;
struct { struct {
int wait_dns; int wait_dns;
@ -351,9 +352,8 @@ int net_createServer( lua_State *L ) {
if (type == TYPE_UDP) return net_createUDPSocket( L ); if (type == TYPE_UDP) return net_createUDPSocket( L );
if (type != TYPE_TCP) return luaL_error(L, "invalid type"); if (type != TYPE_TCP) return luaL_error(L, "invalid type");
net_create(L, TYPE_TCP_SERVER); lnet_userdata *ud = net_create(L, TYPE_TCP_SERVER);
// TODO: timeout ud->server.timeout = timeout;
(void)timeout;
return 1; return 1;
} }
@ -1020,7 +1020,9 @@ static void laccept_cb (lua_State *L, lnet_userdata *ud, struct tcp_pcb *newpcb)
tcp_err(nud->tcp_pcb, net_err_cb); tcp_err(nud->tcp_pcb, net_err_cb);
tcp_recv(nud->tcp_pcb, net_tcp_recv_cb); tcp_recv(nud->tcp_pcb, net_tcp_recv_cb);
tcp_sent(nud->tcp_pcb, net_sent_cb); tcp_sent(nud->tcp_pcb, net_sent_cb);
nud->tcp_pcb->so_options |= SOF_KEEPALIVE;
nud->tcp_pcb->keep_idle = ud->server.timeout * 1000;
nud->tcp_pcb->keep_cnt = 1;
tcp_accepted(ud->tcp_pcb); tcp_accepted(ud->tcp_pcb);
lua_call(L, 1, 0); lua_call(L, 1, 0);