7 /* read operation with pre-read timeout
9 /* #include <iostuff.h>
11 /* ssize_t timed_read(fd, buf, len, timeout, context)
18 /* timed_read() performs a read() operation when the specified
19 /* descriptor becomes readable within a user-specified deadline.
23 /* File descriptor in the range 0..FD_SETSIZE.
25 /* Read buffer pointer.
29 /* The deadline in seconds. If this is <= 0, the deadline feature
32 /* Application context. This parameter is unused. It exists only
33 /* for the sake of VSTREAM compatibility.
35 /* When the operation does not complete within the deadline, the
36 /* result value is -1, and errno is set to ETIMEDOUT.
37 /* All other returns are identical to those of a read(2) operation.
41 /* The Secure Mailer license must be distributed with this software.
44 /* IBM T.J. Watson Research
46 /* Yorktown Heights, NY 10598, USA
55 /* Utility library. */
60 /* timed_read - read with deadline */
62 ssize_t
timed_read(int fd
, void *buf
, size_t len
,
63 int timeout
, void *unused_context
)
68 * Wait for a limited amount of time for something to happen. If nothing
69 * happens, report an ETIMEDOUT error.
71 * XXX Solaris 8 read() fails with EAGAIN after read-select() returns
75 if (timeout
> 0 && read_wait(fd
, timeout
) < 0)
77 if ((ret
= read(fd
, buf
, len
)) < 0 && timeout
> 0 && errno
== EAGAIN
) {
78 msg_warn("read() returns EAGAIN on a readable file descriptor!");
79 msg_warn("pausing to avoid going into a tight select/read loop!");
82 } else if (ret
< 0 && errno
== EINTR
) {