mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +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:
@ -119,13 +119,15 @@ int EthernetClient::peek() {
|
||||
return b;
|
||||
}
|
||||
|
||||
void EthernetClient::flush() {
|
||||
bool EthernetClient::flush(unsigned int maxWaitMs) {
|
||||
(void)maxWaitMs;
|
||||
::flush(_sock);
|
||||
return true;
|
||||
}
|
||||
|
||||
void EthernetClient::stop() {
|
||||
bool EthernetClient::stop(unsigned int maxWaitMs) {
|
||||
if (_sock == MAX_SOCK_NUM)
|
||||
return;
|
||||
return true;
|
||||
|
||||
// attempt to close the connection gracefully (send a FIN to other side)
|
||||
disconnect(_sock);
|
||||
@ -133,19 +135,27 @@ void EthernetClient::stop() {
|
||||
|
||||
// wait up to a second for the connection to close
|
||||
uint8_t s;
|
||||
if (maxWaitMs == 0)
|
||||
maxWaitMs = 1000;
|
||||
do {
|
||||
s = status();
|
||||
if (s == SnSR::CLOSED)
|
||||
break; // exit the loop
|
||||
delay(1);
|
||||
} while (millis() - start < 1000);
|
||||
} while (millis() - start < maxWaitMs);
|
||||
|
||||
bool ret = true;
|
||||
|
||||
// if it hasn't closed, close it forcefully
|
||||
if (s != SnSR::CLOSED)
|
||||
if (s != SnSR::CLOSED) {
|
||||
ret = false;
|
||||
close(_sock);
|
||||
}
|
||||
|
||||
EthernetClass::_server_port[_sock] = 0;
|
||||
_sock = MAX_SOCK_NUM;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t EthernetClient::connected() {
|
||||
|
@ -20,8 +20,8 @@ public:
|
||||
virtual int read();
|
||||
virtual int read(uint8_t *buf, size_t size);
|
||||
virtual int peek();
|
||||
virtual void flush();
|
||||
virtual void stop();
|
||||
virtual bool flush(unsigned int maxWaitMs = 0);
|
||||
virtual bool stop(unsigned int maxWaitMs = 0);
|
||||
virtual uint8_t connected();
|
||||
virtual operator bool();
|
||||
virtual bool operator==(const bool value) { return bool() == value; }
|
||||
|
Reference in New Issue
Block a user