5
/* read operation with pre-read timeout
7
/* #include <iostuff.h>
9
/* int timed_read(fd, buf, buf_len, timeout, context)
16
/* timed_read() performs a read() operation when the specified
17
/* descriptor becomes readable within a user-specified deadline.
21
/* File descriptor in the range 0..FD_SETSIZE.
23
/* Read buffer pointer.
27
/* The deadline in seconds. If this is <= 0, the deadline feature
30
/* Application context. This parameter is unused. It exists only
31
/* for the sake of VSTREAM compatibility.
33
/* When the operation does not complete within the deadline, the
34
/* result value is -1, and errno is set to ETIMEDOUT.
35
/* All other returns are identical to those of a read(2) operation.
39
/* The Secure Mailer license must be distributed with this software.
42
/* IBM T.J. Watson Research
44
/* Yorktown Heights, NY 10598, USA
53
/* Utility library. */
58
/* timed_read - read with deadline */
60
int timed_read(int fd, void *buf, unsigned len,
61
int timeout, void *unused_context)
66
* Wait for a limited amount of time for something to happen. If nothing
67
* happens, report an ETIMEDOUT error.
69
* XXX Solaris 8 read() fails with EAGAIN after read-select() returns
73
if (timeout > 0 && read_wait(fd, timeout) < 0)
75
if ((ret = read(fd, buf, len)) < 0 && timeout > 0 && errno == EAGAIN) {
76
msg_warn("read() returns EAGAIN on a readable file descriptor!");
77
msg_warn("pausing to avoid going into a tight select/read loop!");