Skip to content

Commit

Permalink
Add API to set the beginning of local ports range for WiFiClient
Browse files Browse the repository at this point in the history
  • Loading branch information
igrr committed Jun 2, 2015
1 parent bb462ea commit a965c76
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ extern "C"
#include "include/ClientContext.h"
#include "c_types.h"

uint16_t WiFiClient::_localPort = 0;

ICACHE_FLASH_ATTR WiFiClient::WiFiClient()
: _client(0)
{
Expand Down Expand Up @@ -93,6 +95,10 @@ int ICACHE_FLASH_ATTR WiFiClient::connect(IPAddress ip, uint16_t port)
if (!pcb)
return 0;

if (_localPort > 0) {
pcb->local_port = _localPort++;
}

ip_addr_t addr;
addr.addr = ip;
tcp_arg(pcb, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class WiFiClient : public Client {
uint16_t remotePort();
bool getNoDelay();
void setNoDelay(bool nodelay);
static void setLocalPortStart(uint16_t port) { _localPort = port; }

template<typename T> size_t write(T &src){
uint8_t obuf[1460];
Expand Down Expand Up @@ -97,6 +98,7 @@ class WiFiClient : public Client {
void _err(int8_t err);

ClientContext* _client;
static uint16_t _localPort;

};

Expand Down

0 comments on commit a965c76

Please sign in to comment.