Skip to content

Commit 935134e

Browse files
committed
ESP8266: Add retries to avoid spurious close in blocking mode
With send(...) changing to non-block, modem can be busy in sending previous data and 'busy' the current 'AT+CIPCLOSE' command. In blocking mode, add retries to avoid spurious close to some degree. This is required to pass GT netsocket-tcp/netsocket-tls tests which expect close(...) to be OK.
1 parent 2d42667 commit 935134e

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

components/wifi/esp8266-driver/ESP8266Interface.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,8 +775,27 @@ int ESP8266Interface::socket_close(void *handle)
775775
return NSAPI_ERROR_NO_SOCKET;
776776
}
777777

778-
if (socket->connected && !_esp.close(socket->id)) {
779-
err = NSAPI_ERROR_DEVICE_ERROR;
778+
// With send(...) changing to non-block, modem can be busy in
779+
// sending previous data and 'busy' the current 'AT+CIPCLOSE'
780+
// command. In blocking mode, add retries to avoid spurious
781+
// close to some degree. This is required to pass GT netsocket-tcp/
782+
// netsocket-tls tests which expect close(...) to be OK.
783+
if (socket->connected) {
784+
if (_if_blocking) {
785+
err = NSAPI_ERROR_DEVICE_ERROR;
786+
for (int i = 0; i < 10; i ++) {
787+
if (_esp.close(socket->id)) {
788+
err = 0;
789+
break;
790+
} else {
791+
rtos::ThisThread::sleep_for(1000);
792+
}
793+
}
794+
} else {
795+
if (!_esp.close(socket->id)) {
796+
err = NSAPI_ERROR_WOULD_BLOCK;
797+
}
798+
}
780799
}
781800

782801
_cbs[socket->id].callback = NULL;

0 commit comments

Comments
 (0)