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

Comparing libev/ev.c (file contents):
Revision 1.26 by root, Wed Oct 31 21:50:15 2007 UTC vs.
Revision 1.27 by root, Wed Oct 31 22:16:36 2007 UTC

130/*****************************************************************************/ 130/*****************************************************************************/
131 131
132typedef struct 132typedef struct
133{ 133{
134 struct ev_io *head; 134 struct ev_io *head;
135 unsigned char wev, rev; /* want, received event set */ 135 int events;
136} ANFD; 136} ANFD;
137 137
138static ANFD *anfds; 138static ANFD *anfds;
139static int anfdmax; 139static int anfdmax;
140 140
141static int *fdchanges;
142static int fdchangemax, fdchangecnt;
143
144static void 141static void
145anfds_init (ANFD *base, int count) 142anfds_init (ANFD *base, int count)
146{ 143{
147 while (count--) 144 while (count--)
148 { 145 {
149 base->head = 0; 146 base->head = 0;
150 base->wev = base->rev = EV_NONE; 147 base->events = EV_NONE;
151 ++base; 148 ++base;
152 } 149 }
153} 150}
154 151
155typedef struct 152typedef struct
172 pendings [pendingcnt - 1].events = events; 169 pendings [pendingcnt - 1].events = events;
173 } 170 }
174} 171}
175 172
176static void 173static void
174queue_events (W *events, int eventcnt, int type)
175{
176 int i;
177
178 for (i = 0; i < eventcnt; ++i)
179 event (events [i], type);
180}
181
182static void
177fd_event (int fd, int events) 183fd_event (int fd, int events)
178{ 184{
179 ANFD *anfd = anfds + fd; 185 ANFD *anfd = anfds + fd;
180 struct ev_io *w; 186 struct ev_io *w;
181 187
186 if (ev) 192 if (ev)
187 event ((W)w, ev); 193 event ((W)w, ev);
188 } 194 }
189} 195}
190 196
197/*****************************************************************************/
198
199static int *fdchanges;
200static int fdchangemax, fdchangecnt;
201
191static void 202static void
192queue_events (W *events, int eventcnt, int type) 203fd_reify (void)
193{ 204{
194 int i; 205 int i;
195 206
196 for (i = 0; i < eventcnt; ++i) 207 for (i = 0; i < fdchangecnt; ++i)
197 event (events [i], type); 208 {
209 int fd = fdchanges [i];
210 ANFD *anfd = anfds + fd;
211 struct ev_io *w;
212
213 int events = 0;
214
215 for (w = anfd->head; w; w = w->next)
216 events |= w->events;
217
218 anfd->events &= ~EV_REIFY;
219
220 if (anfd->events != events)
221 {
222 method_modify (fd, anfd->events, events);
223 anfd->events = events;
224 }
225 }
226
227 fdchangecnt = 0;
228}
229
230static void
231fd_change (int fd)
232{
233 if (anfds [fd].events & EV_REIFY)
234 return;
235
236 anfds [fd].events |= EV_REIFY;
237
238 ++fdchangecnt;
239 array_needsize (fdchanges, fdchangemax, fdchangecnt, );
240 fdchanges [fdchangecnt - 1] = fd;
198} 241}
199 242
200/* called on EBADF to verify fds */ 243/* called on EBADF to verify fds */
201static void 244static void
202fd_recheck (void) 245fd_recheck (void)
203{ 246{
204 int fd; 247 int fd;
205 248
206 for (fd = 0; fd < anfdmax; ++fd) 249 for (fd = 0; fd < anfdmax; ++fd)
207 if (anfds [fd].wev) 250 if (anfds [fd].events)
208 if (fcntl (fd, F_GETFD) == -1 && errno == EBADF) 251 if (fcntl (fd, F_GETFD) == -1 && errno == EBADF)
209 while (anfds [fd].head) 252 while (anfds [fd].head)
210 { 253 {
211 event ((W)anfds [fd].head, EV_ERROR); 254 event ((W)anfds [fd].head, EV_ERROR);
212 evio_stop (anfds [fd].head); 255 evio_stop (anfds [fd].head);
459} 502}
460 503
461/*****************************************************************************/ 504/*****************************************************************************/
462 505
463static void 506static void
464fd_reify (void)
465{
466 int i;
467
468 for (i = 0; i < fdchangecnt; ++i)
469 {
470 int fd = fdchanges [i];
471 ANFD *anfd = anfds + fd;
472 struct ev_io *w;
473
474 int wev = 0;
475
476 for (w = anfd->head; w; w = w->next)
477 wev |= w->events;
478
479 if (anfd->wev != wev)
480 {
481 method_modify (fd, anfd->wev, wev);
482 anfd->wev = wev;
483 }
484 }
485
486 fdchangecnt = 0;
487}
488
489static void
490call_pending (void) 507call_pending (void)
491{ 508{
492 while (pendingcnt) 509 while (pendingcnt)
493 { 510 {
494 ANPENDING *p = pendings + --pendingcnt; 511 ANPENDING *p = pendings + --pendingcnt;
737 754
738 ev_start ((W)w, 1); 755 ev_start ((W)w, 1);
739 array_needsize (anfds, anfdmax, fd + 1, anfds_init); 756 array_needsize (anfds, anfdmax, fd + 1, anfds_init);
740 wlist_add ((WL *)&anfds[fd].head, (WL)w); 757 wlist_add ((WL *)&anfds[fd].head, (WL)w);
741 758
742 ++fdchangecnt; 759 fd_change (fd);
743 array_needsize (fdchanges, fdchangemax, fdchangecnt, );
744 fdchanges [fdchangecnt - 1] = fd;
745
746 if (w->fd == 9)
747 printf ("start %p:%x\n", w, w->events);//D
748} 760}
749 761
750void 762void
751evio_stop (struct ev_io *w) 763evio_stop (struct ev_io *w)
752{ 764{
753 if (w->fd == 9)
754 printf ("stop %p:%x\n", w, w->events);//D
755 ev_clear ((W)w); 765 ev_clear ((W)w);
756 if (!ev_is_active (w)) 766 if (!ev_is_active (w))
757 return; 767 return;
758 768
759 wlist_del ((WL *)&anfds[w->fd].head, (WL)w); 769 wlist_del ((WL *)&anfds[w->fd].head, (WL)w);
760 ev_stop ((W)w); 770 ev_stop ((W)w);
761 771
762 ++fdchangecnt; 772 fd_change (w->fd);
763 array_needsize (fdchanges, fdchangemax, fdchangecnt, );
764 fdchanges [fdchangecnt - 1] = w->fd;
765} 773}
766 774
767void 775void
768evtimer_start (struct ev_timer *w) 776evtimer_start (struct ev_timer *w)
769{ 777{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines