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.2 by root, Fri Nov 2 16:54:35 2007 UTC vs.
Revision 1.6 by root, Sun Nov 4 23:14:11 2007 UTC

29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <poll.h> 32#include <poll.h>
33 33
34static struct pollfd *polls;
35static int pollmax, pollcnt;
36static int *pollidxs; /* maps fds into structure indices */
37static int pollidxmax;
38
39static void 34static void
40pollidx_init (int *base, int count) 35pollidx_init (int *base, int count)
41{ 36{
42 while (count--) 37 while (count--)
43 *base++ = -1; 38 *base++ = -1;
44} 39}
45 40
46static void 41static void
47poll_modify (int fd, int oev, int nev) 42poll_modify (EV_P_ int fd, int oev, int nev)
48{ 43{
49 int idx; 44 int idx;
45
46 if (oev == nev)
47 return;
48
50 array_needsize (pollidxs, pollidxmax, fd + 1, pollidx_init); 49 array_needsize (pollidxs, pollidxmax, fd + 1, pollidx_init);
51 50
52 idx = pollidxs [fd]; 51 idx = pollidxs [fd];
53 52
54 if (idx < 0) /* need to allocate a new pollfd */ 53 if (idx < 0) /* need to allocate a new pollfd */
72 } 71 }
73 } 72 }
74} 73}
75 74
76static void 75static void
77poll_poll (ev_tstamp timeout) 76poll_poll (EV_P_ ev_tstamp timeout)
78{ 77{
79 int res = poll (polls, pollcnt, ceil (timeout * 1000.)); 78 int res = poll (polls, pollcnt, ceil (timeout * 1000.));
80 79
81 if (res > 0) 80 if (res > 0)
82 { 81 {
83 int i; 82 int i;
84 83
85 for (i = 0; i < pollcnt; ++i) 84 for (i = 0; i < pollcnt; ++i)
86 fd_event ( 85 fd_event (
86 EV_A_
87 polls [i].fd, 87 polls [i].fd,
88 (polls [i].revents & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0) 88 (polls [i].revents & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0)
89 | (polls [i].revents & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0) 89 | (polls [i].revents & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0)
90 ); 90 );
91 } 91 }
92 else if (res < 0) 92 else if (res < 0)
93 { 93 {
94 if (errno == EBADF) 94 if (errno == EBADF)
95 fd_ebadf (); 95 fd_ebadf (EV_A);
96 else if (errno == ENOMEM) 96 else if (errno == ENOMEM)
97 fd_enomem (); 97 fd_enomem (EV_A);
98 } 98 }
99} 99}
100 100
101static void 101static int
102poll_init (int flags) 102poll_init (EV_P_ int flags)
103{ 103{
104 ev_method = EVMETHOD_POLL;
105 method_fudge = 1e-3; /* needed to compensate for select returning early, very conservative */ 104 method_fudge = 1e-3; /* needed to compensate for select returning early, very conservative */
106 method_modify = poll_modify; 105 method_modify = poll_modify;
107 method_poll = poll_poll; 106 method_poll = poll_poll;
107
108 pollidxs = 0; pollidxmax = 0;
109 polls = 0; pollmax = 0; pollcnt = 0;
110
111 return EVMETHOD_POLL;
108} 112}
113
114static void
115poll_destroy (EV_P)
116{
117 free (pollidxs);
118 free (polls);
119}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines