@@ -697,15 +697,14 @@ nsapi_size_or_error_t ESP8266::send(int id, const void *data, uint32_t amount)
697
697
} else if (_sock_i[id].proto == NSAPI_UDP) {
698
698
ret = NSAPI_ERROR_NO_MEMORY;
699
699
}
700
- goto END;
701
- } else if (bytes_confirmed != amount) {
700
+ } else if (bytes_confirmed != amount && _sock_i[id].proto == NSAPI_UDP) {
702
701
tr_debug (" send(): Error: confirmed %d bytes, but expected %d." , bytes_confirmed, amount);
703
702
ret = NSAPI_ERROR_DEVICE_ERROR;
704
- goto END;
703
+ } else {
704
+ // TCP can accept partial writes (if they ever happen)
705
+ ret = bytes_confirmed;
705
706
}
706
707
707
- ret = amount;
708
-
709
708
END:
710
709
_process_oob (ESP8266_RECV_TIMEOUT, true ); // Drain USART receive register to avoid data overrun
711
710
@@ -1009,6 +1008,14 @@ void ESP8266::_clear_socket_packets(int id)
1009
1008
}
1010
1009
}
1011
1010
1011
+ void ESP8266::_clear_socket_sending (int id)
1012
+ {
1013
+ if (id == _sock_sending_id) {
1014
+ _sock_sending_id = -1 ;
1015
+ }
1016
+ _sock_i[id].send_fail = false ;
1017
+ }
1018
+
1012
1019
bool ESP8266::close (int id)
1013
1020
{
1014
1021
// May take a second try if device is busy
@@ -1021,10 +1028,7 @@ bool ESP8266::close(int id)
1021
1028
_sock_i[id].open = false ;
1022
1029
_clear_socket_packets (id);
1023
1030
// Closed, so this socket escapes from SEND FAIL status.
1024
- if (id == _sock_sending_id) {
1025
- _sock_sending_id = -1 ;
1026
- }
1027
- _sock_i[id].send_fail = false ;
1031
+ _clear_socket_sending (id);
1028
1032
_smutex.unlock ();
1029
1033
// ESP8266 has a habit that it might close a socket on its own.
1030
1034
tr_debug (" close(%d): socket close OK with UNLINK ERROR" , id);
@@ -1034,10 +1038,7 @@ bool ESP8266::close(int id)
1034
1038
// _sock_i[id].open set to false with an OOB
1035
1039
_clear_socket_packets (id);
1036
1040
// Closed, so this socket escapes from SEND FAIL status
1037
- if (id == _sock_sending_id) {
1038
- _sock_sending_id = -1 ;
1039
- }
1040
- _sock_i[id].send_fail = false ;
1041
+ _clear_socket_sending (id);
1041
1042
_smutex.unlock ();
1042
1043
tr_debug (" close(%d): socket close OK with AT+CIPCLOSE OK" , id);
1043
1044
return true ;
@@ -1224,10 +1225,7 @@ void ESP8266::_oob_socket0_closed()
1224
1225
static const int id = 0 ;
1225
1226
_sock_i[id].open = false ;
1226
1227
// Closed, so this socket escapes from SEND FAIL status
1227
- if (id == _sock_sending_id) {
1228
- _sock_sending_id = -1 ;
1229
- }
1230
- _sock_i[id].send_fail = false ;
1228
+ _clear_socket_sending (id);
1231
1229
tr_debug (" _oob_socket0_closed(): Socket %d closed." , id);
1232
1230
}
1233
1231
@@ -1236,34 +1234,23 @@ void ESP8266::_oob_socket1_closed()
1236
1234
static const int id = 1 ;
1237
1235
_sock_i[id].open = false ;
1238
1236
// Closed, so this socket escapes from SEND FAIL status
1239
- if (id == _sock_sending_id) {
1240
- _sock_sending_id = -1 ;
1241
- }
1242
- _sock_i[id].send_fail = false ;
1237
+ _clear_socket_sending (id);
1243
1238
tr_debug (" _oob_socket1_closed(): Socket %d closed." , id);
1244
1239
}
1245
1240
1246
1241
void ESP8266::_oob_socket2_closed ()
1247
1242
{
1248
1243
static const int id = 2 ;
1249
1244
_sock_i[id].open = false ;
1250
- // Closed, so this socket escapes from SEND FAIL status
1251
- if (id == _sock_sending_id) {
1252
- _sock_sending_id = -1 ;
1253
- }
1254
- _sock_i[id].send_fail = false ;
1245
+ _clear_socket_sending (id);
1255
1246
tr_debug (" _oob_socket2_closed(): Socket %d closed." , id);
1256
1247
}
1257
1248
1258
1249
void ESP8266::_oob_socket3_closed ()
1259
1250
{
1260
1251
static const int id = 3 ;
1261
1252
_sock_i[id].open = false ;
1262
- // Closed, so this socket escapes from SEND FAIL status
1263
- if (id == _sock_sending_id) {
1264
- _sock_sending_id = -1 ;
1265
- }
1266
- _sock_i[id].send_fail = false ;
1253
+ _clear_socket_sending (id);
1267
1254
tr_debug (" _oob_socket3_closed(): %d closed." , id);
1268
1255
}
1269
1256
@@ -1272,10 +1259,7 @@ void ESP8266::_oob_socket4_closed()
1272
1259
static const int id = 4 ;
1273
1260
_sock_i[id].open = false ;
1274
1261
// Closed, so this socket escapes from SEND FAIL status
1275
- if (id == _sock_sending_id) {
1276
- _sock_sending_id = -1 ;
1277
- }
1278
- _sock_i[id].send_fail = false ;
1262
+ _clear_socket_sending (id);
1279
1263
tr_debug (" _oob_socket0_closed(): Socket %d closed." , id);
1280
1264
}
1281
1265
0 commit comments