Commit 71078ad3 authored by Martin Storsjö's avatar Martin Storsjö

os_support: Don't compare a negative number against socket descriptors

The fds are unsigned integers in the windows definition of struct
sockfds. Due to this, the comparison if (fds[i].fd > n) was always
false.
Signed-off-by: 's avatarMartin Storsjö <martin@martin.st>
parent 5aff37d2
...@@ -286,7 +286,7 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout) ...@@ -286,7 +286,7 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout)
FD_ZERO(&write_set); FD_ZERO(&write_set);
FD_ZERO(&exception_set); FD_ZERO(&exception_set);
n = -1; n = 0;
for(i = 0; i < numfds; i++) { for(i = 0; i < numfds; i++) {
if (fds[i].fd < 0) if (fds[i].fd < 0)
continue; continue;
...@@ -301,22 +301,22 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout) ...@@ -301,22 +301,22 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout)
if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &write_set); if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &write_set);
if (fds[i].events & POLLERR) FD_SET(fds[i].fd, &exception_set); if (fds[i].events & POLLERR) FD_SET(fds[i].fd, &exception_set);
if (fds[i].fd > n) if (fds[i].fd >= n)
n = fds[i].fd; n = fds[i].fd + 1;
}; };
if (n == -1) if (n == 0)
/* Hey!? Nothing to poll, in fact!!! */ /* Hey!? Nothing to poll, in fact!!! */
return 0; return 0;
if (timeout < 0) if (timeout < 0)
rc = select(n+1, &read_set, &write_set, &exception_set, NULL); rc = select(n, &read_set, &write_set, &exception_set, NULL);
else { else {
struct timeval tv; struct timeval tv;
tv.tv_sec = timeout / 1000; tv.tv_sec = timeout / 1000;
tv.tv_usec = 1000 * (timeout % 1000); tv.tv_usec = 1000 * (timeout % 1000);
rc = select(n+1, &read_set, &write_set, &exception_set, &tv); rc = select(n, &read_set, &write_set, &exception_set, &tv);
}; };
if (rc < 0) if (rc < 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment