From 192f4825a2c5c5e3efc3b0abd473665473600c11 Mon Sep 17 00:00:00 2001 From: RipleyTom Date: Sun, 12 Mar 2023 22:32:12 +0100 Subject: [PATCH] Fix recvn high cpu usage --- rpcs3/Emu/NP/rpcn_client.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/rpcs3/Emu/NP/rpcn_client.cpp b/rpcs3/Emu/NP/rpcn_client.cpp index 83ef664dd1..88fff05bdb 100644 --- a/rpcs3/Emu/NP/rpcn_client.cpp +++ b/rpcs3/Emu/NP/rpcn_client.cpp @@ -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; }