Skip to content

ClientContext: break timeout delays also on error while writing or connecting #6454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions libraries/ESP8266WiFi/src/include/ClientContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down