7 /* test if descriptor is writable
9 /* #include <iostuff.h>
14 /* writable() asks the kernel if the specified file descriptor
15 /* is writable, i.e. a write operation would not block.
19 /* File descriptor in the range 0..FD_SETSIZE.
21 /* All system call errors are fatal.
25 /* The Secure Mailer license must be distributed with this software.
28 /* IBM T.J. Watson Research
30 /* Yorktown Heights, NY 10598, USA
46 #ifdef USE_SYS_SELECT_H
47 #include <sys/select.h>
50 /* Utility library. */
55 /* writable - see if file descriptor is writable */
68 msg_fatal("fd %d does not fit in FD_SETSIZE", fd
);
74 FD_SET(fd
, &write_fds
);
76 FD_SET(fd
, &except_fds
);
81 * Loop until we have an authoritative answer.
84 switch (select(fd
+ 1, (fd_set
*) 0, &write_fds
, &except_fds
, &tv
)) {
87 msg_fatal("select: %m");
90 return (FD_ISSET(fd
, &write_fds
));
98 * System-V poll() is optimal for polling a few descriptors.
100 struct pollfd pollfd
;
102 #define DONT_WAIT_FOR_EVENT 0
105 pollfd
.events
= POLLOUT
;
107 switch (poll(&pollfd
, 1, DONT_WAIT_FOR_EVENT
)) {
110 msg_fatal("poll: %m");
115 if (pollfd
.revents
& POLLNVAL
)
116 msg_fatal("poll: %m");