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.6 by root, Sun Nov 4 23:14:11 2007 UTC vs.
Revision 1.11 by root, Sat Nov 10 17:47:05 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines