Fix recvn high cpu usage

This commit is contained in:
RipleyTom 2023-03-12 22:32:12 +01:00 committed by Megamouse
parent bcce3acd5f
commit 192f4825a2

View File

@ -496,14 +496,13 @@ namespace rpcn
{
if (wolfSSL_want_read(read_wssl))
{
// If we received partially what we want try to wait longer
if (n_recv == 0)
return recvn_result::recvn_nodata;
pollfd poll_fd{};
while ((poll_fd.revents & POLLIN) != POLLIN && (poll_fd.revents & POLLRDNORM) != POLLRDNORM)
{
if (!connected)
return recvn_result::recvn_noconn;
if (terminate)
return recvn_result::recvn_terminate;
@ -523,8 +522,12 @@ namespace rpcn
}
num_timeouts++;
if (num_timeouts > (RPCN_TIMEOUT / RPCN_TIMEOUT_INTERVAL))
{
if (n_recv == 0)
return recvn_result::recvn_nodata;
rpcn_log.error("recvn timeout with %d bytes received", n_recv);
return recvn_result::recvn_timeout;
}
@ -545,6 +548,12 @@ namespace rpcn
res = 0;
}
else
{
// Reset timeout each time something is received
num_timeouts = 0;
}
n_recv += res;
}