1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

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

This PR stops the 1ms-delay loop also when a tcp error occurs (previously this was done only when tcp had just connected or a write/send had succeeded).
The tcp error can be any, in this case with pubsubclient it is "connection refused" after the mqtt server disappeared and pubsubclient tries to reconnect.
This commit is contained in:
david gauchard 2019-08-27 15:26:27 +02:00 committed by GitHub
parent e56aed6540
commit 0937b076c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -128,14 +128,14 @@ public:
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 @@ protected:
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 @@ protected:
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 @@ protected:
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 @@ protected:
(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 @@ private:
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;