]> granicus.if.org Git - php/commitdiff
Clarify usage of max_fd in php_poll2() on Windows
authorChristoph M. Becker <cmbecker69@gmx.de>
Fri, 27 Dec 2019 09:11:01 +0000 (10:11 +0100)
committerChristoph M. Becker <cmbecker69@gmx.de>
Fri, 27 Dec 2019 12:41:29 +0000 (13:41 +0100)
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.

main/network.c

index 5f1957e0fd1eb3995ba11a336defaac95176bdd0..ece2b372ea51dd3f945d4895da6a1bab77fec027 100644 (file)
@@ -1171,16 +1171,18 @@ PHPAPI void _php_emit_fd_setsize_warning(int max_fd)
 PHPAPI int php_poll2(php_pollfd *ufds, unsigned int nfds, int timeout)
 {
        fd_set rset, wset, eset;
-       php_socket_t max_fd = SOCK_ERR;
+       php_socket_t max_fd = SOCK_ERR; /* effectively unused on Windows */
        unsigned int i;
        int n;
        struct timeval tv;
 
+#ifndef PHP_WIN32
        /* check the highest numbered descriptor */
        for (i = 0; i < nfds; i++) {
                if (ufds[i].fd > max_fd)
                        max_fd = ufds[i].fd;
        }
+#endif
 
        PHP_SAFE_MAX_FD(max_fd, nfds + 1);