22 #include <sys/types.h>
31 #include <sys/select.h>
35 #define FD_SETSIZE 512
55 fd_set input, output, except;
64 for (i = 0; i < num_fds; i++)
83 tv.tv_usec = nsec / 1000;
85 r = select(max_fd+1, &input, &output, &except, (sec == -1 ? 0 : &tv));
88 for (i = 0; i < num_fds; i++)
95 if (FD_ISSET(fd, &input))
97 if (FD_ISSET(fd, &output))
99 if (FD_ISSET(fd, &except))
109 int yaz_poll_poll(
struct yaz_poll_fd *fds,
int num_fds,
int sec,
int nsec)
112 struct pollfd *pollfds = 0;
115 pollfds = (
struct pollfd *)
xmalloc(num_fds *
sizeof *pollfds);
117 assert(num_fds >= 0);
118 for (i = 0; i < num_fds; i++)
122 short poll_events = 0;
125 poll_events += POLLIN;
127 poll_events += POLLOUT;
129 poll_events += POLLERR;
131 pollfds[i].events = poll_events;
132 pollfds[i].revents = 0;
134 r = poll(pollfds, num_fds, sec == -1 ? -1 : sec*1000 + nsec/1000000);
137 for (i = 0; i < num_fds; i++)
144 if (pollfds[i].revents & POLLIN)
146 if (pollfds[i].revents & POLLOUT)
148 if (pollfds[i].revents & ~(POLLIN | POLLOUT))
164 return yaz_poll_poll(fds, num_fds, sec, nsec);
Header for errno utilities.
int yaz_poll(struct yaz_poll_fd *fds, int num_fds, int sec, int nsec)
poll wrapper for poll or select
int yaz_poll_select(struct yaz_poll_fd *fds, int num_fds, int sec, int nsec)
#define yaz_poll_add(var, value)
yaz_poll_mask
select/poll masks .. timeout is "output" only
enum yaz_poll_mask output_mask
enum yaz_poll_mask input_mask
Header for memory handling functions.
#define xfree(x)
utility macro which calls xfree_f
#define xmalloc(x)
utility macro which calls malloc_f