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

Comparing libev/ev.c (file contents):
Revision 1.11 by root, Wed Oct 31 07:40:49 2007 UTC vs.
Revision 1.17 by root, Wed Oct 31 14:44:15 2007 UTC

1/*
2 * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials provided
15 * with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
1#include <math.h> 30#include <math.h>
2#include <stdlib.h> 31#include <stdlib.h>
3#include <unistd.h> 32#include <unistd.h>
4#include <fcntl.h> 33#include <fcntl.h>
5#include <signal.h> 34#include <signal.h>
35#include <stddef.h>
6 36
7#include <stdio.h> 37#include <stdio.h>
8 38
9#include <assert.h> 39#include <assert.h>
10#include <errno.h> 40#include <errno.h>
11#include <sys/time.h> 41#include <sys/time.h>
12#include <time.h> 42#include <time.h>
13 43
44#define HAVE_EPOLL 1
45
14#ifndef HAVE_MONOTONIC 46#ifndef HAVE_MONOTONIC
15# ifdef CLOCK_MONOTONIC 47# ifdef CLOCK_MONOTONIC
16# define HAVE_MONOTONIC 1 48# define HAVE_MONOTONIC 1
17# endif 49# endif
18#endif 50#endif
32#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 64#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
33#define MAX_BLOCKTIME 60. 65#define MAX_BLOCKTIME 60.
34 66
35#include "ev.h" 67#include "ev.h"
36 68
37struct ev_watcher {
38 EV_WATCHER (ev_watcher);
39};
40
41struct ev_watcher_list {
42 EV_WATCHER_LIST (ev_watcher_list);
43};
44
45typedef struct ev_watcher *W; 69typedef struct ev_watcher *W;
46typedef struct ev_watcher_list *WL; 70typedef struct ev_watcher_list *WL;
71typedef struct ev_watcher_time *WT;
47 72
48static ev_tstamp now, diff; /* monotonic clock */ 73static ev_tstamp now, diff; /* monotonic clock */
49ev_tstamp ev_now; 74ev_tstamp ev_now;
50int ev_method; 75int ev_method;
51 76
88 113
89#define array_needsize(base,cur,cnt,init) \ 114#define array_needsize(base,cur,cnt,init) \
90 if ((cnt) > cur) \ 115 if ((cnt) > cur) \
91 { \ 116 { \
92 int newcnt = cur ? cur << 1 : 16; \ 117 int newcnt = cur ? cur << 1 : 16; \
93 fprintf (stderr, "resize(" # base ") from %d to %d\n", cur, newcnt);\
94 base = realloc (base, sizeof (*base) * (newcnt)); \ 118 base = realloc (base, sizeof (*base) * (newcnt)); \
95 init (base + cur, newcnt - cur); \ 119 init (base + cur, newcnt - cur); \
96 cur = newcnt; \ 120 cur = newcnt; \
97 } 121 }
98 122
131static int pendingmax, pendingcnt; 155static int pendingmax, pendingcnt;
132 156
133static void 157static void
134event (W w, int events) 158event (W w, int events)
135{ 159{
160 if (w->active)
161 {
136 w->pending = ++pendingcnt; 162 w->pending = ++pendingcnt;
137 array_needsize (pendings, pendingmax, pendingcnt, ); 163 array_needsize (pendings, pendingmax, pendingcnt, );
138 pendings [pendingcnt - 1].w = w; 164 pendings [pendingcnt - 1].w = w;
139 pendings [pendingcnt - 1].events = events; 165 pendings [pendingcnt - 1].events = events;
166 }
140} 167}
141 168
142static void 169static void
143fd_event (int fd, int events) 170fd_event (int fd, int events)
144{ 171{
163 event (events [i], type); 190 event (events [i], type);
164} 191}
165 192
166/*****************************************************************************/ 193/*****************************************************************************/
167 194
168static struct ev_timer **atimers; 195static struct ev_timer **timers;
169static int atimermax, atimercnt; 196static int timermax, timercnt;
170 197
171static struct ev_timer **rtimers; 198static struct ev_periodic **periodics;
172static int rtimermax, rtimercnt; 199static int periodicmax, periodiccnt;
173 200
174static void 201static void
175upheap (struct ev_timer **timers, int k) 202upheap (WT *timers, int k)
176{ 203{
177 struct ev_timer *w = timers [k]; 204 WT w = timers [k];
178 205
179 while (k && timers [k >> 1]->at > w->at) 206 while (k && timers [k >> 1]->at > w->at)
180 { 207 {
181 timers [k] = timers [k >> 1]; 208 timers [k] = timers [k >> 1];
182 timers [k]->active = k + 1; 209 timers [k]->active = k + 1;
187 timers [k]->active = k + 1; 214 timers [k]->active = k + 1;
188 215
189} 216}
190 217
191static void 218static void
192downheap (struct ev_timer **timers, int N, int k) 219downheap (WT *timers, int N, int k)
193{ 220{
194 struct ev_timer *w = timers [k]; 221 WT w = timers [k];
195 222
196 while (k < (N >> 1)) 223 while (k < (N >> 1))
197 { 224 {
198 int j = k << 1; 225 int j = k << 1;
199 226
325 if (ev_method == EVMETHOD_NONE) select_init (flags); 352 if (ev_method == EVMETHOD_NONE) select_init (flags);
326#endif 353#endif
327 354
328 if (ev_method) 355 if (ev_method)
329 { 356 {
330 evw_init (&sigev, sigcb, 0); 357 evw_init (&sigev, sigcb);
331 siginit (); 358 siginit ();
332 } 359 }
333 360
334 return ev_method; 361 return ev_method;
335} 362}
406 433
407 pendingcnt = 0; 434 pendingcnt = 0;
408} 435}
409 436
410static void 437static void
411timers_reify (struct ev_timer **timers, int timercnt, ev_tstamp now) 438timers_reify ()
412{ 439{
413 while (timercnt && timers [0]->at <= now) 440 while (timercnt && timers [0]->at <= now)
414 { 441 {
415 struct ev_timer *w = timers [0]; 442 struct ev_timer *w = timers [0];
443
444 event ((W)w, EV_TIMEOUT);
416 445
417 /* first reschedule or stop timer */ 446 /* first reschedule or stop timer */
418 if (w->repeat) 447 if (w->repeat)
419 { 448 {
420 if (w->is_abs)
421 w->at += floor ((now - w->at) / w->repeat + 1.) * w->repeat;
422 else
423 w->at = now + w->repeat; 449 w->at = now + w->repeat;
424 450 assert (("timer timeout in the past, negative repeat?", w->at > now));
425 assert (w->at > now);
426
427 downheap (timers, timercnt, 0); 451 downheap ((WT *)timers, timercnt, 0);
428 } 452 }
429 else 453 else
430 {
431 evtimer_stop (w); /* nonrepeating: stop timer */ 454 evtimer_stop (w); /* nonrepeating: stop timer */
432 --timercnt; /* maybe pass by reference instead? */ 455 }
456}
457
458static void
459periodics_reify ()
460{
461 while (periodiccnt && periodics [0]->at <= ev_now)
462 {
463 struct ev_periodic *w = periodics [0];
464
465 /* first reschedule or stop timer */
466 if (w->interval)
433 } 467 {
468 w->at += floor ((ev_now - w->at) / w->interval + 1.) * w->interval;
469 assert (("periodic timeout in the past, negative interval?", w->at > ev_now));
470 downheap ((WT *)periodics, periodiccnt, 0);
471 }
472 else
473 evperiodic_stop (w); /* nonrepeating: stop timer */
434 474
435 event ((W)w, EV_TIMEOUT); 475 event ((W)w, EV_TIMEOUT);
436 } 476 }
437} 477}
438 478
439static void 479static void
480periodics_reschedule (ev_tstamp diff)
481{
482 int i;
483
484 /* adjust periodics after time jump */
485 for (i = 0; i < periodiccnt; ++i)
486 {
487 struct ev_periodic *w = periodics [i];
488
489 if (w->interval)
490 {
491 ev_tstamp diff = ceil ((ev_now - w->at) / w->interval) * w->interval;
492
493 if (fabs (diff) >= 1e-4)
494 {
495 evperiodic_stop (w);
496 evperiodic_start (w);
497
498 i = 0; /* restart loop, inefficient, but time jumps should be rare */
499 }
500 }
501 }
502}
503
504static void
440time_update () 505time_update ()
441{ 506{
442 int i; 507 int i;
508
443 ev_now = ev_time (); 509 ev_now = ev_time ();
444 510
445 if (have_monotonic) 511 if (have_monotonic)
446 { 512 {
447 ev_tstamp odiff = diff; 513 ev_tstamp odiff = diff;
448 514
449 /* detecting time jumps is much more difficult */
450 for (i = 2; --i; ) /* loop a few times, before making important decisions */ 515 for (i = 4; --i; ) /* loop a few times, before making important decisions */
451 { 516 {
452 now = get_clock (); 517 now = get_clock ();
453 diff = ev_now - now; 518 diff = ev_now - now;
454 519
455 if (fabs (odiff - diff) < MIN_TIMEJUMP) 520 if (fabs (odiff - diff) < MIN_TIMEJUMP)
456 return; /* all is well */ 521 return; /* all is well */
457 522
458 ev_now = ev_time (); 523 ev_now = ev_time ();
459 } 524 }
460 525
461 /* time jump detected, reschedule atimers */ 526 periodics_reschedule (diff - odiff);
462 for (i = 0; i < atimercnt; ++i) 527 /* no timer adjustment, as the monotonic clock doesn't jump */
463 {
464 struct ev_timer *w = atimers [i];
465 w->at += ceil ((ev_now - w->at) / w->repeat + 1.) * w->repeat;
466 }
467 } 528 }
468 else 529 else
469 { 530 {
470 if (now > ev_now || now < ev_now - MAX_BLOCKTIME - MIN_TIMEJUMP) 531 if (now > ev_now || now < ev_now - MAX_BLOCKTIME - MIN_TIMEJUMP)
471 /* time jump detected, adjust rtimers */ 532 {
533 periodics_reschedule (ev_now - now);
534
535 /* adjust timers. this is easy, as the offset is the same for all */
472 for (i = 0; i < rtimercnt; ++i) 536 for (i = 0; i < timercnt; ++i)
473 rtimers [i]->at += ev_now - now; 537 timers [i]->at += diff;
538 }
474 539
475 now = ev_now; 540 now = ev_now;
476 } 541 }
477} 542}
478 543
479int ev_loop_done; 544int ev_loop_done;
480 545
481void ev_loop (int flags) 546void ev_loop (int flags)
482{ 547{
483 double block; 548 double block;
484 ev_loop_done = flags & EVLOOP_ONESHOT; 549 ev_loop_done = flags & EVLOOP_ONESHOT ? 1 : 0;
485 550
486 if (checkcnt) 551 if (checkcnt)
487 { 552 {
488 queue_events ((W *)checks, checkcnt, EV_CHECK); 553 queue_events ((W *)checks, checkcnt, EV_CHECK);
489 call_pending (); 554 call_pending ();
493 { 558 {
494 /* update fd-related kernel structures */ 559 /* update fd-related kernel structures */
495 fd_reify (); 560 fd_reify ();
496 561
497 /* calculate blocking time */ 562 /* calculate blocking time */
563
564 /* we only need this for !monotonic clock, but as we always have timers, we just calculate it every time */
565 ev_now = ev_time ();
566
498 if (flags & EVLOOP_NONBLOCK || idlecnt) 567 if (flags & EVLOOP_NONBLOCK || idlecnt)
499 block = 0.; 568 block = 0.;
500 else 569 else
501 { 570 {
502 block = MAX_BLOCKTIME; 571 block = MAX_BLOCKTIME;
503 572
504 if (rtimercnt) 573 if (timercnt)
505 { 574 {
506 ev_tstamp to = rtimers [0]->at - get_clock () + method_fudge; 575 ev_tstamp to = timers [0]->at - (have_monotonic ? get_clock () : ev_now) + method_fudge;
507 if (block > to) block = to; 576 if (block > to) block = to;
508 } 577 }
509 578
510 if (atimercnt) 579 if (periodiccnt)
511 { 580 {
512 ev_tstamp to = atimers [0]->at - ev_time () + method_fudge; 581 ev_tstamp to = periodics [0]->at - ev_now + method_fudge;
513 if (block > to) block = to; 582 if (block > to) block = to;
514 } 583 }
515 584
516 if (block < 0.) block = 0.; 585 if (block < 0.) block = 0.;
517 } 586 }
520 589
521 /* update ev_now, do magic */ 590 /* update ev_now, do magic */
522 time_update (); 591 time_update ();
523 592
524 /* queue pending timers and reschedule them */ 593 /* queue pending timers and reschedule them */
525 /* absolute timers first */ 594 periodics_reify (); /* absolute timers first */
526 timers_reify (atimers, atimercnt, ev_now);
527 /* relative timers second */ 595 timers_reify (); /* relative timers second */
528 timers_reify (rtimers, rtimercnt, now);
529 596
530 /* queue idle watchers unless io or timers are pending */ 597 /* queue idle watchers unless io or timers are pending */
531 if (!pendingcnt) 598 if (!pendingcnt)
532 queue_events ((W *)idles, idlecnt, EV_IDLE); 599 queue_events ((W *)idles, idlecnt, EV_IDLE);
533 600
535 queue_events ((W *)checks, checkcnt, EV_CHECK); 602 queue_events ((W *)checks, checkcnt, EV_CHECK);
536 603
537 call_pending (); 604 call_pending ();
538 } 605 }
539 while (!ev_loop_done); 606 while (!ev_loop_done);
607
608 if (ev_loop_done != 2)
609 ev_loop_done = 0;
540} 610}
541 611
542/*****************************************************************************/ 612/*****************************************************************************/
543 613
544static void 614static void
562 head = &(*head)->next; 632 head = &(*head)->next;
563 } 633 }
564} 634}
565 635
566static void 636static void
637ev_clear (W w)
638{
639 if (w->pending)
640 {
641 pendings [w->pending - 1].w = 0;
642 w->pending = 0;
643 }
644}
645
646static void
567ev_start (W w, int active) 647ev_start (W w, int active)
568{ 648{
569 w->pending = 0;
570 w->active = active; 649 w->active = active;
571} 650}
572 651
573static void 652static void
574ev_stop (W w) 653ev_stop (W w)
575{ 654{
576 if (w->pending)
577 pendings [w->pending - 1].w = 0;
578
579 w->active = 0; 655 w->active = 0;
580} 656}
581 657
582/*****************************************************************************/ 658/*****************************************************************************/
583 659
599} 675}
600 676
601void 677void
602evio_stop (struct ev_io *w) 678evio_stop (struct ev_io *w)
603{ 679{
680 ev_clear ((W)w);
604 if (!ev_is_active (w)) 681 if (!ev_is_active (w))
605 return; 682 return;
606 683
607 wlist_del ((WL *)&anfds[w->fd].head, (WL)w); 684 wlist_del ((WL *)&anfds[w->fd].head, (WL)w);
608 ev_stop ((W)w); 685 ev_stop ((W)w);
616evtimer_start (struct ev_timer *w) 693evtimer_start (struct ev_timer *w)
617{ 694{
618 if (ev_is_active (w)) 695 if (ev_is_active (w))
619 return; 696 return;
620 697
621 if (w->is_abs) 698 w->at += now;
622 {
623 /* this formula differs from the one in timer_reify becuse we do not round up */
624 if (w->repeat)
625 w->at += ceil ((ev_now - w->at) / w->repeat) * w->repeat;
626 699
700 assert (("timer repeat value less than zero not allowed", w->repeat >= 0.));
701
627 ev_start ((W)w, ++atimercnt); 702 ev_start ((W)w, ++timercnt);
628 array_needsize (atimers, atimermax, atimercnt, ); 703 array_needsize (timers, timermax, timercnt, );
629 atimers [atimercnt - 1] = w; 704 timers [timercnt - 1] = w;
630 upheap (atimers, atimercnt - 1); 705 upheap ((WT *)timers, timercnt - 1);
631 }
632 else
633 {
634 w->at += now;
635
636 ev_start ((W)w, ++rtimercnt);
637 array_needsize (rtimers, rtimermax, rtimercnt, );
638 rtimers [rtimercnt - 1] = w;
639 upheap (rtimers, rtimercnt - 1);
640 }
641
642} 706}
643 707
644void 708void
645evtimer_stop (struct ev_timer *w) 709evtimer_stop (struct ev_timer *w)
646{ 710{
711 ev_clear ((W)w);
647 if (!ev_is_active (w)) 712 if (!ev_is_active (w))
648 return; 713 return;
649 714
650 if (w->is_abs)
651 {
652 if (w->active < atimercnt--) 715 if (w->active < timercnt--)
653 { 716 {
654 atimers [w->active - 1] = atimers [atimercnt]; 717 timers [w->active - 1] = timers [timercnt];
718 downheap ((WT *)timers, timercnt, w->active - 1);
719 }
720
721 w->at = w->repeat;
722
723 ev_stop ((W)w);
724}
725
726void
727evtimer_again (struct ev_timer *w)
728{
729 if (ev_is_active (w))
730 {
731 if (w->repeat)
732 {
733 w->at = now + w->repeat;
655 downheap (atimers, atimercnt, w->active - 1); 734 downheap ((WT *)timers, timercnt, w->active - 1);
656 }
657 }
658 else
659 {
660 if (w->active < rtimercnt--)
661 { 735 }
662 rtimers [w->active - 1] = rtimers [rtimercnt]; 736 else
663 downheap (rtimers, rtimercnt, w->active - 1); 737 evtimer_stop (w);
664 } 738 }
739 else if (w->repeat)
740 evtimer_start (w);
741}
742
743void
744evperiodic_start (struct ev_periodic *w)
745{
746 if (ev_is_active (w))
747 return;
748
749 assert (("periodic interval value less than zero not allowed", w->interval >= 0.));
750
751 /* this formula differs from the one in periodic_reify because we do not always round up */
752 if (w->interval)
753 w->at += ceil ((ev_now - w->at) / w->interval) * w->interval;
754
755 ev_start ((W)w, ++periodiccnt);
756 array_needsize (periodics, periodicmax, periodiccnt, );
757 periodics [periodiccnt - 1] = w;
758 upheap ((WT *)periodics, periodiccnt - 1);
759}
760
761void
762evperiodic_stop (struct ev_periodic *w)
763{
764 ev_clear ((W)w);
765 if (!ev_is_active (w))
766 return;
767
768 if (w->active < periodiccnt--)
769 {
770 periodics [w->active - 1] = periodics [periodiccnt];
771 downheap ((WT *)periodics, periodiccnt, w->active - 1);
665 } 772 }
666 773
667 ev_stop ((W)w); 774 ev_stop ((W)w);
668} 775}
669 776
688} 795}
689 796
690void 797void
691evsignal_stop (struct ev_signal *w) 798evsignal_stop (struct ev_signal *w)
692{ 799{
800 ev_clear ((W)w);
693 if (!ev_is_active (w)) 801 if (!ev_is_active (w))
694 return; 802 return;
695 803
696 wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); 804 wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w);
697 ev_stop ((W)w); 805 ev_stop ((W)w);
710 idles [idlecnt - 1] = w; 818 idles [idlecnt - 1] = w;
711} 819}
712 820
713void evidle_stop (struct ev_idle *w) 821void evidle_stop (struct ev_idle *w)
714{ 822{
823 ev_clear ((W)w);
824 if (ev_is_active (w))
825 return;
826
715 idles [w->active - 1] = idles [--idlecnt]; 827 idles [w->active - 1] = idles [--idlecnt];
716 ev_stop ((W)w); 828 ev_stop ((W)w);
717} 829}
718 830
719void evcheck_start (struct ev_check *w) 831void evcheck_start (struct ev_check *w)
726 checks [checkcnt - 1] = w; 838 checks [checkcnt - 1] = w;
727} 839}
728 840
729void evcheck_stop (struct ev_check *w) 841void evcheck_stop (struct ev_check *w)
730{ 842{
843 ev_clear ((W)w);
844 if (ev_is_active (w))
845 return;
846
731 checks [w->active - 1] = checks [--checkcnt]; 847 checks [w->active - 1] = checks [--checkcnt];
732 ev_stop ((W)w); 848 ev_stop ((W)w);
733} 849}
734 850
735/*****************************************************************************/ 851/*****************************************************************************/
736 852
853struct ev_once
854{
855 struct ev_io io;
856 struct ev_timer to;
857 void (*cb)(int revents, void *arg);
858 void *arg;
859};
860
861static void
862once_cb (struct ev_once *once, int revents)
863{
864 void (*cb)(int revents, void *arg) = once->cb;
865 void *arg = once->arg;
866
867 evio_stop (&once->io);
868 evtimer_stop (&once->to);
869 free (once);
870
871 cb (revents, arg);
872}
873
874static void
875once_cb_io (struct ev_io *w, int revents)
876{
877 once_cb ((struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)), revents);
878}
879
880static void
881once_cb_to (struct ev_timer *w, int revents)
882{
883 once_cb ((struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)), revents);
884}
885
886void
887ev_once (int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg)
888{
889 struct ev_once *once = malloc (sizeof (struct ev_once));
890
891 if (!once)
892 cb (EV_ERROR, arg);
893 else
894 {
895 once->cb = cb;
896 once->arg = arg;
897
898 evw_init (&once->io, once_cb_io);
899
900 if (fd >= 0)
901 {
902 evio_set (&once->io, fd, events);
903 evio_start (&once->io);
904 }
905
906 evw_init (&once->to, once_cb_to);
907
908 if (timeout >= 0.)
909 {
910 evtimer_set (&once->to, timeout, 0.);
911 evtimer_start (&once->to);
912 }
913 }
914}
915
916/*****************************************************************************/
917
737#if 0 918#if 0
919
920struct ev_io wio;
738 921
739static void 922static void
740sin_cb (struct ev_io *w, int revents) 923sin_cb (struct ev_io *w, int revents)
741{ 924{
742 fprintf (stderr, "sin %d, revents %d\n", w->fd, revents); 925 fprintf (stderr, "sin %d, revents %d\n", w->fd, revents);
752 935
753static void 936static void
754scb (struct ev_signal *w, int revents) 937scb (struct ev_signal *w, int revents)
755{ 938{
756 fprintf (stderr, "signal %x,%d\n", revents, w->signum); 939 fprintf (stderr, "signal %x,%d\n", revents, w->signum);
940 evio_stop (&wio);
941 evio_start (&wio);
757} 942}
758 943
759static void 944static void
760gcb (struct ev_signal *w, int revents) 945gcb (struct ev_signal *w, int revents)
761{ 946{
762 fprintf (stderr, "generic %x\n", revents); 947 fprintf (stderr, "generic %x\n", revents);
948
763} 949}
764 950
765int main (void) 951int main (void)
766{ 952{
767 struct ev_io sin;
768
769 ev_init (0); 953 ev_init (0);
770 954
771 evw_init (&sin, sin_cb, 55);
772 evio_set (&sin, 0, EV_READ); 955 evio_init (&wio, sin_cb, 0, EV_READ);
773 evio_start (&sin); 956 evio_start (&wio);
774 957
775 struct ev_timer t[10000]; 958 struct ev_timer t[10000];
776 959
777#if 0 960#if 0
778 int i; 961 int i;
779 for (i = 0; i < 10000; ++i) 962 for (i = 0; i < 10000; ++i)
780 { 963 {
781 struct ev_timer *w = t + i; 964 struct ev_timer *w = t + i;
782 evw_init (w, ocb, i); 965 evw_init (w, ocb, i);
783 evtimer_set_abs (w, drand48 (), 0.99775533); 966 evtimer_init_abs (w, ocb, drand48 (), 0.99775533);
784 evtimer_start (w); 967 evtimer_start (w);
785 if (drand48 () < 0.5) 968 if (drand48 () < 0.5)
786 evtimer_stop (w); 969 evtimer_stop (w);
787 } 970 }
788#endif 971#endif
789 972
790 struct ev_timer t1; 973 struct ev_timer t1;
791 evw_init (&t1, ocb, 0); 974 evtimer_init (&t1, ocb, 5, 10);
792 evtimer_set_abs (&t1, 5, 10);
793 evtimer_start (&t1); 975 evtimer_start (&t1);
794 976
795 struct ev_signal sig; 977 struct ev_signal sig;
796 evw_init (&sig, scb, 65535);
797 evsignal_set (&sig, SIGQUIT); 978 evsignal_init (&sig, scb, SIGQUIT);
798 evsignal_start (&sig); 979 evsignal_start (&sig);
799 980
800 struct ev_check cw; 981 struct ev_check cw;
801 evw_init (&cw, gcb, 0); 982 evcheck_init (&cw, gcb);
802 evcheck_start (&cw); 983 evcheck_start (&cw);
803 984
804 struct ev_idle iw; 985 struct ev_idle iw;
805 evw_init (&iw, gcb, 0); 986 evidle_init (&iw, gcb);
806 evidle_start (&iw); 987 evidle_start (&iw);
807 988
808 ev_loop (0); 989 ev_loop (0);
809 990
810 return 0; 991 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines