mirror of https://github.com/ARMmbed/mbed-os.git
ESP8266: accept partial writes for TCP and clean up code
parent
4405ab46b6
commit
ea2f36eadf
|
@ -697,15 +697,14 @@ nsapi_size_or_error_t ESP8266::send(int id, const void *data, uint32_t amount)
|
||||||
} else if (_sock_i[id].proto == NSAPI_UDP) {
|
} else if (_sock_i[id].proto == NSAPI_UDP) {
|
||||||
ret = NSAPI_ERROR_NO_MEMORY;
|
ret = NSAPI_ERROR_NO_MEMORY;
|
||||||
}
|
}
|
||||||
goto END;
|
} else if (bytes_confirmed != amount && _sock_i[id].proto == NSAPI_UDP) {
|
||||||
} else if (bytes_confirmed != amount) {
|
|
||||||
tr_debug("send(): Error: confirmed %d bytes, but expected %d.", bytes_confirmed, amount);
|
tr_debug("send(): Error: confirmed %d bytes, but expected %d.", bytes_confirmed, amount);
|
||||||
ret = NSAPI_ERROR_DEVICE_ERROR;
|
ret = NSAPI_ERROR_DEVICE_ERROR;
|
||||||
goto END;
|
} else {
|
||||||
|
// TCP can accept partial writes (if they ever happen)
|
||||||
|
ret = bytes_confirmed;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = amount;
|
|
||||||
|
|
||||||
END:
|
END:
|
||||||
_process_oob(ESP8266_RECV_TIMEOUT, true); // Drain USART receive register to avoid data overrun
|
_process_oob(ESP8266_RECV_TIMEOUT, true); // Drain USART receive register to avoid data overrun
|
||||||
|
|
||||||
|
@ -1009,6 +1008,14 @@ void ESP8266::_clear_socket_packets(int id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ESP8266::_clear_socket_sending(int id)
|
||||||
|
{
|
||||||
|
if (id == _sock_sending_id) {
|
||||||
|
_sock_sending_id = -1;
|
||||||
|
}
|
||||||
|
_sock_i[id].send_fail = false;
|
||||||
|
}
|
||||||
|
|
||||||
bool ESP8266::close(int id)
|
bool ESP8266::close(int id)
|
||||||
{
|
{
|
||||||
//May take a second try if device is busy
|
//May take a second try if device is busy
|
||||||
|
@ -1021,10 +1028,7 @@ bool ESP8266::close(int id)
|
||||||
_sock_i[id].open = false;
|
_sock_i[id].open = false;
|
||||||
_clear_socket_packets(id);
|
_clear_socket_packets(id);
|
||||||
// Closed, so this socket escapes from SEND FAIL status.
|
// Closed, so this socket escapes from SEND FAIL status.
|
||||||
if (id == _sock_sending_id) {
|
_clear_socket_sending(id);
|
||||||
_sock_sending_id = -1;
|
|
||||||
}
|
|
||||||
_sock_i[id].send_fail = false;
|
|
||||||
_smutex.unlock();
|
_smutex.unlock();
|
||||||
// ESP8266 has a habit that it might close a socket on its own.
|
// ESP8266 has a habit that it might close a socket on its own.
|
||||||
tr_debug("close(%d): socket close OK with UNLINK ERROR", id);
|
tr_debug("close(%d): socket close OK with UNLINK ERROR", id);
|
||||||
|
@ -1034,10 +1038,7 @@ bool ESP8266::close(int id)
|
||||||
// _sock_i[id].open set to false with an OOB
|
// _sock_i[id].open set to false with an OOB
|
||||||
_clear_socket_packets(id);
|
_clear_socket_packets(id);
|
||||||
// Closed, so this socket escapes from SEND FAIL status
|
// Closed, so this socket escapes from SEND FAIL status
|
||||||
if (id == _sock_sending_id) {
|
_clear_socket_sending(id);
|
||||||
_sock_sending_id = -1;
|
|
||||||
}
|
|
||||||
_sock_i[id].send_fail = false;
|
|
||||||
_smutex.unlock();
|
_smutex.unlock();
|
||||||
tr_debug("close(%d): socket close OK with AT+CIPCLOSE OK", id);
|
tr_debug("close(%d): socket close OK with AT+CIPCLOSE OK", id);
|
||||||
return true;
|
return true;
|
||||||
|
@ -1224,10 +1225,7 @@ void ESP8266::_oob_socket0_closed()
|
||||||
static const int id = 0;
|
static const int id = 0;
|
||||||
_sock_i[id].open = false;
|
_sock_i[id].open = false;
|
||||||
// Closed, so this socket escapes from SEND FAIL status
|
// Closed, so this socket escapes from SEND FAIL status
|
||||||
if (id == _sock_sending_id) {
|
_clear_socket_sending(id);
|
||||||
_sock_sending_id = -1;
|
|
||||||
}
|
|
||||||
_sock_i[id].send_fail = false;
|
|
||||||
tr_debug("_oob_socket0_closed(): Socket %d closed.", id);
|
tr_debug("_oob_socket0_closed(): Socket %d closed.", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1236,10 +1234,7 @@ void ESP8266::_oob_socket1_closed()
|
||||||
static const int id = 1;
|
static const int id = 1;
|
||||||
_sock_i[id].open = false;
|
_sock_i[id].open = false;
|
||||||
// Closed, so this socket escapes from SEND FAIL status
|
// Closed, so this socket escapes from SEND FAIL status
|
||||||
if (id == _sock_sending_id) {
|
_clear_socket_sending(id);
|
||||||
_sock_sending_id = -1;
|
|
||||||
}
|
|
||||||
_sock_i[id].send_fail = false;
|
|
||||||
tr_debug("_oob_socket1_closed(): Socket %d closed.", id);
|
tr_debug("_oob_socket1_closed(): Socket %d closed.", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1247,11 +1242,7 @@ void ESP8266::_oob_socket2_closed()
|
||||||
{
|
{
|
||||||
static const int id = 2;
|
static const int id = 2;
|
||||||
_sock_i[id].open = false;
|
_sock_i[id].open = false;
|
||||||
// Closed, so this socket escapes from SEND FAIL status
|
_clear_socket_sending(id);
|
||||||
if (id == _sock_sending_id) {
|
|
||||||
_sock_sending_id = -1;
|
|
||||||
}
|
|
||||||
_sock_i[id].send_fail = false;
|
|
||||||
tr_debug("_oob_socket2_closed(): Socket %d closed.", id);
|
tr_debug("_oob_socket2_closed(): Socket %d closed.", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1259,11 +1250,7 @@ void ESP8266::_oob_socket3_closed()
|
||||||
{
|
{
|
||||||
static const int id = 3;
|
static const int id = 3;
|
||||||
_sock_i[id].open = false;
|
_sock_i[id].open = false;
|
||||||
// Closed, so this socket escapes from SEND FAIL status
|
_clear_socket_sending(id);
|
||||||
if (id == _sock_sending_id) {
|
|
||||||
_sock_sending_id = -1;
|
|
||||||
}
|
|
||||||
_sock_i[id].send_fail = false;
|
|
||||||
tr_debug("_oob_socket3_closed(): %d closed.", id);
|
tr_debug("_oob_socket3_closed(): %d closed.", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1272,10 +1259,7 @@ void ESP8266::_oob_socket4_closed()
|
||||||
static const int id = 4;
|
static const int id = 4;
|
||||||
_sock_i[id].open = false;
|
_sock_i[id].open = false;
|
||||||
// Closed, so this socket escapes from SEND FAIL status
|
// Closed, so this socket escapes from SEND FAIL status
|
||||||
if (id == _sock_sending_id) {
|
_clear_socket_sending(id);
|
||||||
_sock_sending_id = -1;
|
|
||||||
}
|
|
||||||
_sock_i[id].send_fail = false;
|
|
||||||
tr_debug("_oob_socket0_closed(): Socket %d closed.", id);
|
tr_debug("_oob_socket0_closed(): Socket %d closed.", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -444,6 +444,7 @@ private:
|
||||||
// data follows
|
// data follows
|
||||||
} *_packets, * *_packets_end;
|
} *_packets, * *_packets_end;
|
||||||
void _clear_socket_packets(int id);
|
void _clear_socket_packets(int id);
|
||||||
|
void _clear_socket_sending(int id);
|
||||||
int _sock_active_id;
|
int _sock_active_id;
|
||||||
|
|
||||||
// Memory statistics
|
// Memory statistics
|
||||||
|
|
Loading…
Reference in New Issue