ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev_poll.c
(Generate patch)

Comparing libev/ev_poll.c (file contents):
Revision 1.4 by root, Sun Nov 4 15:58:50 2007 UTC vs.
Revision 1.9 by root, Tue Nov 6 17:09:45 2007 UTC

40 40
41static void 41static void
42poll_modify (EV_P_ int fd, int oev, int nev) 42poll_modify (EV_P_ int fd, int oev, int nev)
43{ 43{
44 int idx; 44 int idx;
45
46 if (oev == nev)
47 return;
48
45 array_needsize (pollidxs, pollidxmax, fd + 1, pollidx_init); 49 array_needsize (int, pollidxs, pollidxmax, fd + 1, pollidx_init);
46 50
47 idx = pollidxs [fd]; 51 idx = pollidxs [fd];
48 52
49 if (idx < 0) /* need to allocate a new pollfd */ 53 if (idx < 0) /* need to allocate a new pollfd */
50 { 54 {
51 idx = pollcnt++; 55 idx = pollcnt++;
52 array_needsize (polls, pollmax, pollcnt, ); 56 array_needsize (struct pollfd, polls, pollmax, pollcnt, );
53 polls [idx].fd = fd; 57 polls [idx].fd = fd;
54 } 58 }
55 59
56 if (nev) 60 if (nev)
57 polls [idx].events = 61 polls [idx].events =
69} 73}
70 74
71static void 75static void
72poll_poll (EV_P_ ev_tstamp timeout) 76poll_poll (EV_P_ ev_tstamp timeout)
73{ 77{
78 int i;
74 int res = poll (polls, pollcnt, ceil (timeout * 1000.)); 79 int res = poll (polls, pollcnt, ceil (timeout * 1000.));
75 80
76 if (res > 0) 81 if (res < 0)
77 {
78 int i;
79
80 for (i = 0; i < pollcnt; ++i)
81 fd_event (
82 EV_A_
83 polls [i].fd,
84 (polls [i].revents & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0)
85 | (polls [i].revents & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0)
86 );
87 }
88 else if (res < 0)
89 { 82 {
90 if (errno == EBADF) 83 if (errno == EBADF)
91 fd_ebadf (EV_A); 84 fd_ebadf (EV_A);
92 else if (errno == ENOMEM) 85 else if (errno == ENOMEM && !syserr_cb)
93 fd_enomem (EV_A); 86 fd_enomem (EV_A);
87 else if (errno != EINTR)
88 syserr ("(libev) poll");
89
90 return;
94 } 91 }
92
93 for (i = 0; i < pollcnt; ++i)
94 fd_event (
95 EV_A_
96 polls [i].fd,
97 (polls [i].revents & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0)
98 | (polls [i].revents & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0)
99 );
95} 100}
96 101
97static int 102static int
98poll_init (EV_P_ int flags) 103poll_init (EV_P_ int flags)
99{ 104{
100 method_fudge = 1e-3; /* needed to compensate for select returning early, very conservative */ 105 method_fudge = 1e-3; /* needed to compensate for select returning early, very conservative */
101 method_modify = poll_modify; 106 method_modify = poll_modify;
102 method_poll = poll_poll; 107 method_poll = poll_poll;
103 108
104 pollidxs = 0; pollidxmax = 0; 109 pollidxs = 0; pollidxmax = 0;
105 polls = 0; pollsmax = 0; pollscnt = 0; 110 polls = 0; pollmax = 0; pollcnt = 0;
106 111
107 return EVMETHOD_POLL; 112 return EVMETHOD_POLL;
108} 113}
109 114
110static void 115static void
111poll_destroy (EV_P) 116poll_destroy (EV_P)
112{ 117{
113 free (pollidxs); 118 ev_free (pollidxs);
114 free (polls); 119 ev_free (polls);
115} 120}
121

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines