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

Comparing libev/ev.c (file contents):
Revision 1.69 by root, Tue Nov 6 00:10:04 2007 UTC vs.
Revision 1.89 by root, Sat Nov 10 19:48:44 2007 UTC

26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
31#ifndef EV_STANDALONE 36#ifndef EV_STANDALONE
32# include "config.h" 37# include "config.h"
33 38
34# if HAVE_CLOCK_GETTIME 39# if HAVE_CLOCK_GETTIME
35# define EV_USE_MONOTONIC 1 40# define EV_USE_MONOTONIC 1
46 51
47# if HAVE_EPOLL && HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H 52# if HAVE_EPOLL && HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H
48# define EV_USE_EPOLL 1 53# define EV_USE_EPOLL 1
49# endif 54# endif
50 55
51# if HAVE_KQUEUE && HAVE_WORKING_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H 56# if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H
52# define EV_USE_KQUEUE 1 57# define EV_USE_KQUEUE 1
53# endif 58# endif
54 59
55#endif 60#endif
56 61
57#include <math.h> 62#include <math.h>
58#include <stdlib.h> 63#include <stdlib.h>
59#include <unistd.h>
60#include <fcntl.h> 64#include <fcntl.h>
61#include <signal.h>
62#include <stddef.h> 65#include <stddef.h>
63 66
64#include <stdio.h> 67#include <stdio.h>
65 68
66#include <assert.h> 69#include <assert.h>
67#include <errno.h> 70#include <errno.h>
68#include <sys/types.h> 71#include <sys/types.h>
72#include <time.h>
73
74#include <signal.h>
75
69#ifndef WIN32 76#ifndef WIN32
77# include <unistd.h>
78# include <sys/time.h>
70# include <sys/wait.h> 79# include <sys/wait.h>
71#endif 80#endif
72#include <sys/time.h>
73#include <time.h>
74
75/**/ 81/**/
76 82
77#ifndef EV_USE_MONOTONIC 83#ifndef EV_USE_MONOTONIC
78# define EV_USE_MONOTONIC 1 84# define EV_USE_MONOTONIC 1
79#endif 85#endif
94# define EV_USE_KQUEUE 0 100# define EV_USE_KQUEUE 0
95#endif 101#endif
96 102
97#ifndef EV_USE_WIN32 103#ifndef EV_USE_WIN32
98# ifdef WIN32 104# ifdef WIN32
105# define EV_USE_WIN32 0 /* it does not exist, use select */
106# undef EV_USE_SELECT
99# define EV_USE_WIN32 1 107# define EV_USE_SELECT 1
100# else 108# else
101# define EV_USE_WIN32 0 109# define EV_USE_WIN32 0
102# endif 110# endif
103#endif 111#endif
104 112
123#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 131#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
124#define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */ 132#define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */
125#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ 133#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */
126/*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */ 134/*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */
127 135
136#ifdef EV_H
137# include EV_H
138#else
128#include "ev.h" 139# include "ev.h"
140#endif
129 141
130#if __GNUC__ >= 3 142#if __GNUC__ >= 3
131# define expect(expr,value) __builtin_expect ((expr),(value)) 143# define expect(expr,value) __builtin_expect ((expr),(value))
132# define inline inline 144# define inline inline
133#else 145#else
145typedef struct ev_watcher_list *WL; 157typedef struct ev_watcher_list *WL;
146typedef struct ev_watcher_time *WT; 158typedef struct ev_watcher_time *WT;
147 159
148static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ 160static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
149 161
150#if WIN32 162#include "ev_win32.c"
151/* note: the comment below could not be substantiated, but what would I care */
152/* MSDN says this is required to handle SIGFPE */
153volatile double SIGFPE_REQ = 0.0f;
154#endif
155 163
156/*****************************************************************************/ 164/*****************************************************************************/
157 165
158static void (*syserr_cb)(void); 166static void (*syserr_cb)(const char *msg);
159 167
160void ev_set_syserr_cb (void (*cb)(void)) 168void ev_set_syserr_cb (void (*cb)(const char *msg))
161{ 169{
162 syserr_cb = cb; 170 syserr_cb = cb;
163} 171}
164 172
165static void 173static void
166syserr (void) 174syserr (const char *msg)
167{ 175{
176 if (!msg)
177 msg = "(libev) system error";
178
168 if (syserr_cb) 179 if (syserr_cb)
169 syserr_cb (); 180 syserr_cb (msg);
170 else 181 else
171 { 182 {
172 perror ("libev"); 183 perror (msg);
173 abort (); 184 abort ();
174 } 185 }
175} 186}
176 187
177static void *(*alloc)(void *ptr, long size); 188static void *(*alloc)(void *ptr, long size);
213 int events; 224 int events;
214} ANPENDING; 225} ANPENDING;
215 226
216#if EV_MULTIPLICITY 227#if EV_MULTIPLICITY
217 228
218struct ev_loop 229 struct ev_loop
219{ 230 {
231 ev_tstamp ev_rt_now;
220# define VAR(name,decl) decl; 232 #define VAR(name,decl) decl;
221# include "ev_vars.h" 233 #include "ev_vars.h"
222};
223# undef VAR 234 #undef VAR
235 };
224# include "ev_wrap.h" 236 #include "ev_wrap.h"
237
238 struct ev_loop default_loop_struct;
239 static struct ev_loop *default_loop;
225 240
226#else 241#else
227 242
243 ev_tstamp ev_rt_now;
228# define VAR(name,decl) static decl; 244 #define VAR(name,decl) static decl;
229# include "ev_vars.h" 245 #include "ev_vars.h"
230# undef VAR 246 #undef VAR
247
248 static int default_loop;
231 249
232#endif 250#endif
233 251
234/*****************************************************************************/ 252/*****************************************************************************/
235 253
260#endif 278#endif
261 279
262 return ev_time (); 280 return ev_time ();
263} 281}
264 282
283#if EV_MULTIPLICITY
265ev_tstamp 284ev_tstamp
266ev_now (EV_P) 285ev_now (EV_P)
267{ 286{
268 return rt_now; 287 return ev_rt_now;
269} 288}
289#endif
270 290
271#define array_roundsize(base,n) ((n) | 4 & ~3) 291#define array_roundsize(type,n) ((n) | 4 & ~3)
272 292
273#define array_needsize(base,cur,cnt,init) \ 293#define array_needsize(type,base,cur,cnt,init) \
274 if (expect_false ((cnt) > cur)) \ 294 if (expect_false ((cnt) > cur)) \
275 { \ 295 { \
276 int newcnt = cur; \ 296 int newcnt = cur; \
277 do \ 297 do \
278 { \ 298 { \
279 newcnt = array_roundsize (base, newcnt << 1); \ 299 newcnt = array_roundsize (type, newcnt << 1); \
280 } \ 300 } \
281 while ((cnt) > newcnt); \ 301 while ((cnt) > newcnt); \
282 \ 302 \
283 base = ev_realloc (base, sizeof (*base) * (newcnt)); \ 303 base = (type *)ev_realloc (base, sizeof (type) * (newcnt));\
284 init (base + cur, newcnt - cur); \ 304 init (base + cur, newcnt - cur); \
285 cur = newcnt; \ 305 cur = newcnt; \
286 } 306 }
287 307
288#define array_slim(stem) \ 308#define array_slim(type,stem) \
289 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ 309 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \
290 { \ 310 { \
291 stem ## max = array_roundsize (stem ## cnt >> 1); \ 311 stem ## max = array_roundsize (stem ## cnt >> 1); \
292 base = ev_realloc (base, sizeof (*base) * (stem ## max)); \ 312 base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\
293 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ 313 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\
294 } 314 }
315
316/* microsoft's pseudo-c is quite far from C as the rest of the world and the standard knows it */
317/* bringing us everlasting joy in form of stupid extra macros that are not required in C */
318#define array_free_microshit(stem) \
319 ev_free (stem ## s); stem ## cnt = stem ## max = 0;
295 320
296#define array_free(stem, idx) \ 321#define array_free(stem, idx) \
297 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; 322 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0;
298 323
299/*****************************************************************************/ 324/*****************************************************************************/
309 334
310 ++base; 335 ++base;
311 } 336 }
312} 337}
313 338
314static void 339void
315event (EV_P_ W w, int events) 340ev_feed_event (EV_P_ void *w, int revents)
316{ 341{
342 W w_ = (W)w;
343
317 if (w->pending) 344 if (w_->pending)
318 { 345 {
319 pendings [ABSPRI (w)][w->pending - 1].events |= events; 346 pendings [ABSPRI (w_)][w_->pending - 1].events |= revents;
320 return; 347 return;
321 } 348 }
322 349
323 w->pending = ++pendingcnt [ABSPRI (w)]; 350 w_->pending = ++pendingcnt [ABSPRI (w_)];
324 array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], ); 351 array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], (void));
325 pendings [ABSPRI (w)][w->pending - 1].w = w; 352 pendings [ABSPRI (w_)][w_->pending - 1].w = w_;
326 pendings [ABSPRI (w)][w->pending - 1].events = events; 353 pendings [ABSPRI (w_)][w_->pending - 1].events = revents;
327} 354}
328 355
329static void 356static void
330queue_events (EV_P_ W *events, int eventcnt, int type) 357queue_events (EV_P_ W *events, int eventcnt, int type)
331{ 358{
332 int i; 359 int i;
333 360
334 for (i = 0; i < eventcnt; ++i) 361 for (i = 0; i < eventcnt; ++i)
335 event (EV_A_ events [i], type); 362 ev_feed_event (EV_A_ events [i], type);
336} 363}
337 364
338static void 365inline void
339fd_event (EV_P_ int fd, int events) 366fd_event (EV_P_ int fd, int revents)
340{ 367{
341 ANFD *anfd = anfds + fd; 368 ANFD *anfd = anfds + fd;
342 struct ev_io *w; 369 struct ev_io *w;
343 370
344 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) 371 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next)
345 { 372 {
346 int ev = w->events & events; 373 int ev = w->events & revents;
347 374
348 if (ev) 375 if (ev)
349 event (EV_A_ (W)w, ev); 376 ev_feed_event (EV_A_ (W)w, ev);
350 } 377 }
378}
379
380void
381ev_feed_fd_event (EV_P_ int fd, int revents)
382{
383 fd_event (EV_A_ fd, revents);
351} 384}
352 385
353/*****************************************************************************/ 386/*****************************************************************************/
354 387
355static void 388static void
378} 411}
379 412
380static void 413static void
381fd_change (EV_P_ int fd) 414fd_change (EV_P_ int fd)
382{ 415{
383 if (anfds [fd].reify || fdchangecnt < 0) 416 if (anfds [fd].reify)
384 return; 417 return;
385 418
386 anfds [fd].reify = 1; 419 anfds [fd].reify = 1;
387 420
388 ++fdchangecnt; 421 ++fdchangecnt;
389 array_needsize (fdchanges, fdchangemax, fdchangecnt, ); 422 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, (void));
390 fdchanges [fdchangecnt - 1] = fd; 423 fdchanges [fdchangecnt - 1] = fd;
391} 424}
392 425
393static void 426static void
394fd_kill (EV_P_ int fd) 427fd_kill (EV_P_ int fd)
396 struct ev_io *w; 429 struct ev_io *w;
397 430
398 while ((w = (struct ev_io *)anfds [fd].head)) 431 while ((w = (struct ev_io *)anfds [fd].head))
399 { 432 {
400 ev_io_stop (EV_A_ w); 433 ev_io_stop (EV_A_ w);
401 event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); 434 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE);
402 } 435 }
436}
437
438static int
439fd_valid (int fd)
440{
441#ifdef WIN32
442 return !!win32_get_osfhandle (fd);
443#else
444 return fcntl (fd, F_GETFD) != -1;
445#endif
403} 446}
404 447
405/* called on EBADF to verify fds */ 448/* called on EBADF to verify fds */
406static void 449static void
407fd_ebadf (EV_P) 450fd_ebadf (EV_P)
408{ 451{
409 int fd; 452 int fd;
410 453
411 for (fd = 0; fd < anfdmax; ++fd) 454 for (fd = 0; fd < anfdmax; ++fd)
412 if (anfds [fd].events) 455 if (anfds [fd].events)
413 if (fcntl (fd, F_GETFD) == -1 && errno == EBADF) 456 if (!fd_valid (fd) == -1 && errno == EBADF)
414 fd_kill (EV_A_ fd); 457 fd_kill (EV_A_ fd);
415} 458}
416 459
417/* called on ENOMEM in select/poll to kill some fds and retry */ 460/* called on ENOMEM in select/poll to kill some fds and retry */
418static void 461static void
426 fd_kill (EV_A_ fd); 469 fd_kill (EV_A_ fd);
427 return; 470 return;
428 } 471 }
429} 472}
430 473
431/* susually called after fork if method needs to re-arm all fds from scratch */ 474/* usually called after fork if method needs to re-arm all fds from scratch */
432static void 475static void
433fd_rearm_all (EV_P) 476fd_rearm_all (EV_P)
434{ 477{
435 int fd; 478 int fd;
436 479
484 527
485 heap [k] = w; 528 heap [k] = w;
486 ((W)heap [k])->active = k + 1; 529 ((W)heap [k])->active = k + 1;
487} 530}
488 531
532inline void
533adjustheap (WT *heap, int N, int k, ev_tstamp at)
534{
535 ev_tstamp old_at = heap [k]->at;
536 heap [k]->at = at;
537
538 if (old_at < at)
539 downheap (heap, N, k);
540 else
541 upheap (heap, k);
542}
543
489/*****************************************************************************/ 544/*****************************************************************************/
490 545
491typedef struct 546typedef struct
492{ 547{
493 WL head; 548 WL head;
524 579
525 if (!gotsig) 580 if (!gotsig)
526 { 581 {
527 int old_errno = errno; 582 int old_errno = errno;
528 gotsig = 1; 583 gotsig = 1;
584#ifdef WIN32
585 send (sigpipe [1], &signum, 1, MSG_DONTWAIT);
586#else
529 write (sigpipe [1], &signum, 1); 587 write (sigpipe [1], &signum, 1);
588#endif
530 errno = old_errno; 589 errno = old_errno;
531 } 590 }
532} 591}
533 592
593void
594ev_feed_signal_event (EV_P_ int signum)
595{
596 WL w;
597
598#if EV_MULTIPLICITY
599 assert (("feeding signal events is only supported in the default loop", loop == default_loop));
600#endif
601
602 --signum;
603
604 if (signum < 0 || signum >= signalmax)
605 return;
606
607 signals [signum].gotsig = 0;
608
609 for (w = signals [signum].head; w; w = w->next)
610 ev_feed_event (EV_A_ (W)w, EV_SIGNAL);
611}
612
534static void 613static void
535sigcb (EV_P_ struct ev_io *iow, int revents) 614sigcb (EV_P_ struct ev_io *iow, int revents)
536{ 615{
537 WL w;
538 int signum; 616 int signum;
539 617
618#ifdef WIN32
619 recv (sigpipe [0], &revents, 1, MSG_DONTWAIT);
620#else
540 read (sigpipe [0], &revents, 1); 621 read (sigpipe [0], &revents, 1);
622#endif
541 gotsig = 0; 623 gotsig = 0;
542 624
543 for (signum = signalmax; signum--; ) 625 for (signum = signalmax; signum--; )
544 if (signals [signum].gotsig) 626 if (signals [signum].gotsig)
545 { 627 ev_feed_signal_event (EV_A_ signum + 1);
546 signals [signum].gotsig = 0;
547
548 for (w = signals [signum].head; w; w = w->next)
549 event (EV_A_ (W)w, EV_SIGNAL);
550 }
551} 628}
552 629
553static void 630static void
554siginit (EV_P) 631siginit (EV_P)
555{ 632{
567 ev_unref (EV_A); /* child watcher should not keep loop alive */ 644 ev_unref (EV_A); /* child watcher should not keep loop alive */
568} 645}
569 646
570/*****************************************************************************/ 647/*****************************************************************************/
571 648
649static struct ev_child *childs [PID_HASHSIZE];
650
572#ifndef WIN32 651#ifndef WIN32
573 652
574static struct ev_child *childs [PID_HASHSIZE];
575static struct ev_signal childev; 653static struct ev_signal childev;
576 654
577#ifndef WCONTINUED 655#ifndef WCONTINUED
578# define WCONTINUED 0 656# define WCONTINUED 0
579#endif 657#endif
587 if (w->pid == pid || !w->pid) 665 if (w->pid == pid || !w->pid)
588 { 666 {
589 ev_priority (w) = ev_priority (sw); /* need to do it *now* */ 667 ev_priority (w) = ev_priority (sw); /* need to do it *now* */
590 w->rpid = pid; 668 w->rpid = pid;
591 w->rstatus = status; 669 w->rstatus = status;
592 event (EV_A_ (W)w, EV_CHILD); 670 ev_feed_event (EV_A_ (W)w, EV_CHILD);
593 } 671 }
594} 672}
595 673
596static void 674static void
597childcb (EV_P_ struct ev_signal *sw, int revents) 675childcb (EV_P_ struct ev_signal *sw, int revents)
599 int pid, status; 677 int pid, status;
600 678
601 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) 679 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)))
602 { 680 {
603 /* make sure we are called again until all childs have been reaped */ 681 /* make sure we are called again until all childs have been reaped */
604 event (EV_A_ (W)sw, EV_SIGNAL); 682 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL);
605 683
606 child_reap (EV_A_ sw, pid, pid, status); 684 child_reap (EV_A_ sw, pid, pid, status);
607 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */ 685 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */
608 } 686 }
609} 687}
666 if (!clock_gettime (CLOCK_MONOTONIC, &ts)) 744 if (!clock_gettime (CLOCK_MONOTONIC, &ts))
667 have_monotonic = 1; 745 have_monotonic = 1;
668 } 746 }
669#endif 747#endif
670 748
671 rt_now = ev_time (); 749 ev_rt_now = ev_time ();
672 mn_now = get_clock (); 750 mn_now = get_clock ();
673 now_floor = mn_now; 751 now_floor = mn_now;
674 rtmn_diff = rt_now - mn_now; 752 rtmn_diff = ev_rt_now - mn_now;
675 753
676 if (methods == EVMETHOD_AUTO) 754 if (methods == EVMETHOD_AUTO)
677 if (!enable_secure () && getenv ("LIBEV_METHODS")) 755 if (!enable_secure () && getenv ("LIBEV_METHODS"))
678 methods = atoi (getenv ("LIBEV_METHODS")); 756 methods = atoi (getenv ("LIBEV_METHODS"));
679 else 757 else
693 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); 771 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods);
694#endif 772#endif
695#if EV_USE_SELECT 773#if EV_USE_SELECT
696 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); 774 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods);
697#endif 775#endif
776
777 ev_init (&sigev, sigcb);
778 ev_set_priority (&sigev, EV_MAXPRI);
698 } 779 }
699} 780}
700 781
701void 782void
702loop_destroy (EV_P) 783loop_destroy (EV_P)
720#endif 801#endif
721 802
722 for (i = NUMPRI; i--; ) 803 for (i = NUMPRI; i--; )
723 array_free (pending, [i]); 804 array_free (pending, [i]);
724 805
806 /* have to use the microsoft-never-gets-it-right macro */
725 array_free (fdchange, ); 807 array_free_microshit (fdchange);
726 array_free (timer, ); 808 array_free_microshit (timer);
727 array_free (periodic, ); 809 array_free_microshit (periodic);
728 array_free (idle, ); 810 array_free_microshit (idle);
729 array_free (prepare, ); 811 array_free_microshit (prepare);
730 array_free (check, ); 812 array_free_microshit (check);
731 813
732 method = 0; 814 method = 0;
733 /*TODO*/
734} 815}
735 816
736void 817static void
737loop_fork (EV_P) 818loop_fork (EV_P)
738{ 819{
739 /*TODO*/
740#if EV_USE_EPOLL 820#if EV_USE_EPOLL
741 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); 821 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A);
742#endif 822#endif
743#if EV_USE_KQUEUE 823#if EV_USE_KQUEUE
744 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); 824 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A);
745#endif 825#endif
826
827 if (ev_is_active (&sigev))
828 {
829 /* default loop */
830
831 ev_ref (EV_A);
832 ev_io_stop (EV_A_ &sigev);
833 close (sigpipe [0]);
834 close (sigpipe [1]);
835
836 while (pipe (sigpipe))
837 syserr ("(libev) error creating pipe");
838
839 siginit (EV_A);
840 }
841
842 postfork = 0;
746} 843}
747 844
748#if EV_MULTIPLICITY 845#if EV_MULTIPLICITY
749struct ev_loop * 846struct ev_loop *
750ev_loop_new (int methods) 847ev_loop_new (int methods)
769} 866}
770 867
771void 868void
772ev_loop_fork (EV_P) 869ev_loop_fork (EV_P)
773{ 870{
774 loop_fork (EV_A); 871 postfork = 1;
775} 872}
776 873
777#endif 874#endif
778 875
779#if EV_MULTIPLICITY 876#if EV_MULTIPLICITY
780struct ev_loop default_loop_struct;
781static struct ev_loop *default_loop;
782
783struct ev_loop * 877struct ev_loop *
784#else 878#else
785static int default_loop;
786
787int 879int
788#endif 880#endif
789ev_default_loop (int methods) 881ev_default_loop (int methods)
790{ 882{
791 if (sigpipe [0] == sigpipe [1]) 883 if (sigpipe [0] == sigpipe [1])
802 894
803 loop_init (EV_A_ methods); 895 loop_init (EV_A_ methods);
804 896
805 if (ev_method (EV_A)) 897 if (ev_method (EV_A))
806 { 898 {
807 ev_watcher_init (&sigev, sigcb);
808 ev_set_priority (&sigev, EV_MAXPRI);
809 siginit (EV_A); 899 siginit (EV_A);
810 900
811#ifndef WIN32 901#ifndef WIN32
812 ev_signal_init (&childev, childcb, SIGCHLD); 902 ev_signal_init (&childev, childcb, SIGCHLD);
813 ev_set_priority (&childev, EV_MAXPRI); 903 ev_set_priority (&childev, EV_MAXPRI);
827{ 917{
828#if EV_MULTIPLICITY 918#if EV_MULTIPLICITY
829 struct ev_loop *loop = default_loop; 919 struct ev_loop *loop = default_loop;
830#endif 920#endif
831 921
922#ifndef WIN32
832 ev_ref (EV_A); /* child watcher */ 923 ev_ref (EV_A); /* child watcher */
833 ev_signal_stop (EV_A_ &childev); 924 ev_signal_stop (EV_A_ &childev);
925#endif
834 926
835 ev_ref (EV_A); /* signal watcher */ 927 ev_ref (EV_A); /* signal watcher */
836 ev_io_stop (EV_A_ &sigev); 928 ev_io_stop (EV_A_ &sigev);
837 929
838 close (sigpipe [0]); sigpipe [0] = 0; 930 close (sigpipe [0]); sigpipe [0] = 0;
846{ 938{
847#if EV_MULTIPLICITY 939#if EV_MULTIPLICITY
848 struct ev_loop *loop = default_loop; 940 struct ev_loop *loop = default_loop;
849#endif 941#endif
850 942
851 loop_fork (EV_A); 943 if (method)
852 944 postfork = 1;
853 ev_io_stop (EV_A_ &sigev);
854 close (sigpipe [0]);
855 close (sigpipe [1]);
856 pipe (sigpipe);
857
858 ev_ref (EV_A); /* signal watcher */
859 siginit (EV_A);
860} 945}
861 946
862/*****************************************************************************/ 947/*****************************************************************************/
948
949static int
950any_pending (EV_P)
951{
952 int pri;
953
954 for (pri = NUMPRI; pri--; )
955 if (pendingcnt [pri])
956 return 1;
957
958 return 0;
959}
863 960
864static void 961static void
865call_pending (EV_P) 962call_pending (EV_P)
866{ 963{
867 int pri; 964 int pri;
872 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 969 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
873 970
874 if (p->w) 971 if (p->w)
875 { 972 {
876 p->w->pending = 0; 973 p->w->pending = 0;
877 p->w->cb (EV_A_ p->w, p->events); 974 EV_CB_INVOKE (p->w, p->events);
878 } 975 }
879 } 976 }
880} 977}
881 978
882static void 979static void
896 downheap ((WT *)timers, timercnt, 0); 993 downheap ((WT *)timers, timercnt, 0);
897 } 994 }
898 else 995 else
899 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ 996 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
900 997
901 event (EV_A_ (W)w, EV_TIMEOUT); 998 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT);
902 } 999 }
903} 1000}
904 1001
905static void 1002static void
906periodics_reify (EV_P) 1003periodics_reify (EV_P)
907{ 1004{
908 while (periodiccnt && ((WT)periodics [0])->at <= rt_now) 1005 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now)
909 { 1006 {
910 struct ev_periodic *w = periodics [0]; 1007 struct ev_periodic *w = periodics [0];
911 1008
912 assert (("inactive timer on periodic heap detected", ev_is_active (w))); 1009 assert (("inactive timer on periodic heap detected", ev_is_active (w)));
913 1010
914 /* first reschedule or stop timer */ 1011 /* first reschedule or stop timer */
915 if (w->interval) 1012 if (w->reschedule_cb)
916 { 1013 {
1014 ev_tstamp at = ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + 0.0001);
1015
1016 assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now));
1017 downheap ((WT *)periodics, periodiccnt, 0);
1018 }
1019 else if (w->interval)
1020 {
917 ((WT)w)->at += floor ((rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval; 1021 ((WT)w)->at += floor ((ev_rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval;
918 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now)); 1022 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now));
919 downheap ((WT *)periodics, periodiccnt, 0); 1023 downheap ((WT *)periodics, periodiccnt, 0);
920 } 1024 }
921 else 1025 else
922 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ 1026 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
923 1027
924 event (EV_A_ (W)w, EV_PERIODIC); 1028 ev_feed_event (EV_A_ (W)w, EV_PERIODIC);
925 } 1029 }
926} 1030}
927 1031
928static void 1032static void
929periodics_reschedule (EV_P) 1033periodics_reschedule (EV_P)
933 /* adjust periodics after time jump */ 1037 /* adjust periodics after time jump */
934 for (i = 0; i < periodiccnt; ++i) 1038 for (i = 0; i < periodiccnt; ++i)
935 { 1039 {
936 struct ev_periodic *w = periodics [i]; 1040 struct ev_periodic *w = periodics [i];
937 1041
1042 if (w->reschedule_cb)
1043 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now);
938 if (w->interval) 1044 else if (w->interval)
939 {
940 ev_tstamp diff = ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; 1045 ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval;
941
942 if (fabs (diff) >= 1e-4)
943 {
944 ev_periodic_stop (EV_A_ w);
945 ev_periodic_start (EV_A_ w);
946
947 i = 0; /* restart loop, inefficient, but time jumps should be rare */
948 }
949 }
950 } 1046 }
1047
1048 /* now rebuild the heap */
1049 for (i = periodiccnt >> 1; i--; )
1050 downheap ((WT *)periodics, periodiccnt, i);
951} 1051}
952 1052
953inline int 1053inline int
954time_update_monotonic (EV_P) 1054time_update_monotonic (EV_P)
955{ 1055{
956 mn_now = get_clock (); 1056 mn_now = get_clock ();
957 1057
958 if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5)) 1058 if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5))
959 { 1059 {
960 rt_now = rtmn_diff + mn_now; 1060 ev_rt_now = rtmn_diff + mn_now;
961 return 0; 1061 return 0;
962 } 1062 }
963 else 1063 else
964 { 1064 {
965 now_floor = mn_now; 1065 now_floor = mn_now;
966 rt_now = ev_time (); 1066 ev_rt_now = ev_time ();
967 return 1; 1067 return 1;
968 } 1068 }
969} 1069}
970 1070
971static void 1071static void
980 { 1080 {
981 ev_tstamp odiff = rtmn_diff; 1081 ev_tstamp odiff = rtmn_diff;
982 1082
983 for (i = 4; --i; ) /* loop a few times, before making important decisions */ 1083 for (i = 4; --i; ) /* loop a few times, before making important decisions */
984 { 1084 {
985 rtmn_diff = rt_now - mn_now; 1085 rtmn_diff = ev_rt_now - mn_now;
986 1086
987 if (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP) 1087 if (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP)
988 return; /* all is well */ 1088 return; /* all is well */
989 1089
990 rt_now = ev_time (); 1090 ev_rt_now = ev_time ();
991 mn_now = get_clock (); 1091 mn_now = get_clock ();
992 now_floor = mn_now; 1092 now_floor = mn_now;
993 } 1093 }
994 1094
995 periodics_reschedule (EV_A); 1095 periodics_reschedule (EV_A);
998 } 1098 }
999 } 1099 }
1000 else 1100 else
1001#endif 1101#endif
1002 { 1102 {
1003 rt_now = ev_time (); 1103 ev_rt_now = ev_time ();
1004 1104
1005 if (expect_false (mn_now > rt_now || mn_now < rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP)) 1105 if (expect_false (mn_now > ev_rt_now || mn_now < ev_rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP))
1006 { 1106 {
1007 periodics_reschedule (EV_A); 1107 periodics_reschedule (EV_A);
1008 1108
1009 /* adjust timers. this is easy, as the offset is the same for all */ 1109 /* adjust timers. this is easy, as the offset is the same for all */
1010 for (i = 0; i < timercnt; ++i) 1110 for (i = 0; i < timercnt; ++i)
1011 ((WT)timers [i])->at += rt_now - mn_now; 1111 ((WT)timers [i])->at += ev_rt_now - mn_now;
1012 } 1112 }
1013 1113
1014 mn_now = rt_now; 1114 mn_now = ev_rt_now;
1015 } 1115 }
1016} 1116}
1017 1117
1018void 1118void
1019ev_ref (EV_P) 1119ev_ref (EV_P)
1042 { 1142 {
1043 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 1143 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
1044 call_pending (EV_A); 1144 call_pending (EV_A);
1045 } 1145 }
1046 1146
1147 /* we might have forked, so reify kernel state if necessary */
1148 if (expect_false (postfork))
1149 loop_fork (EV_A);
1150
1047 /* update fd-related kernel structures */ 1151 /* update fd-related kernel structures */
1048 fd_reify (EV_A); 1152 fd_reify (EV_A);
1049 1153
1050 /* calculate blocking time */ 1154 /* calculate blocking time */
1051 1155
1052 /* we only need this for !monotonic clockor timers, but as we basically 1156 /* we only need this for !monotonic clock or timers, but as we basically
1053 always have timers, we just calculate it always */ 1157 always have timers, we just calculate it always */
1054#if EV_USE_MONOTONIC 1158#if EV_USE_MONOTONIC
1055 if (expect_true (have_monotonic)) 1159 if (expect_true (have_monotonic))
1056 time_update_monotonic (EV_A); 1160 time_update_monotonic (EV_A);
1057 else 1161 else
1058#endif 1162#endif
1059 { 1163 {
1060 rt_now = ev_time (); 1164 ev_rt_now = ev_time ();
1061 mn_now = rt_now; 1165 mn_now = ev_rt_now;
1062 } 1166 }
1063 1167
1064 if (flags & EVLOOP_NONBLOCK || idlecnt) 1168 if (flags & EVLOOP_NONBLOCK || idlecnt)
1065 block = 0.; 1169 block = 0.;
1066 else 1170 else
1073 if (block > to) block = to; 1177 if (block > to) block = to;
1074 } 1178 }
1075 1179
1076 if (periodiccnt) 1180 if (periodiccnt)
1077 { 1181 {
1078 ev_tstamp to = ((WT)periodics [0])->at - rt_now + method_fudge; 1182 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + method_fudge;
1079 if (block > to) block = to; 1183 if (block > to) block = to;
1080 } 1184 }
1081 1185
1082 if (block < 0.) block = 0.; 1186 if (block < 0.) block = 0.;
1083 } 1187 }
1084 1188
1085 method_poll (EV_A_ block); 1189 method_poll (EV_A_ block);
1086 1190
1087 /* update rt_now, do magic */ 1191 /* update ev_rt_now, do magic */
1088 time_update (EV_A); 1192 time_update (EV_A);
1089 1193
1090 /* queue pending timers and reschedule them */ 1194 /* queue pending timers and reschedule them */
1091 timers_reify (EV_A); /* relative timers called last */ 1195 timers_reify (EV_A); /* relative timers called last */
1092 periodics_reify (EV_A); /* absolute timers called first */ 1196 periodics_reify (EV_A); /* absolute timers called first */
1093 1197
1094 /* queue idle watchers unless io or timers are pending */ 1198 /* queue idle watchers unless io or timers are pending */
1095 if (!pendingcnt) 1199 if (idlecnt && !any_pending (EV_A))
1096 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); 1200 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE);
1097 1201
1098 /* queue check watchers, to be executed first */ 1202 /* queue check watchers, to be executed first */
1099 if (checkcnt) 1203 if (checkcnt)
1100 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); 1204 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
1175 return; 1279 return;
1176 1280
1177 assert (("ev_io_start called with negative fd", fd >= 0)); 1281 assert (("ev_io_start called with negative fd", fd >= 0));
1178 1282
1179 ev_start (EV_A_ (W)w, 1); 1283 ev_start (EV_A_ (W)w, 1);
1180 array_needsize (anfds, anfdmax, fd + 1, anfds_init); 1284 array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init);
1181 wlist_add ((WL *)&anfds[fd].head, (WL)w); 1285 wlist_add ((WL *)&anfds[fd].head, (WL)w);
1182 1286
1183 fd_change (EV_A_ fd); 1287 fd_change (EV_A_ fd);
1184} 1288}
1185 1289
1188{ 1292{
1189 ev_clear_pending (EV_A_ (W)w); 1293 ev_clear_pending (EV_A_ (W)w);
1190 if (!ev_is_active (w)) 1294 if (!ev_is_active (w))
1191 return; 1295 return;
1192 1296
1297 assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax));
1298
1193 wlist_del ((WL *)&anfds[w->fd].head, (WL)w); 1299 wlist_del ((WL *)&anfds[w->fd].head, (WL)w);
1194 ev_stop (EV_A_ (W)w); 1300 ev_stop (EV_A_ (W)w);
1195 1301
1196 fd_change (EV_A_ w->fd); 1302 fd_change (EV_A_ w->fd);
1197} 1303}
1205 ((WT)w)->at += mn_now; 1311 ((WT)w)->at += mn_now;
1206 1312
1207 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 1313 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
1208 1314
1209 ev_start (EV_A_ (W)w, ++timercnt); 1315 ev_start (EV_A_ (W)w, ++timercnt);
1210 array_needsize (timers, timermax, timercnt, ); 1316 array_needsize (struct ev_timer *, timers, timermax, timercnt, (void));
1211 timers [timercnt - 1] = w; 1317 timers [timercnt - 1] = w;
1212 upheap ((WT *)timers, timercnt - 1); 1318 upheap ((WT *)timers, timercnt - 1);
1213 1319
1214 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1320 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1215} 1321}
1238ev_timer_again (EV_P_ struct ev_timer *w) 1344ev_timer_again (EV_P_ struct ev_timer *w)
1239{ 1345{
1240 if (ev_is_active (w)) 1346 if (ev_is_active (w))
1241 { 1347 {
1242 if (w->repeat) 1348 if (w->repeat)
1243 {
1244 ((WT)w)->at = mn_now + w->repeat;
1245 downheap ((WT *)timers, timercnt, ((W)w)->active - 1); 1349 adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1, mn_now + w->repeat);
1246 }
1247 else 1350 else
1248 ev_timer_stop (EV_A_ w); 1351 ev_timer_stop (EV_A_ w);
1249 } 1352 }
1250 else if (w->repeat) 1353 else if (w->repeat)
1251 ev_timer_start (EV_A_ w); 1354 ev_timer_start (EV_A_ w);
1255ev_periodic_start (EV_P_ struct ev_periodic *w) 1358ev_periodic_start (EV_P_ struct ev_periodic *w)
1256{ 1359{
1257 if (ev_is_active (w)) 1360 if (ev_is_active (w))
1258 return; 1361 return;
1259 1362
1363 if (w->reschedule_cb)
1364 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now);
1365 else if (w->interval)
1366 {
1260 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); 1367 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.));
1261
1262 /* this formula differs from the one in periodic_reify because we do not always round up */ 1368 /* this formula differs from the one in periodic_reify because we do not always round up */
1263 if (w->interval)
1264 ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; 1369 ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval;
1370 }
1265 1371
1266 ev_start (EV_A_ (W)w, ++periodiccnt); 1372 ev_start (EV_A_ (W)w, ++periodiccnt);
1267 array_needsize (periodics, periodicmax, periodiccnt, ); 1373 array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, (void));
1268 periodics [periodiccnt - 1] = w; 1374 periodics [periodiccnt - 1] = w;
1269 upheap ((WT *)periodics, periodiccnt - 1); 1375 upheap ((WT *)periodics, periodiccnt - 1);
1270 1376
1271 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1377 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1272} 1378}
1288 1394
1289 ev_stop (EV_A_ (W)w); 1395 ev_stop (EV_A_ (W)w);
1290} 1396}
1291 1397
1292void 1398void
1399ev_periodic_again (EV_P_ struct ev_periodic *w)
1400{
1401 /* TODO: use adjustheap and recalculation */
1402 ev_periodic_stop (EV_A_ w);
1403 ev_periodic_start (EV_A_ w);
1404}
1405
1406void
1293ev_idle_start (EV_P_ struct ev_idle *w) 1407ev_idle_start (EV_P_ struct ev_idle *w)
1294{ 1408{
1295 if (ev_is_active (w)) 1409 if (ev_is_active (w))
1296 return; 1410 return;
1297 1411
1298 ev_start (EV_A_ (W)w, ++idlecnt); 1412 ev_start (EV_A_ (W)w, ++idlecnt);
1299 array_needsize (idles, idlemax, idlecnt, ); 1413 array_needsize (struct ev_idle *, idles, idlemax, idlecnt, (void));
1300 idles [idlecnt - 1] = w; 1414 idles [idlecnt - 1] = w;
1301} 1415}
1302 1416
1303void 1417void
1304ev_idle_stop (EV_P_ struct ev_idle *w) 1418ev_idle_stop (EV_P_ struct ev_idle *w)
1316{ 1430{
1317 if (ev_is_active (w)) 1431 if (ev_is_active (w))
1318 return; 1432 return;
1319 1433
1320 ev_start (EV_A_ (W)w, ++preparecnt); 1434 ev_start (EV_A_ (W)w, ++preparecnt);
1321 array_needsize (prepares, preparemax, preparecnt, ); 1435 array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, (void));
1322 prepares [preparecnt - 1] = w; 1436 prepares [preparecnt - 1] = w;
1323} 1437}
1324 1438
1325void 1439void
1326ev_prepare_stop (EV_P_ struct ev_prepare *w) 1440ev_prepare_stop (EV_P_ struct ev_prepare *w)
1338{ 1452{
1339 if (ev_is_active (w)) 1453 if (ev_is_active (w))
1340 return; 1454 return;
1341 1455
1342 ev_start (EV_A_ (W)w, ++checkcnt); 1456 ev_start (EV_A_ (W)w, ++checkcnt);
1343 array_needsize (checks, checkmax, checkcnt, ); 1457 array_needsize (struct ev_check *, checks, checkmax, checkcnt, (void));
1344 checks [checkcnt - 1] = w; 1458 checks [checkcnt - 1] = w;
1345} 1459}
1346 1460
1347void 1461void
1348ev_check_stop (EV_P_ struct ev_check *w) 1462ev_check_stop (EV_P_ struct ev_check *w)
1369 return; 1483 return;
1370 1484
1371 assert (("ev_signal_start called with illegal signal number", w->signum > 0)); 1485 assert (("ev_signal_start called with illegal signal number", w->signum > 0));
1372 1486
1373 ev_start (EV_A_ (W)w, 1); 1487 ev_start (EV_A_ (W)w, 1);
1374 array_needsize (signals, signalmax, w->signum, signals_init); 1488 array_needsize (ANSIG, signals, signalmax, w->signum, signals_init);
1375 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); 1489 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
1376 1490
1377 if (!((WL)w)->next) 1491 if (!((WL)w)->next)
1378 { 1492 {
1379#if WIN32 1493#if WIN32
1462} 1576}
1463 1577
1464void 1578void
1465ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) 1579ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg)
1466{ 1580{
1467 struct ev_once *once = ev_malloc (sizeof (struct ev_once)); 1581 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
1468 1582
1469 if (!once) 1583 if (!once)
1470 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); 1584 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg);
1471 else 1585 else
1472 { 1586 {
1473 once->cb = cb; 1587 once->cb = cb;
1474 once->arg = arg; 1588 once->arg = arg;
1475 1589
1476 ev_watcher_init (&once->io, once_cb_io); 1590 ev_init (&once->io, once_cb_io);
1477 if (fd >= 0) 1591 if (fd >= 0)
1478 { 1592 {
1479 ev_io_set (&once->io, fd, events); 1593 ev_io_set (&once->io, fd, events);
1480 ev_io_start (EV_A_ &once->io); 1594 ev_io_start (EV_A_ &once->io);
1481 } 1595 }
1482 1596
1483 ev_watcher_init (&once->to, once_cb_to); 1597 ev_init (&once->to, once_cb_to);
1484 if (timeout >= 0.) 1598 if (timeout >= 0.)
1485 { 1599 {
1486 ev_timer_set (&once->to, timeout, 0.); 1600 ev_timer_set (&once->to, timeout, 0.);
1487 ev_timer_start (EV_A_ &once->to); 1601 ev_timer_start (EV_A_ &once->to);
1488 } 1602 }
1489 } 1603 }
1490} 1604}
1491 1605
1606#ifdef __cplusplus
1607}
1608#endif
1609

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines