7 /* write operation with pre-write timeout
9 /* #include <iostuff.h>
11 /* ssize_t timed_write(fd, buf, len, timeout, context)
18 /* timed_write() performs a write() operation when the specified
19 /* descriptor becomes writable within a user-specified deadline.
23 /* File descriptor in the range 0..FD_SETSIZE.
25 /* Write 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 write(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_write - write with deadline */
62 ssize_t
timed_write(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
72 * success. The code below exists just in case their write implementation
75 * This condition may also be found on systems where select() returns
76 * success on pipes with less than PIPE_BUF bytes of space, and with
77 * badly designed software where multiple writers are fighting for access
78 * to the same resource.
81 if (timeout
> 0 && write_wait(fd
, timeout
) < 0)
83 if ((ret
= write(fd
, buf
, len
)) < 0 && timeout
> 0 && errno
== EAGAIN
) {
84 msg_warn("write() returns EAGAIN on a writable file descriptor!");
85 msg_warn("pausing to avoid going into a tight select/write loop!");
88 } else if (ret
< 0 && errno
== EINTR
) {