diff --git a/include/mgba-util/socket.h b/include/mgba-util/socket.h index 96edc3d92..ff9d89626 100644 --- a/include/mgba-util/socket.h +++ b/include/mgba-util/socket.h @@ -434,9 +434,9 @@ static inline int SocketPoll(size_t nSockets, Socket* reads, Socket* writes, Soc #else int result = select(maxFd, &rset, &wset, &eset, timeoutMillis < 0 ? 0 : &tv); #endif - int r = 0; - int w = 0; - int e = 0; + size_t r = 0; + size_t w = 0; + size_t e = 0; Socket j; for (j = 0; j < maxFd; ++j) { if (reads && FD_ISSET(j, &rset)) { @@ -452,6 +452,21 @@ static inline int SocketPoll(size_t nSockets, Socket* reads, Socket* writes, Soc ++e; } } + if (reads) { + for (; r < nSockets; ++r) { + reads[r] = INVALID_SOCKET; + } + } + if (writes) { + for (; w < nSockets; ++w) { + writes[w] = INVALID_SOCKET; + } + } + if (errors) { + for (; e < nSockets; ++e) { + errors[e] = INVALID_SOCKET; + } + } return result; }