2 * libev event processing core, watcher management
4 * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 #include <sys/types.h>
48 # include <sys/wait.h>
55 #ifndef EV_USE_MONOTONIC
56 # define EV_USE_MONOTONIC 1
60 # define EV_USE_SELECT 1
64 # define EV_USEV_POLL 0 /* poll is usually slower than select, and not as well tested */
68 # define EV_USE_EPOLL 0
72 # define EV_USE_KQUEUE 0
75 #ifndef EV_USE_REALTIME
76 # define EV_USE_REALTIME 1
81 #ifndef CLOCK_MONOTONIC
82 # undef EV_USE_MONOTONIC
83 # define EV_USE_MONOTONIC 0
86 #ifndef CLOCK_REALTIME
87 # undef EV_USE_REALTIME
88 # define EV_USE_REALTIME 0
93 #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
94 #define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */
95 #define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */
96 /*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */
101 # define expect(expr,value) __builtin_expect ((expr),(value))
102 # define inline inline
104 # define expect(expr,value) (expr)
105 # define inline static
108 #define expect_false(expr) expect ((expr) != 0, 0)
109 #define expect_true(expr) expect ((expr) != 0, 1)
111 #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
112 #define ABSPRI(w) ((w)->priority - EV_MINPRI)
114 typedef struct ev_watcher *W;
115 typedef struct ev_watcher_list *WL;
116 typedef struct ev_watcher_time *WT;
118 /*****************************************************************************/
122 struct ev_watcher_list *head;
123 unsigned char events;
133 #ifdef EV_MULTIPLICITY
136 # define VAR(name,decl) decl
137 # include "ev_vars.h"
140 # define VAR(name,decl) static decl
141 # include "ev_vars.h"
145 /*****************************************************************************/
152 clock_gettime (CLOCK_REALTIME, &ts);
153 return ts.tv_sec + ts.tv_nsec * 1e-9;
156 gettimeofday (&tv, 0);
157 return tv.tv_sec + tv.tv_usec * 1e-6;
165 if (expect_true (have_monotonic))
168 clock_gettime (CLOCK_MONOTONIC, &ts);
169 return ts.tv_sec + ts.tv_nsec * 1e-9;
182 #define array_roundsize(base,n) ((n) | 4 & ~3)
184 #define array_needsize(base,cur,cnt,init) \
185 if (expect_false ((cnt) > cur)) \
190 newcnt = array_roundsize (base, newcnt << 1); \
192 while ((cnt) > newcnt); \
194 base = realloc (base, sizeof (*base) * (newcnt)); \
195 init (base + cur, newcnt - cur); \
199 /*****************************************************************************/
202 anfds_init (ANFD *base, int count)
207 base->events = EV_NONE;
215 event (EV_P_ W w, int events)
219 pendings [ABSPRI (w)][w->pending - 1].events |= events;
223 w->pending = ++pendingcnt [ABSPRI (w)];
224 array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], );
225 pendings [ABSPRI (w)][w->pending - 1].w = w;
226 pendings [ABSPRI (w)][w->pending - 1].events = events;
230 queue_events (EV_P_ W *events, int eventcnt, int type)
234 for (i = 0; i < eventcnt; ++i)
235 event (EV_A_ events [i], type);
239 fd_event (EV_P_ int fd, int events)
241 ANFD *anfd = anfds + fd;
244 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next)
246 int ev = w->events & events;
249 event (EV_A_ (W)w, ev);
253 /*****************************************************************************/
260 for (i = 0; i < fdchangecnt; ++i)
262 int fd = fdchanges [i];
263 ANFD *anfd = anfds + fd;
268 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next)
273 if (anfd->events != events)
275 method_modify (EV_A_ fd, anfd->events, events);
276 anfd->events = events;
284 fd_change (EV_P_ int fd)
286 if (anfds [fd].reify || fdchangecnt < 0)
289 anfds [fd].reify = 1;
292 array_needsize (fdchanges, fdchangemax, fdchangecnt, );
293 fdchanges [fdchangecnt - 1] = fd;
297 fd_kill (EV_P_ int fd)
301 while ((w = (struct ev_io *)anfds [fd].head))
303 ev_io_stop (EV_A_ w);
304 event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE);
308 /* called on EBADF to verify fds */
314 for (fd = 0; fd < anfdmax; ++fd)
315 if (anfds [fd].events)
316 if (fcntl (fd, F_GETFD) == -1 && errno == EBADF)
320 /* called on ENOMEM in select/poll to kill some fds and retry */
327 if (anfds [fd].events)
335 /*****************************************************************************/
338 upheap (WT *timers, int k)
342 while (k && timers [k >> 1]->at > w->at)
344 timers [k] = timers [k >> 1];
345 timers [k]->active = k + 1;
350 timers [k]->active = k + 1;
355 downheap (WT *timers, int N, int k)
363 if (j + 1 < N && timers [j]->at > timers [j + 1]->at)
366 if (w->at <= timers [j]->at)
369 timers [k] = timers [j];
370 timers [k]->active = k + 1;
375 timers [k]->active = k + 1;
378 /*****************************************************************************/
382 struct ev_watcher_list *head;
383 sig_atomic_t volatile gotsig;
386 static ANSIG *signals;
387 static int signalmax;
389 static int sigpipe [2];
390 static sig_atomic_t volatile gotsig;
393 signals_init (ANSIG *base, int count)
405 sighandler (int signum)
407 signals [signum - 1].gotsig = 1;
411 int old_errno = errno;
413 write (sigpipe [1], &signum, 1);
419 sigcb (EV_P_ struct ev_io *iow, int revents)
421 struct ev_watcher_list *w;
424 read (sigpipe [0], &revents, 1);
427 for (signum = signalmax; signum--; )
428 if (signals [signum].gotsig)
430 signals [signum].gotsig = 0;
432 for (w = signals [signum].head; w; w = w->next)
433 event (EV_A_ (W)w, EV_SIGNAL);
441 fcntl (sigpipe [0], F_SETFD, FD_CLOEXEC);
442 fcntl (sigpipe [1], F_SETFD, FD_CLOEXEC);
444 /* rather than sort out wether we really need nb, set it */
445 fcntl (sigpipe [0], F_SETFL, O_NONBLOCK);
446 fcntl (sigpipe [1], F_SETFL, O_NONBLOCK);
449 ev_io_set (&sigev, sigpipe [0], EV_READ);
450 ev_io_start (&sigev);
451 ev_unref (EV_A); /* child watcher should not keep loop alive */
454 /*****************************************************************************/
459 # define WCONTINUED 0
463 child_reap (EV_P_ struct ev_signal *sw, int chain, int pid, int status)
467 for (w = (struct ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (struct ev_child *)((WL)w)->next)
468 if (w->pid == pid || !w->pid)
470 w->priority = sw->priority; /* need to do it *now* */
473 event (EV_A_ (W)w, EV_CHILD);
478 childcb (EV_P_ struct ev_signal *sw, int revents)
482 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)))
484 /* make sure we are called again until all childs have been reaped */
485 event (EV_A_ (W)sw, EV_SIGNAL);
487 child_reap (EV_A_ sw, pid, pid, status);
488 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */
494 /*****************************************************************************/
497 # include "ev_kqueue.c"
500 # include "ev_epoll.c"
503 # include "ev_poll.c"
506 # include "ev_select.c"
510 ev_version_major (void)
512 return EV_VERSION_MAJOR;
516 ev_version_minor (void)
518 return EV_VERSION_MINOR;
521 /* return true if we are running with elevated privileges and should ignore env variables */
528 return getuid () != geteuid ()
529 || getgid () != getegid ();
540 ev_init (EV_P_ int methods)
542 #ifdef EV_MULTIPLICITY
543 memset (loop, 0, sizeof (struct ev_loop));
551 if (!clock_gettime (CLOCK_MONOTONIC, &ts))
557 mn_now = get_clock ();
559 diff = rt_now - mn_now;
564 if (methods == EVMETHOD_AUTO)
565 if (!enable_secure () && getenv ("LIBmethodS"))
566 methods = atoi (getenv ("LIBmethodS"));
568 methods = EVMETHOD_ANY;
572 if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods);
575 if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods);
578 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods);
581 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods);
586 ev_watcher_init (&sigev, sigcb);
587 ev_set_priority (&sigev, EV_MAXPRI);
591 ev_signal_init (&childev, childcb, SIGCHLD);
592 ev_set_priority (&childev, EV_MAXPRI);
593 ev_signal_start (EV_A_ &childev);
594 ev_unref (EV_A); /* child watcher should not keep loop alive */
602 /*****************************************************************************/
605 ev_fork_prepare (void)
611 ev_fork_parent (void)
620 if (method == EVMETHOD_EPOLL)
621 epoll_postfork_child ();
631 /*****************************************************************************/
638 for (pri = NUMPRI; pri--; )
639 while (pendingcnt [pri])
641 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
646 p->w->cb (EV_A_ p->w, p->events);
654 while (timercnt && timers [0]->at <= mn_now)
656 struct ev_timer *w = timers [0];
658 /* first reschedule or stop timer */
661 assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.));
662 w->at = mn_now + w->repeat;
663 downheap ((WT *)timers, timercnt, 0);
666 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
668 event ((W)w, EV_TIMEOUT);
673 periodics_reify (EV_P)
675 while (periodiccnt && periodics [0]->at <= rt_now)
677 struct ev_periodic *w = periodics [0];
679 /* first reschedule or stop timer */
682 w->at += floor ((rt_now - w->at) / w->interval + 1.) * w->interval;
683 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", w->at > rt_now));
684 downheap ((WT *)periodics, periodiccnt, 0);
687 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
689 event (EV_A_ (W)w, EV_PERIODIC);
694 periodics_reschedule (EV_P_ ev_tstamp diff)
698 /* adjust periodics after time jump */
699 for (i = 0; i < periodiccnt; ++i)
701 struct ev_periodic *w = periodics [i];
705 ev_tstamp diff = ceil ((rt_now - w->at) / w->interval) * w->interval;
707 if (fabs (diff) >= 1e-4)
709 ev_periodic_stop (EV_A_ w);
710 ev_periodic_start (EV_A_ w);
712 i = 0; /* restart loop, inefficient, but time jumps should be rare */
719 time_update_monotonic (EV_P)
721 mn_now = get_clock ();
723 if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5))
725 rt_now = mn_now + diff;
742 if (expect_true (have_monotonic))
744 if (time_update_monotonic (EV_A))
746 ev_tstamp odiff = diff;
748 for (i = 4; --i; ) /* loop a few times, before making important decisions */
750 diff = rt_now - mn_now;
752 if (fabs (odiff - diff) < MIN_TIMEJUMP)
753 return; /* all is well */
756 mn_now = get_clock ();
760 periodics_reschedule (EV_A_ diff - odiff);
761 /* no timer adjustment, as the monotonic clock doesn't jump */
769 if (expect_false (mn_now > rt_now || mn_now < rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP))
771 periodics_reschedule (EV_A_ rt_now - mn_now);
773 /* adjust timers. this is easy, as the offset is the same for all */
774 for (i = 0; i < timercnt; ++i)
775 timers [i]->at += diff;
794 static int loop_done;
797 ev_loop (EV_P_ int flags)
800 loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0;
804 /* queue check watchers (and execute them) */
805 if (expect_false (preparecnt))
807 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
811 /* update fd-related kernel structures */
814 /* calculate blocking time */
816 /* we only need this for !monotonic clockor timers, but as we basically
817 always have timers, we just calculate it always */
819 if (expect_true (have_monotonic))
820 time_update_monotonic (EV_A);
828 if (flags & EVLOOP_NONBLOCK || idlecnt)
832 block = MAX_BLOCKTIME;
836 ev_tstamp to = timers [0]->at - mn_now + method_fudge;
837 if (block > to) block = to;
842 ev_tstamp to = periodics [0]->at - rt_now + method_fudge;
843 if (block > to) block = to;
846 if (block < 0.) block = 0.;
849 method_poll (EV_A_ block);
851 /* update rt_now, do magic */
854 /* queue pending timers and reschedule them */
855 timers_reify (EV_A); /* relative timers called last */
856 periodics_reify (EV_A); /* absolute timers called first */
858 /* queue idle watchers unless io or timers are pending */
860 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE);
862 /* queue check watchers, to be executed first */
864 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
868 while (activecnt && !loop_done);
875 ev_unloop (EV_P_ int how)
880 /*****************************************************************************/
883 wlist_add (WL *head, WL elem)
890 wlist_del (WL *head, WL elem)
900 head = &(*head)->next;
905 ev_clear_pending (EV_P_ W w)
909 pendings [ABSPRI (w)][w->pending - 1].w = 0;
915 ev_start (EV_P_ W w, int active)
917 if (w->priority < EV_MINPRI) w->priority = EV_MINPRI;
918 if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI;
931 /*****************************************************************************/
934 ev_io_start (EV_P_ struct ev_io *w)
938 if (ev_is_active (w))
941 assert (("ev_io_start called with negative fd", fd >= 0));
943 ev_start (EV_A_ (W)w, 1);
944 array_needsize (anfds, anfdmax, fd + 1, anfds_init);
945 wlist_add ((WL *)&anfds[fd].head, (WL)w);
947 fd_change (EV_A_ fd);
951 ev_io_stop (EV_P_ struct ev_io *w)
953 ev_clear_pending (EV_A_ (W)w);
954 if (!ev_is_active (w))
957 wlist_del ((WL *)&anfds[w->fd].head, (WL)w);
958 ev_stop (EV_A_ (W)w);
960 fd_change (EV_A_ w->fd);
964 ev_timer_start (EV_P_ struct ev_timer *w)
966 if (ev_is_active (w))
971 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
973 ev_start (EV_A_ (W)w, ++timercnt);
974 array_needsize (timers, timermax, timercnt, );
975 timers [timercnt - 1] = w;
976 upheap ((WT *)timers, timercnt - 1);
980 ev_timer_stop (EV_P_ struct ev_timer *w)
982 ev_clear_pending (EV_A_ (W)w);
983 if (!ev_is_active (w))
986 if (w->active < timercnt--)
988 timers [w->active - 1] = timers [timercnt];
989 downheap ((WT *)timers, timercnt, w->active - 1);
994 ev_stop (EV_A_ (W)w);
998 ev_timer_again (EV_P_ struct ev_timer *w)
1000 if (ev_is_active (w))
1004 w->at = mn_now + w->repeat;
1005 downheap ((WT *)timers, timercnt, w->active - 1);
1008 ev_timer_stop (EV_A_ w);
1011 ev_timer_start (EV_A_ w);
1015 ev_periodic_start (EV_P_ struct ev_periodic *w)
1017 if (ev_is_active (w))
1020 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.));
1022 /* this formula differs from the one in periodic_reify because we do not always round up */
1024 w->at += ceil ((rt_now - w->at) / w->interval) * w->interval;
1026 ev_start (EV_A_ (W)w, ++periodiccnt);
1027 array_needsize (periodics, periodicmax, periodiccnt, );
1028 periodics [periodiccnt - 1] = w;
1029 upheap ((WT *)periodics, periodiccnt - 1);
1033 ev_periodic_stop (EV_P_ struct ev_periodic *w)
1035 ev_clear_pending (EV_A_ (W)w);
1036 if (!ev_is_active (w))
1039 if (w->active < periodiccnt--)
1041 periodics [w->active - 1] = periodics [periodiccnt];
1042 downheap ((WT *)periodics, periodiccnt, w->active - 1);
1045 ev_stop (EV_A_ (W)w);
1049 # define SA_RESTART 0
1053 ev_signal_start (EV_P_ struct ev_signal *w)
1055 if (ev_is_active (w))
1058 assert (("ev_signal_start called with illegal signal number", w->signum > 0));
1060 ev_start (EV_A_ (W)w, 1);
1061 array_needsize (signals, signalmax, w->signum, signals_init);
1062 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
1066 struct sigaction sa;
1067 sa.sa_handler = sighandler;
1068 sigfillset (&sa.sa_mask);
1069 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */
1070 sigaction (w->signum, &sa, 0);
1075 ev_signal_stop (EV_P_ struct ev_signal *w)
1077 ev_clear_pending (EV_A_ (W)w);
1078 if (!ev_is_active (w))
1081 wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w);
1082 ev_stop (EV_A_ (W)w);
1084 if (!signals [w->signum - 1].head)
1085 signal (w->signum, SIG_DFL);
1089 ev_idle_start (EV_P_ struct ev_idle *w)
1091 if (ev_is_active (w))
1094 ev_start (EV_A_ (W)w, ++idlecnt);
1095 array_needsize (idles, idlemax, idlecnt, );
1096 idles [idlecnt - 1] = w;
1100 ev_idle_stop (EV_P_ struct ev_idle *w)
1102 ev_clear_pending (EV_A_ (W)w);
1103 if (ev_is_active (w))
1106 idles [w->active - 1] = idles [--idlecnt];
1107 ev_stop (EV_A_ (W)w);
1111 ev_prepare_start (EV_P_ struct ev_prepare *w)
1113 if (ev_is_active (w))
1116 ev_start (EV_A_ (W)w, ++preparecnt);
1117 array_needsize (prepares, preparemax, preparecnt, );
1118 prepares [preparecnt - 1] = w;
1122 ev_prepare_stop (EV_P_ struct ev_prepare *w)
1124 ev_clear_pending (EV_A_ (W)w);
1125 if (ev_is_active (w))
1128 prepares [w->active - 1] = prepares [--preparecnt];
1129 ev_stop (EV_A_ (W)w);
1133 ev_check_start (EV_P_ struct ev_check *w)
1135 if (ev_is_active (w))
1138 ev_start (EV_A_ (W)w, ++checkcnt);
1139 array_needsize (checks, checkmax, checkcnt, );
1140 checks [checkcnt - 1] = w;
1144 ev_check_stop (EV_P_ struct ev_check *w)
1146 ev_clear_pending (EV_A_ (W)w);
1147 if (ev_is_active (w))
1150 checks [w->active - 1] = checks [--checkcnt];
1151 ev_stop (EV_A_ (W)w);
1155 ev_child_start (EV_P_ struct ev_child *w)
1157 if (ev_is_active (w))
1160 ev_start (EV_A_ (W)w, 1);
1161 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1165 ev_child_stop (EV_P_ struct ev_child *w)
1167 ev_clear_pending (EV_A_ (W)w);
1168 if (ev_is_active (w))
1171 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1172 ev_stop (EV_A_ (W)w);
1175 /*****************************************************************************/
1181 void (*cb)(int revents, void *arg);
1186 once_cb (EV_P_ struct ev_once *once, int revents)
1188 void (*cb)(int revents, void *arg) = once->cb;
1189 void *arg = once->arg;
1191 ev_io_stop (EV_A_ &once->io);
1192 ev_timer_stop (EV_A_ &once->to);
1199 once_cb_io (EV_P_ struct ev_io *w, int revents)
1201 once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)), revents);
1205 once_cb_to (EV_P_ struct ev_timer *w, int revents)
1207 once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)), revents);
1211 ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg)
1213 struct ev_once *once = malloc (sizeof (struct ev_once));
1216 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg);
1222 ev_watcher_init (&once->io, once_cb_io);
1225 ev_io_set (&once->io, fd, events);
1226 ev_io_start (EV_A_ &once->io);
1229 ev_watcher_init (&once->to, once_cb_to);
1232 ev_timer_set (&once->to, timeout, 0.);
1233 ev_timer_start (EV_A_ &once->to);
1238 /*****************************************************************************/
1245 sin_cb (struct ev_io *w, int revents)
1247 fprintf (stderr, "sin %d, revents %d\n", w->fd, revents);
1251 ocb (struct ev_timer *w, int revents)
1253 //fprintf (stderr, "timer %f,%f (%x) (%f) d%p\n", w->at, w->repeat, revents, w->at - ev_time (), w->data);
1259 scb (struct ev_signal *w, int revents)
1261 fprintf (stderr, "signal %x,%d\n", revents, w->signum);
1267 gcb (struct ev_signal *w, int revents)
1269 fprintf (stderr, "generic %x\n", revents);
1277 ev_io_init (&wio, sin_cb, 0, EV_READ);
1280 struct ev_timer t[10000];
1284 for (i = 0; i < 10000; ++i)
1286 struct ev_timer *w = t + i;
1287 ev_watcher_init (w, ocb, i);
1288 ev_timer_init_abs (w, ocb, drand48 (), 0.99775533);
1290 if (drand48 () < 0.5)
1296 ev_timer_init (&t1, ocb, 5, 10);
1297 ev_timer_start (&t1);
1299 struct ev_signal sig;
1300 ev_signal_init (&sig, scb, SIGQUIT);
1301 ev_signal_start (&sig);
1304 ev_check_init (&cw, gcb);
1305 ev_check_start (&cw);
1308 ev_idle_init (&iw, gcb);
1309 ev_idle_start (&iw);