Set guac_error in guac_select()

This commit is contained in:
Michael Jumper 2011-11-23 16:25:25 -08:00
parent 97f7249e60
commit 5214b1538d
2 changed files with 23 additions and 6 deletions

View File

@ -216,6 +216,12 @@ ssize_t guac_flush(GUACIO* io);
* Waits for input to be available on the given GUACIO object until the
* specified timeout elapses.
*
* If an error occurs while waiting, a negative value is returned, and
* guac_error is set appropriately.
*
* If a timeout occurs while waiting, zero value is returned, and
* guac_error is set to GUAC_STATUS_INPUT_TIMEOUT.
*
* @param io The GUACIO object to wait for.
* @param usec_timeout The maximum number of microseconds to wait for data, or
* -1 to potentially wait forever.

View File

@ -299,17 +299,28 @@ int guac_select(GUACIO* io, int usec_timeout) {
fd_set fds;
struct timeval timeout;
int retval;
/* No timeout if usec_timeout is negative */
if (usec_timeout < 0)
return select(io->fd + 1, &fds, NULL, NULL, NULL);
retval = select(io->fd + 1, &fds, NULL, NULL, NULL);
/* Handle timeout if specified */
else {
timeout.tv_sec = usec_timeout/1000000;
timeout.tv_usec = usec_timeout%1000000;
FD_ZERO(&fds);
FD_SET(io->fd, &fds);
return select(io->fd + 1, &fds, NULL, NULL, &timeout);
retval = select(io->fd + 1, &fds, NULL, NULL, &timeout);
}
/* Properly set guac_error */
if (retval < 0) guac_error = GUAC_STATUS_INPUT_ERROR;
if (retval == 0) guac_error = GUAC_STATUS_INPUT_TIMEOUT;
return retval;
}