2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: zoom-socket.c,v 1.1 2007-01-09 13:56:48 adam Exp $
9 * \brief Implements ZOOM C socket interface.
20 #include <sys/types.h>
29 #include <sys/select.h>
33 #define FD_SETSIZE 512
40 ZOOM_event_sys_select(int no, ZOOM_connection *cs)
43 fd_set input, output, except;
53 for (i = 0; i<no; i++)
55 ZOOM_connection c = cs[i];
60 fd = ZOOM_connection_get_socket(c);
61 mask = ZOOM_connection_get_mask(c);
62 timeout = ZOOM_connection_get_timeout(c);
69 if (mask & ZOOM_SELECT_READ)
71 if (mask & ZOOM_SELECT_WRITE)
73 if (mask & ZOOM_SELECT_EXCEPT)
84 while ((r = select(max_fd+1, &input, &output, &except,
85 (timeout == -1 ? 0 : &tv))) < 0 && errno == EINTR)
91 yaz_log(YLOG_WARN|YLOG_ERRNO, "ZOOM_event_sys_select");
95 for (i = 0; i<no; i++)
97 ZOOM_connection c = cs[i];
102 fd = ZOOM_connection_get_socket(c);
106 /* no timeout and real socket */
107 if (FD_ISSET(fd, &input))
108 mask += ZOOM_SELECT_READ;
109 if (FD_ISSET(fd, &output))
110 mask += ZOOM_SELECT_WRITE;
111 if (FD_ISSET(fd, &except))
112 mask += ZOOM_SELECT_EXCEPT;
114 ZOOM_connection_fire_event_socket(c, mask);
117 ZOOM_connection_fire_event_timeout(c);
124 ZOOM_event_sys_poll(int no, ZOOM_connection *cs)
126 struct pollfd pollfds[1024];
127 ZOOM_connection poll_cs[1024];
132 for (i = 0; i<no; i++)
134 ZOOM_connection c = cs[i];
139 fd = ZOOM_connection_get_socket(c);
140 mask = ZOOM_connection_get_mask(c);
141 timeout = ZOOM_connection_get_timeout(c);
147 short poll_events = 0;
149 if (mask & ZOOM_SELECT_READ)
150 poll_events += POLLIN;
151 if (mask & ZOOM_SELECT_WRITE)
152 poll_events += POLLOUT;
153 if (mask & ZOOM_SELECT_EXCEPT)
154 poll_events += POLLERR;
155 pollfds[nfds].fd = fd;
156 pollfds[nfds].events = poll_events;
157 pollfds[nfds].revents = 0;
164 while ((r = poll(pollfds, nfds,
165 (timeout == -1 ? -1 : timeout * 1000))) < 0
172 yaz_log(YLOG_WARN|YLOG_ERRNO, "ZOOM_event_sys_poll");
175 for (i = 0; i<nfds; i++)
177 ZOOM_connection c = poll_cs[i];
181 if (pollfds[i].revents & POLLIN)
182 mask += ZOOM_SELECT_READ;
183 if (pollfds[i].revents & POLLOUT)
184 mask += ZOOM_SELECT_WRITE;
185 if (pollfds[i].revents & POLLERR)
186 mask += ZOOM_SELECT_EXCEPT;
187 ZOOM_connection_fire_event_socket(c, mask);
190 ZOOM_connection_fire_event_timeout(c);
197 ZOOM_event(int no, ZOOM_connection *cs)
201 r = ZOOM_process_event(no, cs);
205 ZOOM_event_sys_poll(no, cs);
207 ZOOM_event_sys_select(no, cs);
209 return ZOOM_process_event(no, cs);
215 * indent-tabs-mode: nil
217 * vim: shiftwidth=4 tabstop=8 expandtab