From 2f00c1d8d9819bed703f61259c484e26268f0f88 Mon Sep 17 00:00:00 2001 From: Yury Popov Date: Fri, 17 Mar 2017 09:31:37 +0300 Subject: [PATCH] TIME_WAIT sockets fixes (#1838) * Enable SO_REUSEADDR for server TCP sockets * Reduce TCP_MSL to 5 sec * Add changes notice for future updates * Move MSL change to lwipiots.h --- app/include/lwipopts.h | 12 +++++++++++- app/modules/net.c | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/include/lwipopts.h b/app/include/lwipopts.h index 23f731ad..3cb93b73 100755 --- a/app/include/lwipopts.h +++ b/app/include/lwipopts.h @@ -899,6 +899,15 @@ #define TCP_TTL (IP_DEFAULT_TTL) #endif +/** + * TCP_MSL: Maximum segment lifetime + * Override for file + * See https://github.com/nodemcu/nodemcu-firmware/issues/1836 for details + */ +#ifndef TCP_MSL +#define TCP_MSL 5000UL +#endif + /** * TCP_MAXRTX: Maximum number of retransmissions of data segments. */ @@ -1455,7 +1464,8 @@ * SO_REUSE==1: Enable SO_REUSEADDR option. */ #ifndef SO_REUSE -#define SO_REUSE 0 +/* See https://github.com/nodemcu/nodemcu-firmware/issues/1836 for details */ +#define SO_REUSE 1 #endif /** diff --git a/app/modules/net.c b/app/modules/net.c index 4a3c65cc..90c25d26 100644 --- a/app/modules/net.c +++ b/app/modules/net.c @@ -386,6 +386,7 @@ int net_listen( lua_State *L ) { ud->tcp_pcb = tcp_new(); if (!ud->tcp_pcb) return luaL_error(L, "cannot allocate PCB"); + ud->tcp_pcb->so_options |= SOF_REUSEADDR; err = tcp_bind(ud->tcp_pcb, &addr, port); if (err == ERR_OK) { tcp_arg(ud->tcp_pcb, ud);