Check for readable socket right before signaling a read timeout

In the current architecture, all socket reads proceed before all socket
polls, and the socket poll is where the read timeout check is made. If
the sum of the execution time of all write and read handlers exceeds
that of the next timeout-enabled polled socket, the code would
incorrectly close due to a "timeout", even if some readable data became
available in the meantime. Fix by checking (via select()) one last time
and resetting the timer if the socket has some readable data.
This commit is contained in:
Alex Villacís Lasso
2021-09-07 14:06:12 -05:00
parent 6f8bcef490
commit 2895bb8b84

View File

@@ -745,6 +745,20 @@ void AsyncClient::_sockPoll(void)
}
xSemaphoreGive(_write_mutex);
// RX Timeout? Check for readable socket before bailing out
if (_rx_since_timeout && (now - _rx_last_packet) >= (_rx_since_timeout * 1000)) {
fd_set sockSet_r;
struct timeval tv;
FD_ZERO(&sockSet_r);
FD_SET(_socket, &sockSet_r);
tv.tv_sec = 0;
tv.tv_usec = 0;
int r = select(_socket + 1, &sockSet_r, NULL, NULL, &tv);
if (r > 0) _rx_last_packet = now;
}
// RX Timeout
if (_rx_since_timeout && (now - _rx_last_packet) >= (_rx_since_timeout * 1000)) {
//log_w("rx timeout %d", pcb->state);