diff --git a/libraries/ESP8266WiFi/src/include/ClientContext.h b/libraries/ESP8266WiFi/src/include/ClientContext.h index 2f2891510e..2023d30b11 100644 --- a/libraries/ESP8266WiFi/src/include/ClientContext.h +++ b/libraries/ESP8266WiFi/src/include/ClientContext.h @@ -130,8 +130,11 @@ class ClientContext } _connect_pending = 1; _op_start_time = millis(); - // This delay will be interrupted by esp_schedule in the connect callback - delay(_timeout_ms); + // Following delay will be interrupted by connect callback + for (decltype(_timeout_ms) i = 0; _connect_pending && i < _timeout_ms; i++) { + // Give scheduled functions a chance to run (e.g. Ethernet uses recurrent) + delay(1); + } _connect_pending = 0; if (!_pcb) { DEBUGV(":cabrt\r\n"); @@ -456,8 +459,11 @@ class ClientContext } _send_waiting = true; - // This delay will be interrupted by esp_schedule on next received ack - delay(_timeout_ms); + // Following delay will be interrupted by on next received ack + for (decltype(_timeout_ms) i = 0; _send_waiting && i < _timeout_ms; i++) { + // Give scheduled functions a chance to run (e.g. Ethernet uses recurrent) + delay(1); + } } while(true); _send_waiting = false; @@ -603,6 +609,7 @@ class ClientContext (void) pcb; assert(pcb == _pcb); assert(_connect_pending); + _connect_pending = 0; esp_schedule(); return ERR_OK; }