diff --git a/src/guacd/socket-ssl.c b/src/guacd/socket-ssl.c index adbbd94a..751286d8 100644 --- a/src/guacd/socket-ssl.c +++ b/src/guacd/socket-ssl.c @@ -77,6 +77,10 @@ static int __guac_socket_ssl_select_handler(guac_socket* socket, int usec_timeou struct timeval timeout; int retval; + /* Initialize fd_set with single underlying file descriptor */ + FD_ZERO(&fds); + FD_SET(data->fd, &fds); + /* No timeout if usec_timeout is negative */ if (usec_timeout < 0) retval = select(data->fd + 1, &fds, NULL, NULL, NULL); @@ -85,10 +89,6 @@ static int __guac_socket_ssl_select_handler(guac_socket* socket, int usec_timeou else { timeout.tv_sec = usec_timeout/1000000; timeout.tv_usec = usec_timeout%1000000; - - FD_ZERO(&fds); - FD_SET(data->fd, &fds); - retval = select(data->fd + 1, &fds, NULL, NULL, &timeout); } diff --git a/src/libguac/socket-fd.c b/src/libguac/socket-fd.c index 13c66edd..5bd9bf34 100644 --- a/src/libguac/socket-fd.c +++ b/src/libguac/socket-fd.c @@ -92,6 +92,10 @@ int __guac_socket_fd_select_handler(guac_socket* socket, int usec_timeout) { struct timeval timeout; int retval; + /* Initialize fd_set with single underlying file descriptor */ + FD_ZERO(&fds); + FD_SET(data->fd, &fds); + /* No timeout if usec_timeout is negative */ if (usec_timeout < 0) retval = select(data->fd + 1, &fds, NULL, NULL, NULL); @@ -100,10 +104,6 @@ int __guac_socket_fd_select_handler(guac_socket* socket, int usec_timeout) { else { timeout.tv_sec = usec_timeout/1000000; timeout.tv_usec = usec_timeout%1000000; - - FD_ZERO(&fds); - FD_SET(data->fd, &fds); - retval = select(data->fd + 1, &fds, NULL, NULL, &timeout); }