Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClientContext (tcp) updates #5089

Merged
merged 39 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6c64759
wip
d-a-v Aug 22, 2018
746ec81
cc wip
d-a-v Aug 22, 2018
53c9222
cc wip
d-a-v Aug 22, 2018
6de50d4
cc comments
d-a-v Aug 22, 2018
2dd152d
wip cc
d-a-v Aug 24, 2018
f87602a
+sync, get/set default nodelay, sync
d-a-v Aug 27, 2018
6be4b6f
default nodelay=1
d-a-v Aug 28, 2018
8f7fb1e
update flush()
d-a-v Aug 28, 2018
c0bea2b
fix return value
d-a-v Aug 28, 2018
d00ac35
ClientContext: put things together
d-a-v Aug 28, 2018
53931c5
wip
d-a-v Aug 22, 2018
81ec0f4
cc wip
d-a-v Aug 22, 2018
fbf1dd1
cc wip
d-a-v Aug 22, 2018
b4a918f
cc comments
d-a-v Aug 22, 2018
c14eeef
wip cc
d-a-v Aug 24, 2018
238610e
+sync, get/set default nodelay, sync
d-a-v Aug 27, 2018
d0036a1
default nodelay=1
d-a-v Aug 28, 2018
e4c187b
update flush()
d-a-v Aug 28, 2018
d31d6f2
fix return value
d-a-v Aug 28, 2018
5cf60b6
ClientContext: put things together
d-a-v Aug 28, 2018
a058506
Move SSLContext to its own header (#5121)
earlephilhower Sep 17, 2018
a7a5959
Fix connection options and update github pubkey (#5120)
earlephilhower Sep 17, 2018
d06cac2
ClientContext: fix debugging messages
d-a-v Sep 18, 2018
e8c659e
Merge branch 'master' into ClientContext
earlephilhower Sep 18, 2018
f271b2a
WiFiClient: move static members out of the class, add comments
d-a-v Sep 18, 2018
7f57694
Merge branch 'ClientContext' of github.com:d-a-v/Arduino into ClientC…
d-a-v Sep 18, 2018
888bdb8
remove circular dependency
d-a-v Sep 19, 2018
c59a91f
parameter and return value for Client::flush&stop, flush timeout rais…
d-a-v Sep 22, 2018
3c54c9e
Merge branch 'master' into ClientContext
d-a-v Sep 23, 2018
8414e17
tcp flush: restart timer on ack receive
d-a-v Sep 23, 2018
4d62879
OTA protocol needs setNoDelay(true)
d-a-v Sep 23, 2018
826b8b5
fix Ethernet with Client changes
d-a-v Sep 23, 2018
3fa6a97
1 line unredable -> 5 lines readable code
d-a-v Sep 23, 2018
72b59d9
Merge branch 'master' into ClientContext
d-a-v Sep 24, 2018
7752c98
doc
d-a-v Sep 24, 2018
c160d17
doc
d-a-v Sep 24, 2018
db8fe6c
doc
d-a-v Sep 24, 2018
8bb444d
doc
d-a-v Sep 24, 2018
33dee32
Update client-class.rst
devyte Sep 24, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions libraries/ESP8266WiFi/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ extern "C"
#include "c_types.h"

uint16_t WiFiClient::_localPort = 0;
bool WiFiClient::_defaultNoDelay = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest a big fat comment here about what the four combinations of nodelay and sync do, because I can't for the life of me keep them straight in my head.

bool WiFiClient::_defaultSync = false;

template<>
WiFiClient* SList<WiFiClient>::_s_first = 0;
Expand All @@ -60,6 +62,9 @@ WiFiClient::WiFiClient(ClientContext* client)
_timeout = 5000;
_client->ref();
WiFiClient::_add(this);

setSync(_defaultSync);
setNoDelay(_defaultNoDelay);
}

WiFiClient::~WiFiClient()
Expand Down Expand Up @@ -91,7 +96,6 @@ WiFiClient& WiFiClient::operator=(const WiFiClient& other)
return *this;
}


int WiFiClient::connect(const char* host, uint16_t port)
{
IPAddress remote_addr;
Expand Down Expand Up @@ -147,6 +151,9 @@ int WiFiClient::connect(IPAddress ip, uint16_t port)
return 0;
}

setSync(_defaultSync);
setNoDelay(_defaultNoDelay);

return 1;
}

Expand All @@ -156,12 +163,26 @@ void WiFiClient::setNoDelay(bool nodelay) {
_client->setNoDelay(nodelay);
}

bool WiFiClient::getNoDelay() {
bool WiFiClient::getNoDelay() const {
if (!_client)
return false;
return _client->getNoDelay();
}

void WiFiClient::setSync(bool sync)
{
if (!_client)
return;
_client->setSync(sync);
}

bool WiFiClient::getSync() const
{
if (!_client)
return false;
return _client->getSync();
}

size_t WiFiClient::availableForWrite ()
{
return _client? _client->availableForWrite(): 0;
Expand Down Expand Up @@ -275,6 +296,7 @@ void WiFiClient::stop()
if (!_client)
return;

_client->wait_until_sent();
_client->close();
}

Expand Down
20 changes: 18 additions & 2 deletions libraries/ESP8266WiFi/src/WiFiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
#include "IPAddress.h"
#include "include/slist.h"

#define WIFICLIENT_MAX_PACKET_SIZE 1460
#ifndef TCP_MSS
#define TCP_MSS 1460 // lwip1.4
#endif

#define WIFICLIENT_MAX_PACKET_SIZE TCP_MSS
#define WIFICLIENT_MAX_FLUSH_WAIT_MS 100

#define TCP_DEFAULT_KEEPALIVE_IDLE_SEC 7200 // 2 hours
#define TCP_DEFAULT_KEEPALIVE_INTERVAL_SEC 75 // 75 sec
Expand Down Expand Up @@ -76,8 +81,11 @@ class WiFiClient : public Client, public SList<WiFiClient> {
uint16_t remotePort();
IPAddress localIP();
uint16_t localPort();
bool getNoDelay();
bool getNoDelay() const;
void setNoDelay(bool nodelay);
bool getSync() const;
void setSync(bool sync);

static void setLocalPortStart(uint16_t port) { _localPort = port; }

size_t availableForWrite();
Expand All @@ -96,6 +104,11 @@ class WiFiClient : public Client, public SList<WiFiClient> {
uint8_t getKeepAliveCount () const;
void disableKeepAlive () { keepAlive(0, 0, 0); }

static void setDefaultNoDelay (bool noDelay) { _defaultNoDelay = noDelay; }
static void setDefaultSync (bool sync) { _defaultSync = sync; }
static bool getDefaultNoDelay () { return _defaultNoDelay; }
static bool getDefaultSync () { return _defaultSync; }

protected:

static int8_t _s_connected(void* arg, void* tpcb, int8_t err);
Expand All @@ -106,6 +119,9 @@ class WiFiClient : public Client, public SList<WiFiClient> {

ClientContext* _client;
static uint16_t _localPort;

static bool _defaultNoDelay;
static bool _defaultSync;
d-a-v marked this conversation as resolved.
Show resolved Hide resolved
};

#endif
11 changes: 8 additions & 3 deletions libraries/ESP8266WiFi/src/WiFiServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,16 @@ void WiFiServer::begin(uint16_t port) {
}

void WiFiServer::setNoDelay(bool nodelay) {
_noDelay = nodelay;
_noDelay = nodelay? _ndTrue: _ndFalse;
}

bool WiFiServer::getNoDelay() {
return _noDelay;
switch (_noDelay)
{
case _ndFalse: return false;
case _ndTrue: return true;
default: return WiFiClient::getDefaultNoDelay();
}
}

bool WiFiServer::hasClient() {
Expand All @@ -106,7 +111,7 @@ WiFiClient WiFiServer::available(byte* status) {
if (_unclaimed) {
WiFiClient result(_unclaimed);
_unclaimed = _unclaimed->next();
result.setNoDelay(_noDelay);
result.setNoDelay(getNoDelay());
DEBUGV("WS:av\r\n");
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266WiFi/src/WiFiServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class WiFiServer : public Server {

ClientContext* _unclaimed;
ClientContext* _discarded;
bool _noDelay = false;
enum { _ndDefault, _ndFalse, _ndTrue } _noDelay = _ndDefault;

public:
WiFiServer(IPAddress addr, uint16_t port);
Expand Down
Loading