… | |
… | |
130 | /*****************************************************************************/ |
130 | /*****************************************************************************/ |
131 | |
131 | |
132 | typedef struct |
132 | typedef 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 | |
138 | static ANFD *anfds; |
138 | static ANFD *anfds; |
139 | static int anfdmax; |
139 | static int anfdmax; |
140 | |
140 | |
141 | static int *fdchanges; |
|
|
142 | static int fdchangemax, fdchangecnt; |
|
|
143 | |
|
|
144 | static void |
141 | static void |
145 | anfds_init (ANFD *base, int count) |
142 | anfds_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 | |
155 | typedef struct |
152 | typedef struct |
… | |
… | |
172 | pendings [pendingcnt - 1].events = events; |
169 | pendings [pendingcnt - 1].events = events; |
173 | } |
170 | } |
174 | } |
171 | } |
175 | |
172 | |
176 | static void |
173 | static void |
|
|
174 | queue_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 | |
|
|
182 | static void |
177 | fd_event (int fd, int events) |
183 | fd_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 | |
|
|
199 | static int *fdchanges; |
|
|
200 | static int fdchangemax, fdchangecnt; |
|
|
201 | |
191 | static void |
202 | static void |
192 | queue_events (W *events, int eventcnt, int type) |
203 | fd_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 | |
|
|
230 | static void |
|
|
231 | fd_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 */ |
201 | static void |
244 | static void |
202 | fd_recheck (void) |
245 | fd_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 | ev_io_stop (anfds [fd].head); |
213 | } |
256 | } |
214 | } |
257 | } |
215 | |
258 | |
216 | /*****************************************************************************/ |
259 | /*****************************************************************************/ |
217 | |
260 | |
… | |
… | |
327 | |
370 | |
328 | /* rather than sort out wether we really need nb, set it */ |
371 | /* rather than sort out wether we really need nb, set it */ |
329 | fcntl (sigpipe [0], F_SETFL, O_NONBLOCK); |
372 | fcntl (sigpipe [0], F_SETFL, O_NONBLOCK); |
330 | fcntl (sigpipe [1], F_SETFL, O_NONBLOCK); |
373 | fcntl (sigpipe [1], F_SETFL, O_NONBLOCK); |
331 | |
374 | |
332 | evio_set (&sigev, sigpipe [0], EV_READ); |
375 | ev_io_set (&sigev, sigpipe [0], EV_READ); |
333 | evio_start (&sigev); |
376 | ev_io_start (&sigev); |
334 | } |
377 | } |
335 | |
378 | |
336 | /*****************************************************************************/ |
379 | /*****************************************************************************/ |
337 | |
380 | |
338 | static struct ev_idle **idles; |
381 | static struct ev_idle **idles; |
… | |
… | |
416 | if (ev_method == EVMETHOD_NONE) select_init (flags); |
459 | if (ev_method == EVMETHOD_NONE) select_init (flags); |
417 | #endif |
460 | #endif |
418 | |
461 | |
419 | if (ev_method) |
462 | if (ev_method) |
420 | { |
463 | { |
421 | evw_init (&sigev, sigcb); |
464 | ev_watcher_init (&sigev, sigcb); |
422 | siginit (); |
465 | siginit (); |
423 | |
466 | |
424 | evsignal_init (&childev, childcb, SIGCHLD); |
467 | ev_signal_init (&childev, childcb, SIGCHLD); |
425 | evsignal_start (&childev); |
468 | ev_signal_start (&childev); |
426 | } |
469 | } |
427 | } |
470 | } |
428 | |
471 | |
429 | return ev_method; |
472 | return ev_method; |
430 | } |
473 | } |
… | |
… | |
449 | #if HAVE_EPOLL |
492 | #if HAVE_EPOLL |
450 | if (ev_method == EVMETHOD_EPOLL) |
493 | if (ev_method == EVMETHOD_EPOLL) |
451 | epoll_postfork_child (); |
494 | epoll_postfork_child (); |
452 | #endif |
495 | #endif |
453 | |
496 | |
454 | evio_stop (&sigev); |
497 | ev_io_stop (&sigev); |
455 | close (sigpipe [0]); |
498 | close (sigpipe [0]); |
456 | close (sigpipe [1]); |
499 | close (sigpipe [1]); |
457 | pipe (sigpipe); |
500 | pipe (sigpipe); |
458 | siginit (); |
501 | siginit (); |
459 | } |
502 | } |
460 | |
503 | |
461 | /*****************************************************************************/ |
504 | /*****************************************************************************/ |
462 | |
505 | |
463 | static void |
506 | static void |
464 | fd_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 | |
|
|
489 | static void |
|
|
490 | call_pending (void) |
507 | call_pending (void) |
491 | { |
508 | { |
492 | while (pendingcnt) |
509 | while (pendingcnt) |
493 | { |
510 | { |
494 | ANPENDING *p = pendings + --pendingcnt; |
511 | ANPENDING *p = pendings + --pendingcnt; |
… | |
… | |
516 | w->at = now + w->repeat; |
533 | w->at = now + w->repeat; |
517 | assert (("timer timeout in the past, negative repeat?", w->at > now)); |
534 | assert (("timer timeout in the past, negative repeat?", w->at > now)); |
518 | downheap ((WT *)timers, timercnt, 0); |
535 | downheap ((WT *)timers, timercnt, 0); |
519 | } |
536 | } |
520 | else |
537 | else |
521 | evtimer_stop (w); /* nonrepeating: stop timer */ |
538 | ev_timer_stop (w); /* nonrepeating: stop timer */ |
522 | } |
539 | } |
523 | } |
540 | } |
524 | |
541 | |
525 | static void |
542 | static void |
526 | periodics_reify (void) |
543 | periodics_reify (void) |
… | |
… | |
535 | w->at += floor ((ev_now - w->at) / w->interval + 1.) * w->interval; |
552 | w->at += floor ((ev_now - w->at) / w->interval + 1.) * w->interval; |
536 | assert (("periodic timeout in the past, negative interval?", w->at > ev_now)); |
553 | assert (("periodic timeout in the past, negative interval?", w->at > ev_now)); |
537 | downheap ((WT *)periodics, periodiccnt, 0); |
554 | downheap ((WT *)periodics, periodiccnt, 0); |
538 | } |
555 | } |
539 | else |
556 | else |
540 | evperiodic_stop (w); /* nonrepeating: stop timer */ |
557 | ev_periodic_stop (w); /* nonrepeating: stop timer */ |
541 | |
558 | |
542 | event ((W)w, EV_TIMEOUT); |
559 | event ((W)w, EV_TIMEOUT); |
543 | } |
560 | } |
544 | } |
561 | } |
545 | |
562 | |
… | |
… | |
557 | { |
574 | { |
558 | ev_tstamp diff = ceil ((ev_now - w->at) / w->interval) * w->interval; |
575 | ev_tstamp diff = ceil ((ev_now - w->at) / w->interval) * w->interval; |
559 | |
576 | |
560 | if (fabs (diff) >= 1e-4) |
577 | if (fabs (diff) >= 1e-4) |
561 | { |
578 | { |
562 | evperiodic_stop (w); |
579 | ev_periodic_stop (w); |
563 | evperiodic_start (w); |
580 | ev_periodic_start (w); |
564 | |
581 | |
565 | i = 0; /* restart loop, inefficient, but time jumps should be rare */ |
582 | i = 0; /* restart loop, inefficient, but time jumps should be rare */ |
566 | } |
583 | } |
567 | } |
584 | } |
568 | } |
585 | } |
… | |
… | |
611 | int ev_loop_done; |
628 | int ev_loop_done; |
612 | |
629 | |
613 | void ev_loop (int flags) |
630 | void ev_loop (int flags) |
614 | { |
631 | { |
615 | double block; |
632 | double block; |
616 | ev_loop_done = flags & EVLOOP_ONESHOT ? 1 : 0; |
633 | ev_loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0; |
617 | |
634 | |
618 | do |
635 | do |
619 | { |
636 | { |
620 | /* queue check watchers (and execute them) */ |
637 | /* queue check watchers (and execute them) */ |
621 | if (preparecnt) |
638 | if (preparecnt) |
… | |
… | |
726 | } |
743 | } |
727 | |
744 | |
728 | /*****************************************************************************/ |
745 | /*****************************************************************************/ |
729 | |
746 | |
730 | void |
747 | void |
731 | evio_start (struct ev_io *w) |
748 | ev_io_start (struct ev_io *w) |
732 | { |
749 | { |
733 | if (ev_is_active (w)) |
750 | if (ev_is_active (w)) |
734 | return; |
751 | return; |
735 | |
752 | |
736 | int fd = w->fd; |
753 | int fd = w->fd; |
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 | |
750 | void |
762 | void |
751 | evio_stop (struct ev_io *w) |
763 | ev_io_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 | |
767 | void |
775 | void |
768 | evtimer_start (struct ev_timer *w) |
776 | ev_timer_start (struct ev_timer *w) |
769 | { |
777 | { |
770 | if (ev_is_active (w)) |
778 | if (ev_is_active (w)) |
771 | return; |
779 | return; |
772 | |
780 | |
773 | w->at += now; |
781 | w->at += now; |
… | |
… | |
779 | timers [timercnt - 1] = w; |
787 | timers [timercnt - 1] = w; |
780 | upheap ((WT *)timers, timercnt - 1); |
788 | upheap ((WT *)timers, timercnt - 1); |
781 | } |
789 | } |
782 | |
790 | |
783 | void |
791 | void |
784 | evtimer_stop (struct ev_timer *w) |
792 | ev_timer_stop (struct ev_timer *w) |
785 | { |
793 | { |
786 | ev_clear ((W)w); |
794 | ev_clear ((W)w); |
787 | if (!ev_is_active (w)) |
795 | if (!ev_is_active (w)) |
788 | return; |
796 | return; |
789 | |
797 | |
… | |
… | |
797 | |
805 | |
798 | ev_stop ((W)w); |
806 | ev_stop ((W)w); |
799 | } |
807 | } |
800 | |
808 | |
801 | void |
809 | void |
802 | evtimer_again (struct ev_timer *w) |
810 | ev_timer_again (struct ev_timer *w) |
803 | { |
811 | { |
804 | if (ev_is_active (w)) |
812 | if (ev_is_active (w)) |
805 | { |
813 | { |
806 | if (w->repeat) |
814 | if (w->repeat) |
807 | { |
815 | { |
808 | w->at = now + w->repeat; |
816 | w->at = now + w->repeat; |
809 | downheap ((WT *)timers, timercnt, w->active - 1); |
817 | downheap ((WT *)timers, timercnt, w->active - 1); |
810 | } |
818 | } |
811 | else |
819 | else |
812 | evtimer_stop (w); |
820 | ev_timer_stop (w); |
813 | } |
821 | } |
814 | else if (w->repeat) |
822 | else if (w->repeat) |
815 | evtimer_start (w); |
823 | ev_timer_start (w); |
816 | } |
824 | } |
817 | |
825 | |
818 | void |
826 | void |
819 | evperiodic_start (struct ev_periodic *w) |
827 | ev_periodic_start (struct ev_periodic *w) |
820 | { |
828 | { |
821 | if (ev_is_active (w)) |
829 | if (ev_is_active (w)) |
822 | return; |
830 | return; |
823 | |
831 | |
824 | assert (("periodic interval value less than zero not allowed", w->interval >= 0.)); |
832 | assert (("periodic interval value less than zero not allowed", w->interval >= 0.)); |
… | |
… | |
832 | periodics [periodiccnt - 1] = w; |
840 | periodics [periodiccnt - 1] = w; |
833 | upheap ((WT *)periodics, periodiccnt - 1); |
841 | upheap ((WT *)periodics, periodiccnt - 1); |
834 | } |
842 | } |
835 | |
843 | |
836 | void |
844 | void |
837 | evperiodic_stop (struct ev_periodic *w) |
845 | ev_periodic_stop (struct ev_periodic *w) |
838 | { |
846 | { |
839 | ev_clear ((W)w); |
847 | ev_clear ((W)w); |
840 | if (!ev_is_active (w)) |
848 | if (!ev_is_active (w)) |
841 | return; |
849 | return; |
842 | |
850 | |
… | |
… | |
848 | |
856 | |
849 | ev_stop ((W)w); |
857 | ev_stop ((W)w); |
850 | } |
858 | } |
851 | |
859 | |
852 | void |
860 | void |
853 | evsignal_start (struct ev_signal *w) |
861 | ev_signal_start (struct ev_signal *w) |
854 | { |
862 | { |
855 | if (ev_is_active (w)) |
863 | if (ev_is_active (w)) |
856 | return; |
864 | return; |
857 | |
865 | |
858 | ev_start ((W)w, 1); |
866 | ev_start ((W)w, 1); |
… | |
… | |
868 | sigaction (w->signum, &sa, 0); |
876 | sigaction (w->signum, &sa, 0); |
869 | } |
877 | } |
870 | } |
878 | } |
871 | |
879 | |
872 | void |
880 | void |
873 | evsignal_stop (struct ev_signal *w) |
881 | ev_signal_stop (struct ev_signal *w) |
874 | { |
882 | { |
875 | ev_clear ((W)w); |
883 | ev_clear ((W)w); |
876 | if (!ev_is_active (w)) |
884 | if (!ev_is_active (w)) |
877 | return; |
885 | return; |
878 | |
886 | |
… | |
… | |
881 | |
889 | |
882 | if (!signals [w->signum - 1].head) |
890 | if (!signals [w->signum - 1].head) |
883 | signal (w->signum, SIG_DFL); |
891 | signal (w->signum, SIG_DFL); |
884 | } |
892 | } |
885 | |
893 | |
|
|
894 | void |
886 | void evidle_start (struct ev_idle *w) |
895 | ev_idle_start (struct ev_idle *w) |
887 | { |
896 | { |
888 | if (ev_is_active (w)) |
897 | if (ev_is_active (w)) |
889 | return; |
898 | return; |
890 | |
899 | |
891 | ev_start ((W)w, ++idlecnt); |
900 | ev_start ((W)w, ++idlecnt); |
892 | array_needsize (idles, idlemax, idlecnt, ); |
901 | array_needsize (idles, idlemax, idlecnt, ); |
893 | idles [idlecnt - 1] = w; |
902 | idles [idlecnt - 1] = w; |
894 | } |
903 | } |
895 | |
904 | |
|
|
905 | void |
896 | void evidle_stop (struct ev_idle *w) |
906 | ev_idle_stop (struct ev_idle *w) |
897 | { |
907 | { |
898 | ev_clear ((W)w); |
908 | ev_clear ((W)w); |
899 | if (ev_is_active (w)) |
909 | if (ev_is_active (w)) |
900 | return; |
910 | return; |
901 | |
911 | |
902 | idles [w->active - 1] = idles [--idlecnt]; |
912 | idles [w->active - 1] = idles [--idlecnt]; |
903 | ev_stop ((W)w); |
913 | ev_stop ((W)w); |
904 | } |
914 | } |
905 | |
915 | |
|
|
916 | void |
906 | void evprepare_start (struct ev_prepare *w) |
917 | ev_prepare_start (struct ev_prepare *w) |
907 | { |
918 | { |
908 | if (ev_is_active (w)) |
919 | if (ev_is_active (w)) |
909 | return; |
920 | return; |
910 | |
921 | |
911 | ev_start ((W)w, ++preparecnt); |
922 | ev_start ((W)w, ++preparecnt); |
912 | array_needsize (prepares, preparemax, preparecnt, ); |
923 | array_needsize (prepares, preparemax, preparecnt, ); |
913 | prepares [preparecnt - 1] = w; |
924 | prepares [preparecnt - 1] = w; |
914 | } |
925 | } |
915 | |
926 | |
|
|
927 | void |
916 | void evprepare_stop (struct ev_prepare *w) |
928 | ev_prepare_stop (struct ev_prepare *w) |
917 | { |
929 | { |
918 | ev_clear ((W)w); |
930 | ev_clear ((W)w); |
919 | if (ev_is_active (w)) |
931 | if (ev_is_active (w)) |
920 | return; |
932 | return; |
921 | |
933 | |
922 | prepares [w->active - 1] = prepares [--preparecnt]; |
934 | prepares [w->active - 1] = prepares [--preparecnt]; |
923 | ev_stop ((W)w); |
935 | ev_stop ((W)w); |
924 | } |
936 | } |
925 | |
937 | |
|
|
938 | void |
926 | void evcheck_start (struct ev_check *w) |
939 | ev_check_start (struct ev_check *w) |
927 | { |
940 | { |
928 | if (ev_is_active (w)) |
941 | if (ev_is_active (w)) |
929 | return; |
942 | return; |
930 | |
943 | |
931 | ev_start ((W)w, ++checkcnt); |
944 | ev_start ((W)w, ++checkcnt); |
932 | array_needsize (checks, checkmax, checkcnt, ); |
945 | array_needsize (checks, checkmax, checkcnt, ); |
933 | checks [checkcnt - 1] = w; |
946 | checks [checkcnt - 1] = w; |
934 | } |
947 | } |
935 | |
948 | |
|
|
949 | void |
936 | void evcheck_stop (struct ev_check *w) |
950 | ev_check_stop (struct ev_check *w) |
937 | { |
951 | { |
938 | ev_clear ((W)w); |
952 | ev_clear ((W)w); |
939 | if (ev_is_active (w)) |
953 | if (ev_is_active (w)) |
940 | return; |
954 | return; |
941 | |
955 | |
942 | checks [w->active - 1] = checks [--checkcnt]; |
956 | checks [w->active - 1] = checks [--checkcnt]; |
943 | ev_stop ((W)w); |
957 | ev_stop ((W)w); |
944 | } |
958 | } |
945 | |
959 | |
|
|
960 | void |
946 | void evchild_start (struct ev_child *w) |
961 | ev_child_start (struct ev_child *w) |
947 | { |
962 | { |
948 | if (ev_is_active (w)) |
963 | if (ev_is_active (w)) |
949 | return; |
964 | return; |
950 | |
965 | |
951 | ev_start ((W)w, 1); |
966 | ev_start ((W)w, 1); |
952 | wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
967 | wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
953 | } |
968 | } |
954 | |
969 | |
|
|
970 | void |
955 | void evchild_stop (struct ev_child *w) |
971 | ev_child_stop (struct ev_child *w) |
956 | { |
972 | { |
957 | ev_clear ((W)w); |
973 | ev_clear ((W)w); |
958 | if (ev_is_active (w)) |
974 | if (ev_is_active (w)) |
959 | return; |
975 | return; |
960 | |
976 | |
… | |
… | |
976 | once_cb (struct ev_once *once, int revents) |
992 | once_cb (struct ev_once *once, int revents) |
977 | { |
993 | { |
978 | void (*cb)(int revents, void *arg) = once->cb; |
994 | void (*cb)(int revents, void *arg) = once->cb; |
979 | void *arg = once->arg; |
995 | void *arg = once->arg; |
980 | |
996 | |
981 | evio_stop (&once->io); |
997 | ev_io_stop (&once->io); |
982 | evtimer_stop (&once->to); |
998 | ev_timer_stop (&once->to); |
983 | free (once); |
999 | free (once); |
984 | |
1000 | |
985 | cb (revents, arg); |
1001 | cb (revents, arg); |
986 | } |
1002 | } |
987 | |
1003 | |
… | |
… | |
1007 | else |
1023 | else |
1008 | { |
1024 | { |
1009 | once->cb = cb; |
1025 | once->cb = cb; |
1010 | once->arg = arg; |
1026 | once->arg = arg; |
1011 | |
1027 | |
1012 | evw_init (&once->io, once_cb_io); |
1028 | ev_watcher_init (&once->io, once_cb_io); |
1013 | |
1029 | |
1014 | if (fd >= 0) |
1030 | if (fd >= 0) |
1015 | { |
1031 | { |
1016 | evio_set (&once->io, fd, events); |
1032 | ev_io_set (&once->io, fd, events); |
1017 | evio_start (&once->io); |
1033 | ev_io_start (&once->io); |
1018 | } |
1034 | } |
1019 | |
1035 | |
1020 | evw_init (&once->to, once_cb_to); |
1036 | ev_watcher_init (&once->to, once_cb_to); |
1021 | |
1037 | |
1022 | if (timeout >= 0.) |
1038 | if (timeout >= 0.) |
1023 | { |
1039 | { |
1024 | evtimer_set (&once->to, timeout, 0.); |
1040 | ev_timer_set (&once->to, timeout, 0.); |
1025 | evtimer_start (&once->to); |
1041 | ev_timer_start (&once->to); |
1026 | } |
1042 | } |
1027 | } |
1043 | } |
1028 | } |
1044 | } |
1029 | |
1045 | |
1030 | /*****************************************************************************/ |
1046 | /*****************************************************************************/ |
… | |
… | |
1041 | |
1057 | |
1042 | static void |
1058 | static void |
1043 | ocb (struct ev_timer *w, int revents) |
1059 | ocb (struct ev_timer *w, int revents) |
1044 | { |
1060 | { |
1045 | //fprintf (stderr, "timer %f,%f (%x) (%f) d%p\n", w->at, w->repeat, revents, w->at - ev_time (), w->data); |
1061 | //fprintf (stderr, "timer %f,%f (%x) (%f) d%p\n", w->at, w->repeat, revents, w->at - ev_time (), w->data); |
1046 | evtimer_stop (w); |
1062 | ev_timer_stop (w); |
1047 | evtimer_start (w); |
1063 | ev_timer_start (w); |
1048 | } |
1064 | } |
1049 | |
1065 | |
1050 | static void |
1066 | static void |
1051 | scb (struct ev_signal *w, int revents) |
1067 | scb (struct ev_signal *w, int revents) |
1052 | { |
1068 | { |
1053 | fprintf (stderr, "signal %x,%d\n", revents, w->signum); |
1069 | fprintf (stderr, "signal %x,%d\n", revents, w->signum); |
1054 | evio_stop (&wio); |
1070 | ev_io_stop (&wio); |
1055 | evio_start (&wio); |
1071 | ev_io_start (&wio); |
1056 | } |
1072 | } |
1057 | |
1073 | |
1058 | static void |
1074 | static void |
1059 | gcb (struct ev_signal *w, int revents) |
1075 | gcb (struct ev_signal *w, int revents) |
1060 | { |
1076 | { |
… | |
… | |
1064 | |
1080 | |
1065 | int main (void) |
1081 | int main (void) |
1066 | { |
1082 | { |
1067 | ev_init (0); |
1083 | ev_init (0); |
1068 | |
1084 | |
1069 | evio_init (&wio, sin_cb, 0, EV_READ); |
1085 | ev_io_init (&wio, sin_cb, 0, EV_READ); |
1070 | evio_start (&wio); |
1086 | ev_io_start (&wio); |
1071 | |
1087 | |
1072 | struct ev_timer t[10000]; |
1088 | struct ev_timer t[10000]; |
1073 | |
1089 | |
1074 | #if 0 |
1090 | #if 0 |
1075 | int i; |
1091 | int i; |
1076 | for (i = 0; i < 10000; ++i) |
1092 | for (i = 0; i < 10000; ++i) |
1077 | { |
1093 | { |
1078 | struct ev_timer *w = t + i; |
1094 | struct ev_timer *w = t + i; |
1079 | evw_init (w, ocb, i); |
1095 | ev_watcher_init (w, ocb, i); |
1080 | evtimer_init_abs (w, ocb, drand48 (), 0.99775533); |
1096 | ev_timer_init_abs (w, ocb, drand48 (), 0.99775533); |
1081 | evtimer_start (w); |
1097 | ev_timer_start (w); |
1082 | if (drand48 () < 0.5) |
1098 | if (drand48 () < 0.5) |
1083 | evtimer_stop (w); |
1099 | ev_timer_stop (w); |
1084 | } |
1100 | } |
1085 | #endif |
1101 | #endif |
1086 | |
1102 | |
1087 | struct ev_timer t1; |
1103 | struct ev_timer t1; |
1088 | evtimer_init (&t1, ocb, 5, 10); |
1104 | ev_timer_init (&t1, ocb, 5, 10); |
1089 | evtimer_start (&t1); |
1105 | ev_timer_start (&t1); |
1090 | |
1106 | |
1091 | struct ev_signal sig; |
1107 | struct ev_signal sig; |
1092 | evsignal_init (&sig, scb, SIGQUIT); |
1108 | ev_signal_init (&sig, scb, SIGQUIT); |
1093 | evsignal_start (&sig); |
1109 | ev_signal_start (&sig); |
1094 | |
1110 | |
1095 | struct ev_check cw; |
1111 | struct ev_check cw; |
1096 | evcheck_init (&cw, gcb); |
1112 | ev_check_init (&cw, gcb); |
1097 | evcheck_start (&cw); |
1113 | ev_check_start (&cw); |
1098 | |
1114 | |
1099 | struct ev_idle iw; |
1115 | struct ev_idle iw; |
1100 | evidle_init (&iw, gcb); |
1116 | ev_idle_init (&iw, gcb); |
1101 | evidle_start (&iw); |
1117 | ev_idle_start (&iw); |
1102 | |
1118 | |
1103 | ev_loop (0); |
1119 | ev_loop (0); |
1104 | |
1120 | |
1105 | return 0; |
1121 | return 0; |
1106 | } |
1122 | } |