Util: Fix handling of SocketPoll of n > 1

This commit is contained in:
Vicki Pfau 2023-05-05 02:00:03 -07:00
parent 00d1c0dc9d
commit 0a36069315
1 changed files with 18 additions and 3 deletions

View File

@ -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;
}