From a1fc5bc733f50c54e261352312a4b90d21731b07 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 11 Nov 2016 13:12:12 -0800 Subject: [PATCH] GUACAMOLE-118: Use poll() when waiting for data to be written to the terminal emulator. --- src/terminal/terminal.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 174e0d45..598a3852 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -32,12 +32,12 @@ #include "typescript.h" #include +#include #include #include #include #include #include -#include #include #include #include @@ -463,19 +463,15 @@ void guac_terminal_free(guac_terminal* term) { */ static int guac_terminal_wait_for_data(int fd, int msec_timeout) { - /* Build fd_set */ - fd_set fds; - FD_ZERO(&fds); - FD_SET(fd, &fds); - - /* Split millisecond timeout into seconds and microseconds */ - struct timeval timeout = { - .tv_sec = msec_timeout / 1000, - .tv_usec = (msec_timeout % 1000) * 1000 - }; + /* Build array of file descriptors */ + struct pollfd fds[] = {{ + .fd = fd, + .events = POLLIN, + .revents = 0, + }}; /* Wait for data */ - return select(fd+1, &fds, NULL, NULL, &timeout); + return poll(fds, 1, msec_timeout); }