Skip to content

Commit 388c582

Browse files
committed
Clarify usage of max_fd in php_poll2() on Windows
Actually, `max_fd` is not used on Windows, since `PHP_SAFE_MAX_FD` and `select` ignore it; so it makes no sense to calculate it in the loop. Even worse, since `php_socket_t` is unsigned on Windows, it will never be modified during the loop, because `SOCK_ERR` is already the largest representable value of that type. Therefore we skip the loop on Windows, and add a clarifying comment.
1 parent 7b69855 commit 388c582

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

main/network.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,16 +1171,18 @@ PHPAPI void _php_emit_fd_setsize_warning(int max_fd)
11711171
PHPAPI int php_poll2(php_pollfd *ufds, unsigned int nfds, int timeout)
11721172
{
11731173
fd_set rset, wset, eset;
1174-
php_socket_t max_fd = SOCK_ERR;
1174+
php_socket_t max_fd = SOCK_ERR; /* effectively unused on Windows */
11751175
unsigned int i;
11761176
int n;
11771177
struct timeval tv;
11781178

1179+
#ifndef PHP_WIN32
11791180
/* check the highest numbered descriptor */
11801181
for (i = 0; i < nfds; i++) {
11811182
if (ufds[i].fd > max_fd)
11821183
max_fd = ufds[i].fd;
11831184
}
1185+
#endif
11841186

11851187
PHP_SAFE_MAX_FD(max_fd, nfds + 1);
11861188

0 commit comments

Comments
 (0)