diff --git a/libraries/ESP8266WiFi/src/include/ClientContext.h b/libraries/ESP8266WiFi/src/include/ClientContext.h index 2023d30b11..4a53009d41 100644 --- a/libraries/ESP8266WiFi/src/include/ClientContext.h +++ b/libraries/ESP8266WiFi/src/include/ClientContext.h @@ -128,14 +128,14 @@ class ClientContext if (err != ERR_OK) { return 0; } - _connect_pending = 1; + _delaying = true; _op_start_time = millis(); // Following delay will be interrupted by connect callback - for (decltype(_timeout_ms) i = 0; _connect_pending && i < _timeout_ms; i++) { + for (decltype(_timeout_ms) i = 0; _delaying && i < _timeout_ms; i++) { // Give scheduled functions a chance to run (e.g. Ethernet uses recurrent) delay(1); - } - _connect_pending = 0; + } + _delaying = false; if (!_pcb) { DEBUGV(":cabrt\r\n"); return 0; @@ -432,15 +432,16 @@ class ClientContext void _notify_error() { - if (_connect_pending || _send_waiting) { - esp_schedule(); + if (_delaying) { + _delaying = false; + esp_schedule(); // break current delay() } } size_t _write_from_source(DataSource* ds) { assert(_datasource == nullptr); - assert(!_send_waiting); + assert(!_delaying); _datasource = ds; _written = 0; _op_start_time = millis(); @@ -458,14 +459,14 @@ class ClientContext break; } - _send_waiting = true; + _delaying = true; // Following delay will be interrupted by on next received ack - for (decltype(_timeout_ms) i = 0; _send_waiting && i < _timeout_ms; i++) { + for (decltype(_timeout_ms) i = 0; _delaying && i < _timeout_ms; i++) { // Give scheduled functions a chance to run (e.g. Ethernet uses recurrent) delay(1); } + _delaying = false; } while(true); - _send_waiting = false; if (_sync) wait_until_sent(); @@ -532,9 +533,9 @@ class ClientContext void _write_some_from_cb() { - if (_send_waiting) { - _send_waiting = false; - esp_schedule(); + if (_delaying) { + _delaying = false; + esp_schedule(); // break current delay() } } @@ -608,9 +609,9 @@ class ClientContext (void) err; (void) pcb; assert(pcb == _pcb); - assert(_connect_pending); - _connect_pending = 0; - esp_schedule(); + assert(_delaying); + _delaying = false; + esp_schedule(); // break current delay() return ERR_OK; } @@ -658,8 +659,7 @@ class ClientContext size_t _written = 0; uint32_t _timeout_ms = 5000; uint32_t _op_start_time = 0; - bool _send_waiting = false; - uint8_t _connect_pending = 0; + bool _delaying = false; int8_t _refcnt; ClientContext* _next;