Cellular: Replace CellularSocket.rx_avail with pending_bytes

CellularSocket::rx_avail can be refactored away as
it is a duplicate to CellularSocket::pending_bytes.
pull/11937/head
Ari Parkkila 2019-11-25 04:57:41 -08:00
parent e03180d13d
commit adba109de6
5 changed files with 6 additions and 14 deletions

View File

@ -274,7 +274,7 @@ nsapi_size_or_error_t AT_CellularStack::socket_sendto(nsapi_socket_t handle, con
return NSAPI_ERROR_NO_SOCKET;
}
if (socket->closed && !socket->rx_avail) {
if (socket->closed && !socket->pending_bytes) {
tr_info("sendto socket %d closed", socket->id);
return NSAPI_ERROR_NO_CONNECTION;
}

View File

@ -112,7 +112,6 @@ protected:
closed(false),
started(false),
tx_ready(false),
rx_avail(false),
tls_socket(false),
pending_bytes(0)
{
@ -130,7 +129,6 @@ protected:
bool closed; // socket has been closed by a peer
bool started; // socket has been opened on modem stack
bool tx_ready; // socket is ready for sending on modem stack
bool rx_avail; // socket has data for reading on modem stack
bool tls_socket; // socket uses modem's internal TLS socket functionality
nsapi_size_t pending_bytes; // The number of received bytes pending
};

View File

@ -99,7 +99,7 @@ void GEMALTO_CINTERION_CellularStack::sisr_urc_handler(int sock_id, int urc_code
if (sock) {
if (urc_code == 1) { // data available
if (sock->_cb) {
sock->rx_avail = true;
sock->pending_bytes = 1;
sock->_cb(sock->_data);
}
}
@ -387,9 +387,9 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell
// we must use this flag, otherwise ^SISR URC can come while we are reading response and there is
// no way to detect if that is really an URC or response
if (!socket->rx_avail) {
if (!socket->pending_bytes) {
_at.process_oob(); // check for ^SISR URC
if (!socket->rx_avail) {
if (!socket->pending_bytes) {
tr_debug("Socekt %d recv would block", socket->id);
return NSAPI_ERROR_WOULD_BLOCK;
}
@ -430,12 +430,12 @@ sisr_retry:
tr_error("Socket %d recvfrom failed!", socket->id);
return NSAPI_ERROR_DEVICE_ERROR;
}
socket->rx_avail = false;
socket->pending_bytes = 0;
if (len >= (nsapi_size_or_error_t)size) {
len = (nsapi_size_or_error_t)size;
int remain_len = _at.read_int();
if (remain_len > 0) {
socket->rx_avail = true;
socket->pending_bytes = 1;
}
}

View File

@ -55,7 +55,6 @@ void UBLOX_AT_CellularStack::UUSORD_URC()
socket = find_socket(a);
if (socket != NULL) {
socket->rx_avail = true;
socket->pending_bytes = b;
// No debug prints here as they can affect timing
// and cause data loss in UARTSerial
@ -76,7 +75,6 @@ void UBLOX_AT_CellularStack::UUSORF_URC()
socket = find_socket(a);
if (socket != NULL) {
socket->rx_avail = true;
socket->pending_bytes = b;
// No debug prints here as they can affect timing
// and cause data loss in UARTSerial
@ -353,7 +351,6 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke
}
timer.stop();
socket->rx_avail = false;
socket->pending_bytes = 0;
if (!count || (_at.get_last_error() != NSAPI_ERROR_OK)) {
return NSAPI_ERROR_WOULD_BLOCK;
@ -398,7 +395,6 @@ void UBLOX_AT_CellularStack::clear_socket(CellularSocket *socket)
if (socket != NULL) {
socket->id = SOCKET_UNUSED;
socket->started = false;
socket->rx_avail = false;
socket->pending_bytes = 0;
socket->closed = true;
if (socket->_cb) {

View File

@ -54,7 +54,6 @@ void UBLOX_N2XX_CellularStack::NSONMI_URC()
socket = find_socket(a);
if (socket != NULL) {
socket->rx_avail = true;
socket->pending_bytes = b;
// No debug prints here as they can affect timing
// and cause data loss in UARTSerial
@ -209,7 +208,6 @@ nsapi_size_or_error_t UBLOX_N2XX_CellularStack::socket_recvfrom_impl(CellularSoc
}
timer.stop();
socket->rx_avail = false;
socket->pending_bytes = 0;
if (!count || (_at.get_last_error() != NSAPI_ERROR_OK)) {
return NSAPI_ERROR_WOULD_BLOCK;