source: branches/ithildin-1.1/source/poller_select.c @ 578

Revision 578, 1.3 KB checked in by wd, 7 years ago (diff)

Expand tabs ('\t') to eight spaces.

  • Property svn:keywords set to Id Rev
Line 
1/*
2 * poller_select.c: select() polling mechanis,
3 *
4 * Copyright 2002 the Ithildin Project.
5 * See the COPYING file for more information on licensing and use.
6 */
7
8IDSTRING(poller_rcsid, "$Id$");
9
10int poll_sockets(time_t timeout) {
11    fd_set rfds, wfds;
12    struct timeval tv = {timeout, 0}; /* sleep at most 50ms */
13    struct isocket *sp;
14    int ret;
15
16    memcpy(&rfds, &select_rfds, sizeof(fd_set));
17    memcpy(&wfds, &select_wfds, sizeof(fd_set));
18
19    if ((ret = select(maxsockets, &rfds, &wfds, NULL,
20                    (timeout ? &tv : NULL))) == -1 && errno != EINTR) {
21        log_error("select(%d, %p, %p, NULL, %p) error: %s", maxsockets, &rfds,
22                &wfds, &tv, strerror(errno));
23        return 0;
24    } else if (ret <= 0)
25        return 1; /* nothing to do, but nothing wrong */
26
27    me.now = time(NULL);
28    LIST_FOREACH(sp, &allsockets, intlp) {
29        if (SOCKET_DEAD(sp) || sp->fd < 0)
30            continue; /* dead socket. */
31        if (FD_ISSET(sp->fd, &rfds))
32            sp->state |= SOCKET_FL_READ_PENDING;
33        if (FD_ISSET(sp->fd, &wfds)) {
34            sp->state |= SOCKET_FL_WRITE_PENDING;
35            socket_unmonitor(sp, SOCKET_FL_WRITE);
36        }
37        if (sp->state & SOCKET_FL_PENDING)
38            socket_event(sp);
39    }
40       
41    return 1;
42}
43/* vi:set ts=8 sts=4 sw=4 tw=76 et: */
Note: See TracBrowser for help on using the repository browser.