From 199fe0f16d3544a092f2e3622c40502f5a5117cd Mon Sep 17 00:00:00 2001 From: david gauchard Date: Thu, 1 Feb 2018 11:49:04 +0100 Subject: [PATCH] ClientContext:_write_some: release buffer once data really accepted for sending (#4265) may fix #1872 --- libraries/ESP8266WiFi/src/include/ClientContext.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/ESP8266WiFi/src/include/ClientContext.h b/libraries/ESP8266WiFi/src/include/ClientContext.h index 43e9040a4..d53b45394 100644 --- a/libraries/ESP8266WiFi/src/include/ClientContext.h +++ b/libraries/ESP8266WiFi/src/include/ClientContext.h @@ -447,11 +447,13 @@ protected: } err_t err = tcp_write(_pcb, buf, next_chunk, TCP_WRITE_FLAG_COPY); DEBUGV(":wrc %d %d %d\r\n", next_chunk, will_send, (int) err); - _datasource->release_buffer(buf, next_chunk); if (err == ERR_OK) { + _datasource->release_buffer(buf, next_chunk); _written += next_chunk; need_output = true; } else { + // ERR_MEM(-1) is a valid error meaning + // "come back later". It leaves state() opened break; } will_send -= next_chunk;