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
This commit is contained in:
Yury Popov 2017-03-17 09:31:37 +03:00 committed by Arnim Läuger
parent 925991715f
commit 2f00c1d8d9
2 changed files with 12 additions and 1 deletions

View File

@ -899,6 +899,15 @@
#define TCP_TTL (IP_DEFAULT_TTL) #define TCP_TTL (IP_DEFAULT_TTL)
#endif #endif
/**
* TCP_MSL: Maximum segment lifetime
* Override for <tcp_impl.h> 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. * TCP_MAXRTX: Maximum number of retransmissions of data segments.
*/ */
@ -1455,7 +1464,8 @@
* SO_REUSE==1: Enable SO_REUSEADDR option. * SO_REUSE==1: Enable SO_REUSEADDR option.
*/ */
#ifndef SO_REUSE #ifndef SO_REUSE
#define SO_REUSE 0 /* See https://github.com/nodemcu/nodemcu-firmware/issues/1836 for details */
#define SO_REUSE 1
#endif #endif
/** /**

View File

@ -386,6 +386,7 @@ int net_listen( lua_State *L ) {
ud->tcp_pcb = tcp_new(); ud->tcp_pcb = tcp_new();
if (!ud->tcp_pcb) if (!ud->tcp_pcb)
return luaL_error(L, "cannot allocate PCB"); return luaL_error(L, "cannot allocate PCB");
ud->tcp_pcb->so_options |= SOF_REUSEADDR;
err = tcp_bind(ud->tcp_pcb, &addr, port); err = tcp_bind(ud->tcp_pcb, &addr, port);
if (err == ERR_OK) { if (err == ERR_OK) {
tcp_arg(ud->tcp_pcb, ud); tcp_arg(ud->tcp_pcb, ud);