From 644df526c13a45b5d5d985ecf3c9fbfd6e6f6d5d Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Sat, 31 Aug 2013 23:36:27 +0200 Subject: Use normal timeout handling in tio_skipall() Use the same mechanism in tio_skipall() as in tio_read(), except use a different timeout value. --- common/tio.c | 18 +++++------------- common/tio.h | 2 +- 2 files changed, 6 insertions(+), 14 deletions(-) (limited to 'common') diff --git a/common/tio.c b/common/tio.c index d68490a..aa032d7 100644 --- a/common/tio.c +++ b/common/tio.c @@ -282,9 +282,9 @@ int tio_skip(TFILE *fp, size_t count) } /* Read all available data from the stream and empty the read buffer. */ -int tio_skipall(TFILE *fp, int skiptimeout) +int tio_skipall(TFILE *fp, int timeout) { - struct pollfd fds[1]; + struct timeval deadline = {0, 0}; int rv; size_t len; /* clear the read buffer */ @@ -299,17 +299,9 @@ int tio_skipall(TFILE *fp, int skiptimeout) #endif /* SSIZE_MAX */ while (1) { - /* see if any data is available */ - fds[0].fd = fp->fd; - fds[0].events = POLLIN; - rv = poll(fds, 1, skiptimeout); - /* check the poll() result */ - if (rv == 0) - return 0; /* no file descriptor ready */ - if ((rv < 0) && ((errno == EINTR) || (errno == EAGAIN))) - continue; /* interrupted, try again */ - if (rv < 0) - return -1; /* something went wrong */ + /* wait until we have input */ + if (tio_wait(fp->fd, POLLIN, timeout, &deadline)) + return -1; /* read data from the stream */ rv = read(fp->fd, fp->readbuffer.buffer, len); if (rv == 0) diff --git a/common/tio.h b/common/tio.h index 7723ee2..3e0af12 100644 --- a/common/tio.h +++ b/common/tio.h @@ -59,7 +59,7 @@ int tio_read(TFILE *fp, void *buf, size_t count); int tio_skip(TFILE *fp, size_t count); /* Read all available data from the stream and empty the read buffer. */ -int tio_skipall(TFILE *fp, int skiptimeout); +int tio_skipall(TFILE *fp, int timeout); /* Write the specified buffer to the stream. */ int tio_write(TFILE *fp, const void *buf, size_t count); -- cgit v1.2.3