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

Comparing libev/ev.c (file contents):
Revision 1.27 by root, Wed Oct 31 22:16:36 2007 UTC vs.
Revision 1.31 by root, Thu Nov 1 09:05:33 2007 UTC

24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29#if EV_USE_CONFIG_H
30# include "config.h"
31#endif
29 32
30#include <math.h> 33#include <math.h>
31#include <stdlib.h> 34#include <stdlib.h>
32#include <unistd.h> 35#include <unistd.h>
33#include <fcntl.h> 36#include <fcntl.h>
41#include <sys/types.h> 44#include <sys/types.h>
42#include <sys/wait.h> 45#include <sys/wait.h>
43#include <sys/time.h> 46#include <sys/time.h>
44#include <time.h> 47#include <time.h>
45 48
46#ifndef HAVE_MONOTONIC 49#ifndef EV_USE_MONOTONIC
47# ifdef CLOCK_MONOTONIC 50# ifdef CLOCK_MONOTONIC
48# define HAVE_MONOTONIC 1 51# define EV_USE_MONOTONIC 1
49# endif 52# endif
50#endif 53#endif
51 54
52#ifndef HAVE_SELECT 55#ifndef EV_USE_SELECT
53# define HAVE_SELECT 1 56# define EV_USE_SELECT 1
54#endif 57#endif
55 58
56#ifndef HAVE_EPOLL 59#ifndef EV_USE_EPOLL
57# define HAVE_EPOLL 0 60# define EV_USE_EPOLL 0
58#endif 61#endif
59 62
63#ifndef CLOCK_REALTIME
64# define EV_USE_REALTIME 0
65#endif
60#ifndef HAVE_REALTIME 66#ifndef EV_USE_REALTIME
61# define HAVE_REALTIME 1 /* posix requirement, but might be slower */ 67# define EV_USE_REALTIME 1 /* posix requirement, but might be slower */
62#endif 68#endif
63 69
64#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ 70#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
65#define MAX_BLOCKTIME 60. 71#define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detetc time jumps) */
66#define PID_HASHSIZE 16 /* size of pid hahs table, must be power of two */ 72#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */
73#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */
67 74
68#include "ev.h" 75#include "ev.h"
69 76
70typedef struct ev_watcher *W; 77typedef struct ev_watcher *W;
71typedef struct ev_watcher_list *WL; 78typedef struct ev_watcher_list *WL;
84/*****************************************************************************/ 91/*****************************************************************************/
85 92
86ev_tstamp 93ev_tstamp
87ev_time (void) 94ev_time (void)
88{ 95{
89#if HAVE_REALTIME 96#if EV_USE_REALTIME
90 struct timespec ts; 97 struct timespec ts;
91 clock_gettime (CLOCK_REALTIME, &ts); 98 clock_gettime (CLOCK_REALTIME, &ts);
92 return ts.tv_sec + ts.tv_nsec * 1e-9; 99 return ts.tv_sec + ts.tv_nsec * 1e-9;
93#else 100#else
94 struct timeval tv; 101 struct timeval tv;
98} 105}
99 106
100static ev_tstamp 107static ev_tstamp
101get_clock (void) 108get_clock (void)
102{ 109{
103#if HAVE_MONOTONIC 110#if EV_USE_MONOTONIC
104 if (have_monotonic) 111 if (have_monotonic)
105 { 112 {
106 struct timespec ts; 113 struct timespec ts;
107 clock_gettime (CLOCK_MONOTONIC, &ts); 114 clock_gettime (CLOCK_MONOTONIC, &ts);
108 return ts.tv_sec + ts.tv_nsec * 1e-9; 115 return ts.tv_sec + ts.tv_nsec * 1e-9;
109 } 116 }
110#endif 117#endif
111 118
112 return ev_time (); 119 return ev_time ();
113} 120}
121
122#define array_roundsize(base,n) ((n) | 4 & ~3)
114 123
115#define array_needsize(base,cur,cnt,init) \ 124#define array_needsize(base,cur,cnt,init) \
116 if ((cnt) > cur) \ 125 if ((cnt) > cur) \
117 { \ 126 { \
118 int newcnt = cur; \ 127 int newcnt = cur; \
119 do \ 128 do \
120 { \ 129 { \
121 newcnt = (newcnt << 1) | 4 & ~3; \ 130 newcnt = array_roundsize (base, newcnt << 1); \
122 } \ 131 } \
123 while ((cnt) > newcnt); \ 132 while ((cnt) > newcnt); \
124 \ 133 \
125 base = realloc (base, sizeof (*base) * (newcnt)); \ 134 base = realloc (base, sizeof (*base) * (newcnt)); \
126 init (base + cur, newcnt - cur); \ 135 init (base + cur, newcnt - cur); \
159static int pendingmax, pendingcnt; 168static int pendingmax, pendingcnt;
160 169
161static void 170static void
162event (W w, int events) 171event (W w, int events)
163{ 172{
164 if (w->active)
165 {
166 w->pending = ++pendingcnt; 173 w->pending = ++pendingcnt;
167 array_needsize (pendings, pendingmax, pendingcnt, ); 174 array_needsize (pendings, pendingmax, pendingcnt, );
168 pendings [pendingcnt - 1].w = w; 175 pendings [pendingcnt - 1].w = w;
169 pendings [pendingcnt - 1].events = events; 176 pendings [pendingcnt - 1].events = events;
170 }
171} 177}
172 178
173static void 179static void
174queue_events (W *events, int eventcnt, int type) 180queue_events (W *events, int eventcnt, int type)
175{ 181{
228} 234}
229 235
230static void 236static void
231fd_change (int fd) 237fd_change (int fd)
232{ 238{
233 if (anfds [fd].events & EV_REIFY) 239 if (anfds [fd].events & EV_REIFY || fdchangecnt < 0)
234 return; 240 return;
235 241
236 anfds [fd].events |= EV_REIFY; 242 anfds [fd].events |= EV_REIFY;
237 243
238 ++fdchangecnt; 244 ++fdchangecnt;
249 for (fd = 0; fd < anfdmax; ++fd) 255 for (fd = 0; fd < anfdmax; ++fd)
250 if (anfds [fd].events) 256 if (anfds [fd].events)
251 if (fcntl (fd, F_GETFD) == -1 && errno == EBADF) 257 if (fcntl (fd, F_GETFD) == -1 && errno == EBADF)
252 while (anfds [fd].head) 258 while (anfds [fd].head)
253 { 259 {
254 event ((W)anfds [fd].head, EV_ERROR); 260 event ((W)anfds [fd].head, EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT);
255 evio_stop (anfds [fd].head); 261 ev_io_stop (anfds [fd].head);
256 } 262 }
257} 263}
258 264
259/*****************************************************************************/ 265/*****************************************************************************/
260 266
370 376
371 /* rather than sort out wether we really need nb, set it */ 377 /* rather than sort out wether we really need nb, set it */
372 fcntl (sigpipe [0], F_SETFL, O_NONBLOCK); 378 fcntl (sigpipe [0], F_SETFL, O_NONBLOCK);
373 fcntl (sigpipe [1], F_SETFL, O_NONBLOCK); 379 fcntl (sigpipe [1], F_SETFL, O_NONBLOCK);
374 380
375 evio_set (&sigev, sigpipe [0], EV_READ); 381 ev_io_set (&sigev, sigpipe [0], EV_READ);
376 evio_start (&sigev); 382 ev_io_start (&sigev);
377} 383}
378 384
379/*****************************************************************************/ 385/*****************************************************************************/
380 386
381static struct ev_idle **idles; 387static struct ev_idle **idles;
411 } 417 }
412} 418}
413 419
414/*****************************************************************************/ 420/*****************************************************************************/
415 421
416#if HAVE_EPOLL 422#if EV_USE_EPOLL
417# include "ev_epoll.c" 423# include "ev_epoll.c"
418#endif 424#endif
419#if HAVE_SELECT 425#if EV_USE_SELECT
420# include "ev_select.c" 426# include "ev_select.c"
421#endif 427#endif
422 428
423int 429int
424ev_version_major (void) 430ev_version_major (void)
434 440
435int ev_init (int flags) 441int ev_init (int flags)
436{ 442{
437 if (!ev_method) 443 if (!ev_method)
438 { 444 {
439#if HAVE_MONOTONIC 445#if EV_USE_MONOTONIC
440 { 446 {
441 struct timespec ts; 447 struct timespec ts;
442 if (!clock_gettime (CLOCK_MONOTONIC, &ts)) 448 if (!clock_gettime (CLOCK_MONOTONIC, &ts))
443 have_monotonic = 1; 449 have_monotonic = 1;
444 } 450 }
450 456
451 if (pipe (sigpipe)) 457 if (pipe (sigpipe))
452 return 0; 458 return 0;
453 459
454 ev_method = EVMETHOD_NONE; 460 ev_method = EVMETHOD_NONE;
455#if HAVE_EPOLL 461#if EV_USE_EPOLL
456 if (ev_method == EVMETHOD_NONE) epoll_init (flags); 462 if (ev_method == EVMETHOD_NONE) epoll_init (flags);
457#endif 463#endif
458#if HAVE_SELECT 464#if EV_USE_SELECT
459 if (ev_method == EVMETHOD_NONE) select_init (flags); 465 if (ev_method == EVMETHOD_NONE) select_init (flags);
460#endif 466#endif
461 467
462 if (ev_method) 468 if (ev_method)
463 { 469 {
464 evw_init (&sigev, sigcb); 470 ev_watcher_init (&sigev, sigcb);
465 siginit (); 471 siginit ();
466 472
467 evsignal_init (&childev, childcb, SIGCHLD); 473 ev_signal_init (&childev, childcb, SIGCHLD);
468 evsignal_start (&childev); 474 ev_signal_start (&childev);
469 } 475 }
470 } 476 }
471 477
472 return ev_method; 478 return ev_method;
473} 479}
487} 493}
488 494
489void 495void
490ev_postfork_child (void) 496ev_postfork_child (void)
491{ 497{
492#if HAVE_EPOLL 498#if EV_USE_EPOLL
493 if (ev_method == EVMETHOD_EPOLL) 499 if (ev_method == EVMETHOD_EPOLL)
494 epoll_postfork_child (); 500 epoll_postfork_child ();
495#endif 501#endif
496 502
497 evio_stop (&sigev); 503 ev_io_stop (&sigev);
498 close (sigpipe [0]); 504 close (sigpipe [0]);
499 close (sigpipe [1]); 505 close (sigpipe [1]);
500 pipe (sigpipe); 506 pipe (sigpipe);
501 siginit (); 507 siginit ();
502} 508}
523{ 529{
524 while (timercnt && timers [0]->at <= now) 530 while (timercnt && timers [0]->at <= now)
525 { 531 {
526 struct ev_timer *w = timers [0]; 532 struct ev_timer *w = timers [0];
527 533
528 event ((W)w, EV_TIMEOUT);
529
530 /* first reschedule or stop timer */ 534 /* first reschedule or stop timer */
531 if (w->repeat) 535 if (w->repeat)
532 { 536 {
533 w->at = now + w->repeat; 537 w->at = now + w->repeat;
534 assert (("timer timeout in the past, negative repeat?", w->at > now)); 538 assert (("timer timeout in the past, negative repeat?", w->at > now));
535 downheap ((WT *)timers, timercnt, 0); 539 downheap ((WT *)timers, timercnt, 0);
536 } 540 }
537 else 541 else
538 evtimer_stop (w); /* nonrepeating: stop timer */ 542 ev_timer_stop (w); /* nonrepeating: stop timer */
543
544 event ((W)w, EV_TIMEOUT);
539 } 545 }
540} 546}
541 547
542static void 548static void
543periodics_reify (void) 549periodics_reify (void)
552 w->at += floor ((ev_now - w->at) / w->interval + 1.) * w->interval; 558 w->at += floor ((ev_now - w->at) / w->interval + 1.) * w->interval;
553 assert (("periodic timeout in the past, negative interval?", w->at > ev_now)); 559 assert (("periodic timeout in the past, negative interval?", w->at > ev_now));
554 downheap ((WT *)periodics, periodiccnt, 0); 560 downheap ((WT *)periodics, periodiccnt, 0);
555 } 561 }
556 else 562 else
557 evperiodic_stop (w); /* nonrepeating: stop timer */ 563 ev_periodic_stop (w); /* nonrepeating: stop timer */
558 564
559 event ((W)w, EV_TIMEOUT); 565 event ((W)w, EV_TIMEOUT);
560 } 566 }
561} 567}
562 568
574 { 580 {
575 ev_tstamp diff = ceil ((ev_now - w->at) / w->interval) * w->interval; 581 ev_tstamp diff = ceil ((ev_now - w->at) / w->interval) * w->interval;
576 582
577 if (fabs (diff) >= 1e-4) 583 if (fabs (diff) >= 1e-4)
578 { 584 {
579 evperiodic_stop (w); 585 ev_periodic_stop (w);
580 evperiodic_start (w); 586 ev_periodic_start (w);
581 587
582 i = 0; /* restart loop, inefficient, but time jumps should be rare */ 588 i = 0; /* restart loop, inefficient, but time jumps should be rare */
583 } 589 }
584 } 590 }
585 } 591 }
743} 749}
744 750
745/*****************************************************************************/ 751/*****************************************************************************/
746 752
747void 753void
748evio_start (struct ev_io *w) 754ev_io_start (struct ev_io *w)
749{ 755{
750 if (ev_is_active (w)) 756 if (ev_is_active (w))
751 return; 757 return;
752 758
753 int fd = w->fd; 759 int fd = w->fd;
758 764
759 fd_change (fd); 765 fd_change (fd);
760} 766}
761 767
762void 768void
763evio_stop (struct ev_io *w) 769ev_io_stop (struct ev_io *w)
764{ 770{
765 ev_clear ((W)w); 771 ev_clear ((W)w);
766 if (!ev_is_active (w)) 772 if (!ev_is_active (w))
767 return; 773 return;
768 774
771 777
772 fd_change (w->fd); 778 fd_change (w->fd);
773} 779}
774 780
775void 781void
776evtimer_start (struct ev_timer *w) 782ev_timer_start (struct ev_timer *w)
777{ 783{
778 if (ev_is_active (w)) 784 if (ev_is_active (w))
779 return; 785 return;
780 786
781 w->at += now; 787 w->at += now;
787 timers [timercnt - 1] = w; 793 timers [timercnt - 1] = w;
788 upheap ((WT *)timers, timercnt - 1); 794 upheap ((WT *)timers, timercnt - 1);
789} 795}
790 796
791void 797void
792evtimer_stop (struct ev_timer *w) 798ev_timer_stop (struct ev_timer *w)
793{ 799{
794 ev_clear ((W)w); 800 ev_clear ((W)w);
795 if (!ev_is_active (w)) 801 if (!ev_is_active (w))
796 return; 802 return;
797 803
805 811
806 ev_stop ((W)w); 812 ev_stop ((W)w);
807} 813}
808 814
809void 815void
810evtimer_again (struct ev_timer *w) 816ev_timer_again (struct ev_timer *w)
811{ 817{
812 if (ev_is_active (w)) 818 if (ev_is_active (w))
813 { 819 {
814 if (w->repeat) 820 if (w->repeat)
815 { 821 {
816 w->at = now + w->repeat; 822 w->at = now + w->repeat;
817 downheap ((WT *)timers, timercnt, w->active - 1); 823 downheap ((WT *)timers, timercnt, w->active - 1);
818 } 824 }
819 else 825 else
820 evtimer_stop (w); 826 ev_timer_stop (w);
821 } 827 }
822 else if (w->repeat) 828 else if (w->repeat)
823 evtimer_start (w); 829 ev_timer_start (w);
824} 830}
825 831
826void 832void
827evperiodic_start (struct ev_periodic *w) 833ev_periodic_start (struct ev_periodic *w)
828{ 834{
829 if (ev_is_active (w)) 835 if (ev_is_active (w))
830 return; 836 return;
831 837
832 assert (("periodic interval value less than zero not allowed", w->interval >= 0.)); 838 assert (("periodic interval value less than zero not allowed", w->interval >= 0.));
840 periodics [periodiccnt - 1] = w; 846 periodics [periodiccnt - 1] = w;
841 upheap ((WT *)periodics, periodiccnt - 1); 847 upheap ((WT *)periodics, periodiccnt - 1);
842} 848}
843 849
844void 850void
845evperiodic_stop (struct ev_periodic *w) 851ev_periodic_stop (struct ev_periodic *w)
846{ 852{
847 ev_clear ((W)w); 853 ev_clear ((W)w);
848 if (!ev_is_active (w)) 854 if (!ev_is_active (w))
849 return; 855 return;
850 856
856 862
857 ev_stop ((W)w); 863 ev_stop ((W)w);
858} 864}
859 865
860void 866void
861evsignal_start (struct ev_signal *w) 867ev_signal_start (struct ev_signal *w)
862{ 868{
863 if (ev_is_active (w)) 869 if (ev_is_active (w))
864 return; 870 return;
865 871
866 ev_start ((W)w, 1); 872 ev_start ((W)w, 1);
876 sigaction (w->signum, &sa, 0); 882 sigaction (w->signum, &sa, 0);
877 } 883 }
878} 884}
879 885
880void 886void
881evsignal_stop (struct ev_signal *w) 887ev_signal_stop (struct ev_signal *w)
882{ 888{
883 ev_clear ((W)w); 889 ev_clear ((W)w);
884 if (!ev_is_active (w)) 890 if (!ev_is_active (w))
885 return; 891 return;
886 892
889 895
890 if (!signals [w->signum - 1].head) 896 if (!signals [w->signum - 1].head)
891 signal (w->signum, SIG_DFL); 897 signal (w->signum, SIG_DFL);
892} 898}
893 899
900void
894void evidle_start (struct ev_idle *w) 901ev_idle_start (struct ev_idle *w)
895{ 902{
896 if (ev_is_active (w)) 903 if (ev_is_active (w))
897 return; 904 return;
898 905
899 ev_start ((W)w, ++idlecnt); 906 ev_start ((W)w, ++idlecnt);
900 array_needsize (idles, idlemax, idlecnt, ); 907 array_needsize (idles, idlemax, idlecnt, );
901 idles [idlecnt - 1] = w; 908 idles [idlecnt - 1] = w;
902} 909}
903 910
911void
904void evidle_stop (struct ev_idle *w) 912ev_idle_stop (struct ev_idle *w)
905{ 913{
906 ev_clear ((W)w); 914 ev_clear ((W)w);
907 if (ev_is_active (w)) 915 if (ev_is_active (w))
908 return; 916 return;
909 917
910 idles [w->active - 1] = idles [--idlecnt]; 918 idles [w->active - 1] = idles [--idlecnt];
911 ev_stop ((W)w); 919 ev_stop ((W)w);
912} 920}
913 921
922void
914void evprepare_start (struct ev_prepare *w) 923ev_prepare_start (struct ev_prepare *w)
915{ 924{
916 if (ev_is_active (w)) 925 if (ev_is_active (w))
917 return; 926 return;
918 927
919 ev_start ((W)w, ++preparecnt); 928 ev_start ((W)w, ++preparecnt);
920 array_needsize (prepares, preparemax, preparecnt, ); 929 array_needsize (prepares, preparemax, preparecnt, );
921 prepares [preparecnt - 1] = w; 930 prepares [preparecnt - 1] = w;
922} 931}
923 932
933void
924void evprepare_stop (struct ev_prepare *w) 934ev_prepare_stop (struct ev_prepare *w)
925{ 935{
926 ev_clear ((W)w); 936 ev_clear ((W)w);
927 if (ev_is_active (w)) 937 if (ev_is_active (w))
928 return; 938 return;
929 939
930 prepares [w->active - 1] = prepares [--preparecnt]; 940 prepares [w->active - 1] = prepares [--preparecnt];
931 ev_stop ((W)w); 941 ev_stop ((W)w);
932} 942}
933 943
944void
934void evcheck_start (struct ev_check *w) 945ev_check_start (struct ev_check *w)
935{ 946{
936 if (ev_is_active (w)) 947 if (ev_is_active (w))
937 return; 948 return;
938 949
939 ev_start ((W)w, ++checkcnt); 950 ev_start ((W)w, ++checkcnt);
940 array_needsize (checks, checkmax, checkcnt, ); 951 array_needsize (checks, checkmax, checkcnt, );
941 checks [checkcnt - 1] = w; 952 checks [checkcnt - 1] = w;
942} 953}
943 954
955void
944void evcheck_stop (struct ev_check *w) 956ev_check_stop (struct ev_check *w)
945{ 957{
946 ev_clear ((W)w); 958 ev_clear ((W)w);
947 if (ev_is_active (w)) 959 if (ev_is_active (w))
948 return; 960 return;
949 961
950 checks [w->active - 1] = checks [--checkcnt]; 962 checks [w->active - 1] = checks [--checkcnt];
951 ev_stop ((W)w); 963 ev_stop ((W)w);
952} 964}
953 965
966void
954void evchild_start (struct ev_child *w) 967ev_child_start (struct ev_child *w)
955{ 968{
956 if (ev_is_active (w)) 969 if (ev_is_active (w))
957 return; 970 return;
958 971
959 ev_start ((W)w, 1); 972 ev_start ((W)w, 1);
960 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 973 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
961} 974}
962 975
976void
963void evchild_stop (struct ev_child *w) 977ev_child_stop (struct ev_child *w)
964{ 978{
965 ev_clear ((W)w); 979 ev_clear ((W)w);
966 if (ev_is_active (w)) 980 if (ev_is_active (w))
967 return; 981 return;
968 982
984once_cb (struct ev_once *once, int revents) 998once_cb (struct ev_once *once, int revents)
985{ 999{
986 void (*cb)(int revents, void *arg) = once->cb; 1000 void (*cb)(int revents, void *arg) = once->cb;
987 void *arg = once->arg; 1001 void *arg = once->arg;
988 1002
989 evio_stop (&once->io); 1003 ev_io_stop (&once->io);
990 evtimer_stop (&once->to); 1004 ev_timer_stop (&once->to);
991 free (once); 1005 free (once);
992 1006
993 cb (revents, arg); 1007 cb (revents, arg);
994} 1008}
995 1009
1009ev_once (int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) 1023ev_once (int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg)
1010{ 1024{
1011 struct ev_once *once = malloc (sizeof (struct ev_once)); 1025 struct ev_once *once = malloc (sizeof (struct ev_once));
1012 1026
1013 if (!once) 1027 if (!once)
1014 cb (EV_ERROR, arg); 1028 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg);
1015 else 1029 else
1016 { 1030 {
1017 once->cb = cb; 1031 once->cb = cb;
1018 once->arg = arg; 1032 once->arg = arg;
1019 1033
1020 evw_init (&once->io, once_cb_io); 1034 ev_watcher_init (&once->io, once_cb_io);
1021
1022 if (fd >= 0) 1035 if (fd >= 0)
1023 { 1036 {
1024 evio_set (&once->io, fd, events); 1037 ev_io_set (&once->io, fd, events);
1025 evio_start (&once->io); 1038 ev_io_start (&once->io);
1026 } 1039 }
1027 1040
1028 evw_init (&once->to, once_cb_to); 1041 ev_watcher_init (&once->to, once_cb_to);
1029
1030 if (timeout >= 0.) 1042 if (timeout >= 0.)
1031 { 1043 {
1032 evtimer_set (&once->to, timeout, 0.); 1044 ev_timer_set (&once->to, timeout, 0.);
1033 evtimer_start (&once->to); 1045 ev_timer_start (&once->to);
1034 } 1046 }
1035 } 1047 }
1036} 1048}
1037 1049
1038/*****************************************************************************/ 1050/*****************************************************************************/
1049 1061
1050static void 1062static void
1051ocb (struct ev_timer *w, int revents) 1063ocb (struct ev_timer *w, int revents)
1052{ 1064{
1053 //fprintf (stderr, "timer %f,%f (%x) (%f) d%p\n", w->at, w->repeat, revents, w->at - ev_time (), w->data); 1065 //fprintf (stderr, "timer %f,%f (%x) (%f) d%p\n", w->at, w->repeat, revents, w->at - ev_time (), w->data);
1054 evtimer_stop (w); 1066 ev_timer_stop (w);
1055 evtimer_start (w); 1067 ev_timer_start (w);
1056} 1068}
1057 1069
1058static void 1070static void
1059scb (struct ev_signal *w, int revents) 1071scb (struct ev_signal *w, int revents)
1060{ 1072{
1061 fprintf (stderr, "signal %x,%d\n", revents, w->signum); 1073 fprintf (stderr, "signal %x,%d\n", revents, w->signum);
1062 evio_stop (&wio); 1074 ev_io_stop (&wio);
1063 evio_start (&wio); 1075 ev_io_start (&wio);
1064} 1076}
1065 1077
1066static void 1078static void
1067gcb (struct ev_signal *w, int revents) 1079gcb (struct ev_signal *w, int revents)
1068{ 1080{
1072 1084
1073int main (void) 1085int main (void)
1074{ 1086{
1075 ev_init (0); 1087 ev_init (0);
1076 1088
1077 evio_init (&wio, sin_cb, 0, EV_READ); 1089 ev_io_init (&wio, sin_cb, 0, EV_READ);
1078 evio_start (&wio); 1090 ev_io_start (&wio);
1079 1091
1080 struct ev_timer t[10000]; 1092 struct ev_timer t[10000];
1081 1093
1082#if 0 1094#if 0
1083 int i; 1095 int i;
1084 for (i = 0; i < 10000; ++i) 1096 for (i = 0; i < 10000; ++i)
1085 { 1097 {
1086 struct ev_timer *w = t + i; 1098 struct ev_timer *w = t + i;
1087 evw_init (w, ocb, i); 1099 ev_watcher_init (w, ocb, i);
1088 evtimer_init_abs (w, ocb, drand48 (), 0.99775533); 1100 ev_timer_init_abs (w, ocb, drand48 (), 0.99775533);
1089 evtimer_start (w); 1101 ev_timer_start (w);
1090 if (drand48 () < 0.5) 1102 if (drand48 () < 0.5)
1091 evtimer_stop (w); 1103 ev_timer_stop (w);
1092 } 1104 }
1093#endif 1105#endif
1094 1106
1095 struct ev_timer t1; 1107 struct ev_timer t1;
1096 evtimer_init (&t1, ocb, 5, 10); 1108 ev_timer_init (&t1, ocb, 5, 10);
1097 evtimer_start (&t1); 1109 ev_timer_start (&t1);
1098 1110
1099 struct ev_signal sig; 1111 struct ev_signal sig;
1100 evsignal_init (&sig, scb, SIGQUIT); 1112 ev_signal_init (&sig, scb, SIGQUIT);
1101 evsignal_start (&sig); 1113 ev_signal_start (&sig);
1102 1114
1103 struct ev_check cw; 1115 struct ev_check cw;
1104 evcheck_init (&cw, gcb); 1116 ev_check_init (&cw, gcb);
1105 evcheck_start (&cw); 1117 ev_check_start (&cw);
1106 1118
1107 struct ev_idle iw; 1119 struct ev_idle iw;
1108 evidle_init (&iw, gcb); 1120 ev_idle_init (&iw, gcb);
1109 evidle_start (&iw); 1121 ev_idle_start (&iw);
1110 1122
1111 ev_loop (0); 1123 ev_loop (0);
1112 1124
1113 return 0; 1125 return 0;
1114} 1126}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines