Skip to content

Commit 4bfa2ae

Browse files
emelianovd-a-v
authored andcommitted
TCP connect and send delay fix (#6213)
* TCP connect and send delay fix Implement early exit as connection established or data already sent. (Previous implementation was exiting only on timeout expired)
1 parent 403001e commit 4bfa2ae

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Diff for: libraries/ESP8266WiFi/src/include/ClientContext.h

+11-4
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,11 @@ class ClientContext
130130
}
131131
_connect_pending = 1;
132132
_op_start_time = millis();
133-
// This delay will be interrupted by esp_schedule in the connect callback
134-
delay(_timeout_ms);
133+
// Following delay will be interrupted by connect callback
134+
for (decltype(_timeout_ms) i = 0; _connect_pending && i < _timeout_ms; i++) {
135+
// Give scheduled functions a chance to run (e.g. Ethernet uses recurrent)
136+
delay(1);
137+
}
135138
_connect_pending = 0;
136139
if (!_pcb) {
137140
DEBUGV(":cabrt\r\n");
@@ -456,8 +459,11 @@ class ClientContext
456459
}
457460

458461
_send_waiting = true;
459-
// This delay will be interrupted by esp_schedule on next received ack
460-
delay(_timeout_ms);
462+
// Following delay will be interrupted by on next received ack
463+
for (decltype(_timeout_ms) i = 0; _send_waiting && i < _timeout_ms; i++) {
464+
// Give scheduled functions a chance to run (e.g. Ethernet uses recurrent)
465+
delay(1);
466+
}
461467
} while(true);
462468
_send_waiting = false;
463469

@@ -603,6 +609,7 @@ class ClientContext
603609
(void) pcb;
604610
assert(pcb == _pcb);
605611
assert(_connect_pending);
612+
_connect_pending = 0;
606613
esp_schedule();
607614
return ERR_OK;
608615
}

0 commit comments

Comments
 (0)