From d6f1f0d5d77508ed2b3bb6051a6fba3d69ab98ca Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 22 May 2017 20:08:16 +0800 Subject: [PATCH] WiFiClient: apply write timeout to single chunk (#3273) WiFiClient write timeouts introduced in #3257 applied to the whole write operation, which could take long time if data size was large. This change makes the timeout happen per chunk. Timeout now happens if no data has been delivered within a given interval. --- libraries/ESP8266WiFi/src/include/ClientContext.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libraries/ESP8266WiFi/src/include/ClientContext.h b/libraries/ESP8266WiFi/src/include/ClientContext.h index 82e059467..de6d8e150 100644 --- a/libraries/ESP8266WiFi/src/include/ClientContext.h +++ b/libraries/ESP8266WiFi/src/include/ClientContext.h @@ -353,9 +353,14 @@ protected: _written = 0; _op_start_time = millis(); do { - _write_some(); + if (_write_some()) { + _op_start_time = millis(); + } if (!_datasource->available() || _is_timeout() || state() == CLOSED) { + if (_is_timeout()) { + DEBUGV(":wtmo\r\n"); + } delete _datasource; _datasource = nullptr; break; @@ -368,10 +373,10 @@ protected: return _written; } - void _write_some() + bool _write_some() { if (!_datasource || !_pcb) { - return; + return false; } size_t left = _datasource->available(); @@ -403,7 +408,9 @@ protected: } if( need_output ) { tcp_output(_pcb); + return true; } + return false; } void _write_some_from_cb()