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

Comparing libev/ev.c (file contents):
Revision 1.64 by root, Sun Nov 4 23:14:11 2007 UTC vs.
Revision 1.72 by root, Tue Nov 6 16:09:37 2007 UTC

54 54
55#endif 55#endif
56 56
57#include <math.h> 57#include <math.h>
58#include <stdlib.h> 58#include <stdlib.h>
59#include <unistd.h>
60#include <fcntl.h> 59#include <fcntl.h>
61#include <signal.h>
62#include <stddef.h> 60#include <stddef.h>
63 61
64#include <stdio.h> 62#include <stdio.h>
65 63
66#include <assert.h> 64#include <assert.h>
67#include <errno.h> 65#include <errno.h>
68#include <sys/types.h> 66#include <sys/types.h>
67#include <time.h>
68
69#include <signal.h>
70
69#ifndef WIN32 71#ifndef WIN32
72# include <unistd.h>
73# include <sys/time.h>
70# include <sys/wait.h> 74# include <sys/wait.h>
71#endif 75#endif
72#include <sys/time.h>
73#include <time.h>
74
75/**/ 76/**/
76 77
77#ifndef EV_USE_MONOTONIC 78#ifndef EV_USE_MONOTONIC
78# define EV_USE_MONOTONIC 1 79# define EV_USE_MONOTONIC 1
79#endif 80#endif
94# define EV_USE_KQUEUE 0 95# define EV_USE_KQUEUE 0
95#endif 96#endif
96 97
97#ifndef EV_USE_WIN32 98#ifndef EV_USE_WIN32
98# ifdef WIN32 99# ifdef WIN32
100# define EV_USE_WIN32 0 /* it does not exist, use select */
101# undef EV_USE_SELECT
99# define EV_USE_WIN32 1 102# define EV_USE_SELECT 1
100# else 103# else
101# define EV_USE_WIN32 0 104# define EV_USE_WIN32 0
102# endif 105# endif
103#endif 106#endif
104 107
145typedef struct ev_watcher_list *WL; 148typedef struct ev_watcher_list *WL;
146typedef struct ev_watcher_time *WT; 149typedef struct ev_watcher_time *WT;
147 150
148static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ 151static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
149 152
153#if WIN32
154/* note: the comment below could not be substantiated, but what would I care */
155/* MSDN says this is required to handle SIGFPE */
156volatile double SIGFPE_REQ = 0.0f;
157
158static int
159ev_socketpair_tcp (int filedes [2])
160{
161 struct sockaddr_in addr = { 0 };
162 int addr_size = sizeof (addr);
163 SOCKET listener;
164 SOCKET sock [2] = { -1, -1 };
165
166 if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
167 return -1;
168
169 addr.sin_family = AF_INET;
170 addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
171 addr.sin_port = 0;
172
173 if (bind (listener, (struct sockaddr *)&addr, addr_size))
174 goto fail;
175
176 if (getsockname(listener, (struct sockaddr *)&addr, &addr_size))
177 goto fail;
178
179 if (listen (listener, 1))
180 goto fail;
181
182 if ((sock [0] = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
183 goto fail;
184
185 if (connect (sock[0], (struct sockaddr *)&addr, addr_size))
186 goto fail;
187
188 if ((sock[1] = accept (listener, 0, 0)) < 0)
189 goto fail;
190
191 closesocket (listener);
192
193 filedes [0] = sock [0];
194 filedes [1] = sock [1];
195
196 return 0;
197
198fail:
199 closesocket (listener);
200
201 if (sock [0] != INVALID_SOCKET) closesocket (sock [0]);
202 if (sock [1] != INVALID_SOCKET) closesocket (sock [1]);
203
204 return -1;
205}
206
207# define ev_pipe(filedes) ev_socketpair_tcp (filedes)
208#else
209# define ev_pipe(filedes) pipe (filedes)
210#endif
211
150/*****************************************************************************/ 212/*****************************************************************************/
151 213
214static void (*syserr_cb)(const char *msg);
215
216void ev_set_syserr_cb (void (*cb)(const char *msg))
217{
218 syserr_cb = cb;
219}
220
221static void
222syserr (const char *msg)
223{
224 if (!msg)
225 msg = "(libev) system error";
226
227 if (syserr_cb)
228 syserr_cb (msg);
229 else
230 {
231 perror (msg);
232 abort ();
233 }
234}
235
236static void *(*alloc)(void *ptr, long size);
237
238void ev_set_allocator (void *(*cb)(void *ptr, long size))
239{
240 alloc = cb;
241}
242
243static void *
244ev_realloc (void *ptr, long size)
245{
246 ptr = alloc ? alloc (ptr, size) : realloc (ptr, size);
247
248 if (!ptr && size)
249 {
250 fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size);
251 abort ();
252 }
253
254 return ptr;
255}
256
257#define ev_malloc(size) ev_realloc (0, (size))
258#define ev_free(ptr) ev_realloc ((ptr), 0)
259
260/*****************************************************************************/
261
152typedef struct 262typedef struct
153{ 263{
154 struct ev_watcher_list *head; 264 WL head;
155 unsigned char events; 265 unsigned char events;
156 unsigned char reify; 266 unsigned char reify;
157} ANFD; 267} ANFD;
158 268
159typedef struct 269typedef struct
217 return rt_now; 327 return rt_now;
218} 328}
219 329
220#define array_roundsize(base,n) ((n) | 4 & ~3) 330#define array_roundsize(base,n) ((n) | 4 & ~3)
221 331
222#define array_needsize(base,cur,cnt,init) \ 332#define array_needsize(base,cur,cnt,init) \
223 if (expect_false ((cnt) > cur)) \ 333 if (expect_false ((cnt) > cur)) \
224 { \ 334 { \
225 int newcnt = cur; \ 335 int newcnt = cur; \
226 do \ 336 do \
227 { \ 337 { \
228 newcnt = array_roundsize (base, newcnt << 1); \ 338 newcnt = array_roundsize (base, newcnt << 1); \
229 } \ 339 } \
230 while ((cnt) > newcnt); \ 340 while ((cnt) > newcnt); \
231 \ 341 \
232 base = realloc (base, sizeof (*base) * (newcnt)); \ 342 base = ev_realloc (base, sizeof (*base) * (newcnt)); \
233 init (base + cur, newcnt - cur); \ 343 init (base + cur, newcnt - cur); \
234 cur = newcnt; \ 344 cur = newcnt; \
235 } 345 }
346
347#define array_slim(stem) \
348 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \
349 { \
350 stem ## max = array_roundsize (stem ## cnt >> 1); \
351 base = ev_realloc (base, sizeof (*base) * (stem ## max)); \
352 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\
353 }
354
355/* microsoft's pseudo-c is quite far from C as the rest of the world and the standard knows it */
356/* bringing us everlasting joy in form of stupid extra macros that are not required in C */
357#define array_free_microshit(stem) \
358 ev_free (stem ## s); stem ## cnt = stem ## max = 0;
359
360#define array_free(stem, idx) \
361 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0;
236 362
237/*****************************************************************************/ 363/*****************************************************************************/
238 364
239static void 365static void
240anfds_init (ANFD *base, int count) 366anfds_init (ANFD *base, int count)
257 pendings [ABSPRI (w)][w->pending - 1].events |= events; 383 pendings [ABSPRI (w)][w->pending - 1].events |= events;
258 return; 384 return;
259 } 385 }
260 386
261 w->pending = ++pendingcnt [ABSPRI (w)]; 387 w->pending = ++pendingcnt [ABSPRI (w)];
262 array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], ); 388 array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], (void));
263 pendings [ABSPRI (w)][w->pending - 1].w = w; 389 pendings [ABSPRI (w)][w->pending - 1].w = w;
264 pendings [ABSPRI (w)][w->pending - 1].events = events; 390 pendings [ABSPRI (w)][w->pending - 1].events = events;
265} 391}
266 392
267static void 393static void
316} 442}
317 443
318static void 444static void
319fd_change (EV_P_ int fd) 445fd_change (EV_P_ int fd)
320{ 446{
321 if (anfds [fd].reify || fdchangecnt < 0) 447 if (anfds [fd].reify)
322 return; 448 return;
323 449
324 anfds [fd].reify = 1; 450 anfds [fd].reify = 1;
325 451
326 ++fdchangecnt; 452 ++fdchangecnt;
327 array_needsize (fdchanges, fdchangemax, fdchangecnt, ); 453 array_needsize (fdchanges, fdchangemax, fdchangecnt, (void));
328 fdchanges [fdchangecnt - 1] = fd; 454 fdchanges [fdchangecnt - 1] = fd;
329} 455}
330 456
331static void 457static void
332fd_kill (EV_P_ int fd) 458fd_kill (EV_P_ int fd)
338 ev_io_stop (EV_A_ w); 464 ev_io_stop (EV_A_ w);
339 event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); 465 event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE);
340 } 466 }
341} 467}
342 468
469static int
470fd_valid (int fd)
471{
472#ifdef WIN32
473 return !!win32_get_osfhandle (fd);
474#else
475 return fcntl (fd, F_GETFD) != -1;
476#endif
477}
478
343/* called on EBADF to verify fds */ 479/* called on EBADF to verify fds */
344static void 480static void
345fd_ebadf (EV_P) 481fd_ebadf (EV_P)
346{ 482{
347 int fd; 483 int fd;
348 484
349 for (fd = 0; fd < anfdmax; ++fd) 485 for (fd = 0; fd < anfdmax; ++fd)
350 if (anfds [fd].events) 486 if (anfds [fd].events)
351 if (fcntl (fd, F_GETFD) == -1 && errno == EBADF) 487 if (!fd_valid (fd) == -1 && errno == EBADF)
352 fd_kill (EV_A_ fd); 488 fd_kill (EV_A_ fd);
353} 489}
354 490
355/* called on ENOMEM in select/poll to kill some fds and retry */ 491/* called on ENOMEM in select/poll to kill some fds and retry */
356static void 492static void
359 int fd; 495 int fd;
360 496
361 for (fd = anfdmax; fd--; ) 497 for (fd = anfdmax; fd--; )
362 if (anfds [fd].events) 498 if (anfds [fd].events)
363 { 499 {
364 close (fd);
365 fd_kill (EV_A_ fd); 500 fd_kill (EV_A_ fd);
366 return; 501 return;
367 } 502 }
368} 503}
369 504
370/* susually called after fork if method needs to re-arm all fds from scratch */ 505/* usually called after fork if method needs to re-arm all fds from scratch */
371static void 506static void
372fd_rearm_all (EV_P) 507fd_rearm_all (EV_P)
373{ 508{
374 int fd; 509 int fd;
375 510
427 562
428/*****************************************************************************/ 563/*****************************************************************************/
429 564
430typedef struct 565typedef struct
431{ 566{
432 struct ev_watcher_list *head; 567 WL head;
433 sig_atomic_t volatile gotsig; 568 sig_atomic_t volatile gotsig;
434} ANSIG; 569} ANSIG;
435 570
436static ANSIG *signals; 571static ANSIG *signals;
437static int signalmax; 572static int signalmax;
453} 588}
454 589
455static void 590static void
456sighandler (int signum) 591sighandler (int signum)
457{ 592{
593#if WIN32
594 signal (signum, sighandler);
595#endif
596
458 signals [signum - 1].gotsig = 1; 597 signals [signum - 1].gotsig = 1;
459 598
460 if (!gotsig) 599 if (!gotsig)
461 { 600 {
462 int old_errno = errno; 601 int old_errno = errno;
467} 606}
468 607
469static void 608static void
470sigcb (EV_P_ struct ev_io *iow, int revents) 609sigcb (EV_P_ struct ev_io *iow, int revents)
471{ 610{
472 struct ev_watcher_list *w; 611 WL w;
473 int signum; 612 int signum;
474 613
475 read (sigpipe [0], &revents, 1); 614 read (sigpipe [0], &revents, 1);
476 gotsig = 0; 615 gotsig = 0;
477 616
502 ev_unref (EV_A); /* child watcher should not keep loop alive */ 641 ev_unref (EV_A); /* child watcher should not keep loop alive */
503} 642}
504 643
505/*****************************************************************************/ 644/*****************************************************************************/
506 645
646static struct ev_child *childs [PID_HASHSIZE];
647
507#ifndef WIN32 648#ifndef WIN32
508 649
509static struct ev_child *childs [PID_HASHSIZE];
510static struct ev_signal childev; 650static struct ev_signal childev;
511 651
512#ifndef WCONTINUED 652#ifndef WCONTINUED
513# define WCONTINUED 0 653# define WCONTINUED 0
514#endif 654#endif
628 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); 768 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods);
629#endif 769#endif
630#if EV_USE_SELECT 770#if EV_USE_SELECT
631 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); 771 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods);
632#endif 772#endif
773
774 ev_watcher_init (&sigev, sigcb);
775 ev_set_priority (&sigev, EV_MAXPRI);
633 } 776 }
634} 777}
635 778
636void 779void
637loop_destroy (EV_P) 780loop_destroy (EV_P)
638{ 781{
782 int i;
783
639#if EV_USE_WIN32 784#if EV_USE_WIN32
640 if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A); 785 if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A);
641#endif 786#endif
642#if EV_USE_KQUEUE 787#if EV_USE_KQUEUE
643 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); 788 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
650#endif 795#endif
651#if EV_USE_SELECT 796#if EV_USE_SELECT
652 if (method == EVMETHOD_SELECT) select_destroy (EV_A); 797 if (method == EVMETHOD_SELECT) select_destroy (EV_A);
653#endif 798#endif
654 799
800 for (i = NUMPRI; i--; )
801 array_free (pending, [i]);
802
803 /* have to use the microsoft-never-gets-it-right macro */
804 array_free_microshit (fdchange);
805 array_free_microshit (timer);
806 array_free_microshit (periodic);
807 array_free_microshit (idle);
808 array_free_microshit (prepare);
809 array_free_microshit (check);
810
655 method = 0; 811 method = 0;
656 /*TODO*/
657} 812}
658 813
659void 814static void
660loop_fork (EV_P) 815loop_fork (EV_P)
661{ 816{
662 /*TODO*/
663#if EV_USE_EPOLL 817#if EV_USE_EPOLL
664 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); 818 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A);
665#endif 819#endif
666#if EV_USE_KQUEUE 820#if EV_USE_KQUEUE
667 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); 821 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A);
668#endif 822#endif
823
824 if (ev_is_active (&sigev))
825 {
826 /* default loop */
827
828 ev_ref (EV_A);
829 ev_io_stop (EV_A_ &sigev);
830 close (sigpipe [0]);
831 close (sigpipe [1]);
832
833 while (ev_pipe (sigpipe))
834 syserr ("(libev) error creating pipe");
835
836 siginit (EV_A);
837 }
838
839 postfork = 0;
669} 840}
670 841
671#if EV_MULTIPLICITY 842#if EV_MULTIPLICITY
672struct ev_loop * 843struct ev_loop *
673ev_loop_new (int methods) 844ev_loop_new (int methods)
674{ 845{
675 struct ev_loop *loop = (struct ev_loop *)calloc (1, sizeof (struct ev_loop)); 846 struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
847
848 memset (loop, 0, sizeof (struct ev_loop));
676 849
677 loop_init (EV_A_ methods); 850 loop_init (EV_A_ methods);
678 851
679 if (ev_method (EV_A)) 852 if (ev_method (EV_A))
680 return loop; 853 return loop;
684 857
685void 858void
686ev_loop_destroy (EV_P) 859ev_loop_destroy (EV_P)
687{ 860{
688 loop_destroy (EV_A); 861 loop_destroy (EV_A);
689 free (loop); 862 ev_free (loop);
690} 863}
691 864
692void 865void
693ev_loop_fork (EV_P) 866ev_loop_fork (EV_P)
694{ 867{
695 loop_fork (EV_A); 868 postfork = 1;
696} 869}
697 870
698#endif 871#endif
699 872
700#if EV_MULTIPLICITY 873#if EV_MULTIPLICITY
708int 881int
709#endif 882#endif
710ev_default_loop (int methods) 883ev_default_loop (int methods)
711{ 884{
712 if (sigpipe [0] == sigpipe [1]) 885 if (sigpipe [0] == sigpipe [1])
713 if (pipe (sigpipe)) 886 if (ev_pipe (sigpipe))
714 return 0; 887 return 0;
715 888
716 if (!default_loop) 889 if (!default_loop)
717 { 890 {
718#if EV_MULTIPLICITY 891#if EV_MULTIPLICITY
723 896
724 loop_init (EV_A_ methods); 897 loop_init (EV_A_ methods);
725 898
726 if (ev_method (EV_A)) 899 if (ev_method (EV_A))
727 { 900 {
728 ev_watcher_init (&sigev, sigcb);
729 ev_set_priority (&sigev, EV_MAXPRI);
730 siginit (EV_A); 901 siginit (EV_A);
731 902
732#ifndef WIN32 903#ifndef WIN32
733 ev_signal_init (&childev, childcb, SIGCHLD); 904 ev_signal_init (&childev, childcb, SIGCHLD);
734 ev_set_priority (&childev, EV_MAXPRI); 905 ev_set_priority (&childev, EV_MAXPRI);
748{ 919{
749#if EV_MULTIPLICITY 920#if EV_MULTIPLICITY
750 struct ev_loop *loop = default_loop; 921 struct ev_loop *loop = default_loop;
751#endif 922#endif
752 923
924#ifndef WIN32
753 ev_ref (EV_A); /* child watcher */ 925 ev_ref (EV_A); /* child watcher */
754 ev_signal_stop (EV_A_ &childev); 926 ev_signal_stop (EV_A_ &childev);
927#endif
755 928
756 ev_ref (EV_A); /* signal watcher */ 929 ev_ref (EV_A); /* signal watcher */
757 ev_io_stop (EV_A_ &sigev); 930 ev_io_stop (EV_A_ &sigev);
758 931
759 close (sigpipe [0]); sigpipe [0] = 0; 932 close (sigpipe [0]); sigpipe [0] = 0;
767{ 940{
768#if EV_MULTIPLICITY 941#if EV_MULTIPLICITY
769 struct ev_loop *loop = default_loop; 942 struct ev_loop *loop = default_loop;
770#endif 943#endif
771 944
772 loop_fork (EV_A); 945 if (method)
773 946 postfork = 1;
774 ev_io_stop (EV_A_ &sigev);
775 close (sigpipe [0]);
776 close (sigpipe [1]);
777 pipe (sigpipe);
778
779 ev_ref (EV_A); /* signal watcher */
780 siginit (EV_A);
781} 947}
782 948
783/*****************************************************************************/ 949/*****************************************************************************/
784 950
785static void 951static void
793 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 959 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
794 960
795 if (p->w) 961 if (p->w)
796 { 962 {
797 p->w->pending = 0; 963 p->w->pending = 0;
798
799 (*(void (**)(EV_P_ W, int))&p->w->cb) (EV_A_ p->w, p->events); 964 p->w->cb (EV_A_ p->w, p->events);
800 } 965 }
801 } 966 }
802} 967}
803 968
804static void 969static void
964 { 1129 {
965 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 1130 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
966 call_pending (EV_A); 1131 call_pending (EV_A);
967 } 1132 }
968 1133
1134 /* we might have forked, so reify kernel state if necessary */
1135 if (expect_false (postfork))
1136 loop_fork (EV_A);
1137
969 /* update fd-related kernel structures */ 1138 /* update fd-related kernel structures */
970 fd_reify (EV_A); 1139 fd_reify (EV_A);
971 1140
972 /* calculate blocking time */ 1141 /* calculate blocking time */
973 1142
1127 ((WT)w)->at += mn_now; 1296 ((WT)w)->at += mn_now;
1128 1297
1129 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 1298 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
1130 1299
1131 ev_start (EV_A_ (W)w, ++timercnt); 1300 ev_start (EV_A_ (W)w, ++timercnt);
1132 array_needsize (timers, timermax, timercnt, ); 1301 array_needsize (timers, timermax, timercnt, (void));
1133 timers [timercnt - 1] = w; 1302 timers [timercnt - 1] = w;
1134 upheap ((WT *)timers, timercnt - 1); 1303 upheap ((WT *)timers, timercnt - 1);
1135 1304
1136 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1305 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1137} 1306}
1184 /* this formula differs from the one in periodic_reify because we do not always round up */ 1353 /* this formula differs from the one in periodic_reify because we do not always round up */
1185 if (w->interval) 1354 if (w->interval)
1186 ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; 1355 ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval;
1187 1356
1188 ev_start (EV_A_ (W)w, ++periodiccnt); 1357 ev_start (EV_A_ (W)w, ++periodiccnt);
1189 array_needsize (periodics, periodicmax, periodiccnt, ); 1358 array_needsize (periodics, periodicmax, periodiccnt, (void));
1190 periodics [periodiccnt - 1] = w; 1359 periodics [periodiccnt - 1] = w;
1191 upheap ((WT *)periodics, periodiccnt - 1); 1360 upheap ((WT *)periodics, periodiccnt - 1);
1192 1361
1193 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1362 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1194} 1363}
1216{ 1385{
1217 if (ev_is_active (w)) 1386 if (ev_is_active (w))
1218 return; 1387 return;
1219 1388
1220 ev_start (EV_A_ (W)w, ++idlecnt); 1389 ev_start (EV_A_ (W)w, ++idlecnt);
1221 array_needsize (idles, idlemax, idlecnt, ); 1390 array_needsize (idles, idlemax, idlecnt, (void));
1222 idles [idlecnt - 1] = w; 1391 idles [idlecnt - 1] = w;
1223} 1392}
1224 1393
1225void 1394void
1226ev_idle_stop (EV_P_ struct ev_idle *w) 1395ev_idle_stop (EV_P_ struct ev_idle *w)
1238{ 1407{
1239 if (ev_is_active (w)) 1408 if (ev_is_active (w))
1240 return; 1409 return;
1241 1410
1242 ev_start (EV_A_ (W)w, ++preparecnt); 1411 ev_start (EV_A_ (W)w, ++preparecnt);
1243 array_needsize (prepares, preparemax, preparecnt, ); 1412 array_needsize (prepares, preparemax, preparecnt, (void));
1244 prepares [preparecnt - 1] = w; 1413 prepares [preparecnt - 1] = w;
1245} 1414}
1246 1415
1247void 1416void
1248ev_prepare_stop (EV_P_ struct ev_prepare *w) 1417ev_prepare_stop (EV_P_ struct ev_prepare *w)
1260{ 1429{
1261 if (ev_is_active (w)) 1430 if (ev_is_active (w))
1262 return; 1431 return;
1263 1432
1264 ev_start (EV_A_ (W)w, ++checkcnt); 1433 ev_start (EV_A_ (W)w, ++checkcnt);
1265 array_needsize (checks, checkmax, checkcnt, ); 1434 array_needsize (checks, checkmax, checkcnt, (void));
1266 checks [checkcnt - 1] = w; 1435 checks [checkcnt - 1] = w;
1267} 1436}
1268 1437
1269void 1438void
1270ev_check_stop (EV_P_ struct ev_check *w) 1439ev_check_stop (EV_P_ struct ev_check *w)
1296 array_needsize (signals, signalmax, w->signum, signals_init); 1465 array_needsize (signals, signalmax, w->signum, signals_init);
1297 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); 1466 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
1298 1467
1299 if (!((WL)w)->next) 1468 if (!((WL)w)->next)
1300 { 1469 {
1470#if WIN32
1471 signal (w->signum, sighandler);
1472#else
1301 struct sigaction sa; 1473 struct sigaction sa;
1302 sa.sa_handler = sighandler; 1474 sa.sa_handler = sighandler;
1303 sigfillset (&sa.sa_mask); 1475 sigfillset (&sa.sa_mask);
1304 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ 1476 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */
1305 sigaction (w->signum, &sa, 0); 1477 sigaction (w->signum, &sa, 0);
1478#endif
1306 } 1479 }
1307} 1480}
1308 1481
1309void 1482void
1310ev_signal_stop (EV_P_ struct ev_signal *w) 1483ev_signal_stop (EV_P_ struct ev_signal *w)
1360 void (*cb)(int revents, void *arg) = once->cb; 1533 void (*cb)(int revents, void *arg) = once->cb;
1361 void *arg = once->arg; 1534 void *arg = once->arg;
1362 1535
1363 ev_io_stop (EV_A_ &once->io); 1536 ev_io_stop (EV_A_ &once->io);
1364 ev_timer_stop (EV_A_ &once->to); 1537 ev_timer_stop (EV_A_ &once->to);
1365 free (once); 1538 ev_free (once);
1366 1539
1367 cb (revents, arg); 1540 cb (revents, arg);
1368} 1541}
1369 1542
1370static void 1543static void
1380} 1553}
1381 1554
1382void 1555void
1383ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) 1556ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg)
1384{ 1557{
1385 struct ev_once *once = malloc (sizeof (struct ev_once)); 1558 struct ev_once *once = ev_malloc (sizeof (struct ev_once));
1386 1559
1387 if (!once) 1560 if (!once)
1388 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); 1561 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg);
1389 else 1562 else
1390 { 1563 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines