1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-12 01:53:07 +03:00

ClientContext (tcp) updates (#5089)

* +sync, get/set default nodelay, sync

* default nodelay=1

* update flush()

* fix return value

* ClientContext: put things together

* ClientContext: fix debugging messages

* WiFiClient: move static members out of the class, add comments

* remove circular dependency

* parameter and return value for Client::flush&stop, flush timeout raised to 300ms

* tcp flush: restart timer on ack receive

* OTA protocol needs setNoDelay(true)

* fix Ethernet with Client changes

* 1 line unredable -> 5 lines readable code

* doc

* Update client-class.rst

* Added details for getters
This commit is contained in:
david gauchard
2018-09-25 15:47:27 +02:00
committed by Develo
parent 88bd26bd74
commit 83a8076db8
15 changed files with 290 additions and 96 deletions

View File

@ -43,6 +43,34 @@ extern "C"
uint16_t WiFiClient::_localPort = 0;
static bool defaultNoDelay = false; // false == Nagle enabled by default
static bool defaultSync = false;
bool getDefaultPrivateGlobalSyncValue ()
{
return defaultSync;
}
void WiFiClient::setDefaultNoDelay (bool noDelay)
{
defaultNoDelay = noDelay;
}
void WiFiClient::setDefaultSync (bool sync)
{
defaultSync = sync;
}
bool WiFiClient::getDefaultNoDelay ()
{
return defaultNoDelay;
}
bool WiFiClient::getDefaultSync ()
{
return defaultSync;
}
template<>
WiFiClient* SList<WiFiClient>::_s_first = 0;
@ -60,6 +88,9 @@ WiFiClient::WiFiClient(ClientContext* client)
_timeout = 5000;
_client->ref();
WiFiClient::_add(this);
setSync(defaultSync);
setNoDelay(defaultNoDelay);
}
WiFiClient::~WiFiClient()
@ -91,7 +122,6 @@ WiFiClient& WiFiClient::operator=(const WiFiClient& other)
return *this;
}
int WiFiClient::connect(const char* host, uint16_t port)
{
IPAddress remote_addr;
@ -147,6 +177,9 @@ int WiFiClient::connect(IPAddress ip, uint16_t port)
return 0;
}
setSync(defaultSync);
setNoDelay(defaultNoDelay);
return 1;
}
@ -156,12 +189,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;
@ -264,19 +311,25 @@ size_t WiFiClient::peekBytes(uint8_t *buffer, size_t length) {
return _client->peekBytes((char *)buffer, count);
}
void WiFiClient::flush()
{
if (_client)
_client->wait_until_sent();
}
void WiFiClient::stop()
bool WiFiClient::flush(unsigned int maxWaitMs)
{
if (!_client)
return;
return true;
flush();
_client->close();
if (maxWaitMs == 0)
maxWaitMs = WIFICLIENT_MAX_FLUSH_WAIT_MS;
return _client->wait_until_sent(maxWaitMs);
}
bool WiFiClient::stop(unsigned int maxWaitMs)
{
if (!_client)
return true;
bool ret = flush(maxWaitMs); // virtual, may be ssl's
if (_client->close() != ERR_OK)
ret = false;
return ret;
}
uint8_t WiFiClient::connected()