mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
ref: d-a-v/esp82xx-nonos-linklayer#31 origin: #5902 me-no-dev/ESPAsyncTCP#108 Following the links above is instructive. To summarize: * currently and from a long time lwIP tcp client connections always uses the same tcp source port number right after boot * this port number is increased everytime a new one is needed (= new tcp client connection) (to be noted, linux has the same increasing behavior) * when connecting to the same server (right after boot), the triplet (esp-ip-address, source port, destination port) are the same, and may hit remote server list of sockets in time-wait-state (previous connection unproperly closed from the same esp). Consequently the new connection fails when it happens. * this is happening only when debugging (esp reboots often, in less time than time-wait expiration), so the nasty effect is amplified especially when bugs are being chased * efforts had been done when espressif's lwIP implementation wasn't open source, with WiFiClient::setLocalPortStart() #632 but it must be explicitely called with a different random number at every reboot. Efficient but not ideal. This PR uses espressif firmware's r_rand() everytime a new local source port is needed. A different source port number is now showed by tcpdump right after boot. Source port range and duplication is verified everytime in lwIP's src/core/tcp.c:tcp_new_port(). It is implemented as a local patch for upstream lwIP so it is valid not only with WiFiClient but also with @me-no-dev's Async libraries (they don't use WiFiClient). WiFiClient::setLocalPortStart() is still usable with the same effects as before.
1.3 MiB
1.3 MiB