Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2013-08-31 23:36:27 +0200
committerArthur de Jong <arthur@arthurdejong.org>2013-08-31 23:37:16 +0200
commit644df526c13a45b5d5d985ecf3c9fbfd6e6f6d5d (patch)
tree36e1c24731ff39d2d7780c47b75e3ff7b392541f /common
parent0787d459f4401363a63ce5582c84ecd5fb7b286f (diff)
Use normal timeout handling in tio_skipall()
Use the same mechanism in tio_skipall() as in tio_read(), except use a different timeout value.
Diffstat (limited to 'common')
-rw-r--r--common/tio.c18
-rw-r--r--common/tio.h2
2 files changed, 6 insertions, 14 deletions
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);