From 688a4e42bc5aed3111b410df2e9f4a474ef16b42 Mon Sep 17 00:00:00 2001 From: Veijo Pesonen Date: Mon, 25 Feb 2019 16:09:06 +0200 Subject: [PATCH] ESP8266: recv() is able to handle device busy indication --- .../wifi/esp8266-driver/ESP8266/ESP8266.cpp | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp b/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp index 94470e0b696..d6e283bff6c 100644 --- a/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp +++ b/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp @@ -736,12 +736,14 @@ int32_t ESP8266::_recv_tcp_passive(int id, void *data, uint32_t amount, uint32_t // NOTE: documentation v3.0 says '+CIPRECVDATA:,' but it's not how the FW responds... bool done = _parser.send("AT+CIPRECVDATA=%d,%lu", id, amount) && _parser.recv("OK\n"); - if (!done) { - tr_debug("data request failed"); - } + _sock_i[id].tcp_data = NULL; _sock_active_id = -1; + if (!done) { + goto BUSY; + } + // update internal variable tcp_data_avbl to reflect the remaining data if (_sock_i[id].tcp_data_rcvd > 0) { if (_sock_i[id].tcp_data_rcvd > (int32_t)amount) { @@ -764,6 +766,18 @@ int32_t ESP8266::_recv_tcp_passive(int id, void *data, uint32_t amount, uint32_t _smutex.unlock(); return ret; + +BUSY: + _process_oob(ESP8266_RECV_TIMEOUT, true); + if (_busy) { + tr_debug("_recv_tcp_passive(): modem busy"); + ret = NSAPI_ERROR_WOULD_BLOCK; + } else { + tr_error("_recv_tcp_passive(): unknown state"); + ret = NSAPI_ERROR_DEVICE_ERROR; + } + _smutex.unlock(); + return ret; } int32_t ESP8266::recv_tcp(int id, void *data, uint32_t amount, uint32_t timeout)