105 #if defined(USE_SYSV_POLL_THEN_SELECT)
106 #define poll_fd_sysv poll_fd
107 #define USE_SYSV_POLL
108 #define USE_BSD_SELECT
114 #elif defined(USE_BSD_SELECT)
115 #define poll_fd_bsd poll_fd
121 #elif defined(USE_SYSV_POLL)
122 #define poll_fd_sysv poll_fd
128 #error "specify USE_SYSV_POLL, USE_BSD_SELECT or USE_SYSV_POLL_THEN_SELECT"
135 #ifdef USE_SYS_SELECT_H
136 #include <sys/select.h>
144 #ifdef USE_BSD_SELECT
149 int true_res,
int false_res)
162 if (FD_SETSIZE <= fd) {
163 if ((temp_fd = dup(fd)) < 0 || temp_fd >= FD_SETSIZE)
164 msg_fatal(
"descriptor %d does not fit FD_SETSIZE %d", fd, FD_SETSIZE);
175 FD_SET(fd, &req_fds);
176 except_fds = req_fds;
182 write_fds = &req_fds;
184 msg_panic(
"poll_fd: bad request %d", request);
187 if (time_limit >= 0) {
189 tv.tv_sec = time_limit;
196 switch (select(fd + 1, read_fds, write_fds, &except_fds, tp)) {
203 (void) close(temp_fd);
209 (void) close(temp_fd);
219 #ifdef USE_SYSV_POLL_THEN_SELECT
220 #define HANDLE_SYSV_POLL_ERROR(fd, req, time_limit, true_res, false_res) \
221 return (poll_fd_bsd((fd), (req), (time_limit), (true_res), (false_res)))
223 #define HANDLE_SYSV_POLL_ERROR(fd, req, time_limit, true_res, false_res) \
224 msg_fatal("poll: %m")
229 int poll_fd_sysv(
int fd,
int request,
int time_limit,
230 int true_res,
int false_res)
232 struct pollfd pollfd;
237 #define WAIT_FOR_EVENT (-1)
241 pollfd.events = POLLIN;
243 pollfd.events = POLLOUT;
245 msg_panic(
"poll_fd: bad request %d", request);
249 switch (poll(&pollfd, 1, time_limit < 0 ?
253 HANDLE_SYSV_POLL_ERROR(fd, request, time_limit,
254 true_res, false_res);
261 if (pollfd.revents & POLLNVAL)
262 HANDLE_SYSV_POLL_ERROR(fd, request, time_limit,
263 true_res, false_res);
NORETURN msg_panic(const char *fmt,...)
NORETURN msg_fatal(const char *fmt,...)