From e79fdaca57d8e43bd8ee154045d36ea34ebebf50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 10 Jan 2025 11:24:12 +0100 Subject: [PATCH] Fix bug in sceNetInetPoll, similar to the previous select bug --- Core/HLE/sceNetInet.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Core/HLE/sceNetInet.cpp b/Core/HLE/sceNetInet.cpp index f54f122890..3252445321 100644 --- a/Core/HLE/sceNetInet.cpp +++ b/Core/HLE/sceNetInet.cpp @@ -311,7 +311,7 @@ int sceNetInetSelect(int nfds, u32 readfdsPtr, u32 writefdsPtr, u32 exceptfdsPtr int sceNetInetPoll(u32 fdsPtr, u32 nfds, int timeout) { // timeout in miliseconds just like posix poll? or in microseconds as other PSP timeout? DEBUG_LOG(Log::sceNet, "UNTESTED sceNetInetPoll(%08x, %d, %i) at %08x", fdsPtr, nfds, timeout, currentMIPS->pc); int retval = -1; - int maxfd = 0; + int maxHostFd = 0; SceNetInetPollfd *fdarray = (SceNetInetPollfd*)Memory::GetPointer(fdsPtr); // SceNetInetPollfd/pollfd, sceNetInetPoll() have similarity to BSD poll() but pollfd have different size on 64bit if (nfds > FD_SETSIZE) @@ -324,10 +324,11 @@ int sceNetInetPoll(u32 fdsPtr, u32 nfds, int timeout) { // timeout in milisecond inetLastErrno = EINVAL; return hleLogError(Log::sceNet, -1, "invalid socket id"); } - if (fdarray[i].fd > maxfd) { - maxfd = fdarray[i].fd; - } SOCKET hostSocket = g_socketManager.GetHostSocketFromInetSocket(fdarray[i].fd); + if (hostSocket > maxHostFd) { + maxHostFd = hostSocket; + } + _dbg_assert_(hostSocket != 0); FD_SET(hostSocket, &readfds); FD_SET(hostSocket, &writefds); FD_SET(hostSocket, &exceptfds); @@ -340,7 +341,7 @@ int sceNetInetPoll(u32 fdsPtr, u32 nfds, int timeout) { // timeout in milisecond tmout.tv_usec = (timeout % 1000000); // microseconds } // TODO: Simulate blocking behaviour when timeout is non-zero to prevent PPSSPP from freezing - retval = select(maxfd + 1, &readfds, &writefds, &exceptfds, /*(timeout<0)? NULL:*/&tmout); + retval = select(maxHostFd + 1, &readfds, &writefds, &exceptfds, /*(timeout<0)? NULL:*/&tmout); if (retval < 0) { inetLastErrno = EINTR; return hleLogError(Log::sceNet, hleDelayResult(retval, "workaround until blocking-socket", 500)); // Using hleDelayResult as a workaround for games that need blocking-socket to be implemented