Selaa lähdekoodia

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
Yury Popov 7 vuotta sitten
vanhempi
commit
2f00c1d8d9
2 muutettua tiedostoa jossa 12 lisäystä ja 1 poistoa
  1. 11 1
      app/include/lwipopts.h
  2. 1 0
      app/modules/net.c

+ 11 - 1
app/include/lwipopts.h

@@ -899,6 +899,15 @@
 #define TCP_TTL                         (IP_DEFAULT_TTL)
 #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.
  */
@@ -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
 
 /**

+ 1 - 0
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);