GUACAMOLE-118: Migrate to poll() instead of select() for file descriptor guac_socket implementation.

This commit is contained in:
Michael Jumper 2016-11-11 13:03:43 -08:00
parent a46ce4cc3b
commit 9d6d2aeba7

View File

@ -22,6 +22,7 @@
#include "error.h" #include "error.h"
#include "socket.h" #include "socket.h"
#include <poll.h>
#include <pthread.h> #include <pthread.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
@ -30,12 +31,6 @@
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#ifdef __MINGW32__
#include <winsock2.h>
#else
#include <sys/select.h>
#endif
/** /**
* Data associated with an open socket which writes to a file descriptor. * Data associated with an open socket which writes to a file descriptor.
*/ */
@ -337,24 +332,22 @@ static int guac_socket_fd_select_handler(guac_socket* socket,
guac_socket_fd_data* data = (guac_socket_fd_data*) socket->data; guac_socket_fd_data* data = (guac_socket_fd_data*) socket->data;
fd_set fds;
struct timeval timeout;
int retval; int retval;
/* Initialize fd_set with single underlying file descriptor */ /* Initialize with single underlying file descriptor */
FD_ZERO(&fds); struct pollfd fds[1] = {{
FD_SET(data->fd, &fds); .fd = data->fd,
.events = POLLIN,
.revents = 0,
}};
/* No timeout if usec_timeout is negative */ /* No timeout if usec_timeout is negative */
if (usec_timeout < 0) if (usec_timeout < 0)
retval = select(data->fd + 1, &fds, NULL, NULL, NULL); retval = poll(fds, 1, -1);
/* Handle timeout if specified */ /* Handle timeout if specified, rounding up to poll()'s granularity */
else { else
timeout.tv_sec = usec_timeout/1000000; retval = poll(fds, 1, (usec_timeout + 999) / 1000);
timeout.tv_usec = usec_timeout%1000000;
retval = select(data->fd + 1, &fds, NULL, NULL, &timeout);
}
/* Properly set guac_error */ /* Properly set guac_error */
if (retval < 0) { if (retval < 0) {