1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

disable tcp_bind for WiFiClient (tcp_connect gets automatic a free src port)

This commit is contained in:
Markus Sattler 2015-04-02 19:11:06 +02:00
parent 53dbeeb0aa
commit d87bc938f9

View File

@ -40,10 +40,15 @@ extern "C"
#include "include/ClientContext.h" #include "include/ClientContext.h"
#include "c_types.h" #include "c_types.h"
#define NO_PORT_BIND
#ifndef NO_PORT_BIND
#define MIN_LOCAL_PORT 1024 #define MIN_LOCAL_PORT 1024
#define MAX_LOCAL_PORT 1124 #define MAX_LOCAL_PORT 1124
static int g_localPort = MIN_LOCAL_PORT; static int g_localPort = MIN_LOCAL_PORT;
#endif
ICACHE_FLASH_ATTR WiFiClient::WiFiClient() ICACHE_FLASH_ATTR WiFiClient::WiFiClient()
: _client(0) : _client(0)
@ -97,7 +102,7 @@ int ICACHE_FLASH_ATTR WiFiClient::connect(IPAddress ip, uint16_t port)
tcp_pcb* pcb = tcp_new(); tcp_pcb* pcb = tcp_new();
if (!pcb) if (!pcb)
return 0; return 0;
#ifndef NO_PORT_BIND
while(true) while(true)
{ {
err_t err = tcp_bind(pcb, INADDR_ANY, g_localPort); err_t err = tcp_bind(pcb, INADDR_ANY, g_localPort);
@ -105,11 +110,14 @@ int ICACHE_FLASH_ATTR WiFiClient::connect(IPAddress ip, uint16_t port)
g_localPort = MIN_LOCAL_PORT; g_localPort = MIN_LOCAL_PORT;
if (err == ERR_OK) if (err == ERR_OK)
break; break;
if (err == ERR_USE) if (err == ERR_USE) {
esp_yield();
continue; continue;
}
tcp_abort(pcb); tcp_abort(pcb);
return 0; return 0;
} }
#endif
ip_addr_t addr; ip_addr_t addr;
addr.addr = ip; addr.addr = ip;
tcp_arg(pcb, this); tcp_arg(pcb, this);