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

Comparing libev/ev.c (file contents):
Revision 1.63 by root, Sun Nov 4 22:03:17 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
306 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) 432 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next)
307 events |= w->events; 433 events |= w->events;
308 434
309 anfd->reify = 0; 435 anfd->reify = 0;
310 436
311 if (anfd->events != events)
312 {
313 method_modify (EV_A_ fd, anfd->events, events); 437 method_modify (EV_A_ fd, anfd->events, events);
314 anfd->events = events; 438 anfd->events = events;
315 }
316 } 439 }
317 440
318 fdchangecnt = 0; 441 fdchangecnt = 0;
319} 442}
320 443
321static void 444static void
322fd_change (EV_P_ int fd) 445fd_change (EV_P_ int fd)
323{ 446{
324 if (anfds [fd].reify || fdchangecnt < 0) 447 if (anfds [fd].reify)
325 return; 448 return;
326 449
327 anfds [fd].reify = 1; 450 anfds [fd].reify = 1;
328 451
329 ++fdchangecnt; 452 ++fdchangecnt;
330 array_needsize (fdchanges, fdchangemax, fdchangecnt, ); 453 array_needsize (fdchanges, fdchangemax, fdchangecnt, (void));
331 fdchanges [fdchangecnt - 1] = fd; 454 fdchanges [fdchangecnt - 1] = fd;
332} 455}
333 456
334static void 457static void
335fd_kill (EV_P_ int fd) 458fd_kill (EV_P_ int fd)
341 ev_io_stop (EV_A_ w); 464 ev_io_stop (EV_A_ w);
342 event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); 465 event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE);
343 } 466 }
344} 467}
345 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
346/* called on EBADF to verify fds */ 479/* called on EBADF to verify fds */
347static void 480static void
348fd_ebadf (EV_P) 481fd_ebadf (EV_P)
349{ 482{
350 int fd; 483 int fd;
351 484
352 for (fd = 0; fd < anfdmax; ++fd) 485 for (fd = 0; fd < anfdmax; ++fd)
353 if (anfds [fd].events) 486 if (anfds [fd].events)
354 if (fcntl (fd, F_GETFD) == -1 && errno == EBADF) 487 if (!fd_valid (fd) == -1 && errno == EBADF)
355 fd_kill (EV_A_ fd); 488 fd_kill (EV_A_ fd);
356} 489}
357 490
358/* 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 */
359static void 492static void
362 int fd; 495 int fd;
363 496
364 for (fd = anfdmax; fd--; ) 497 for (fd = anfdmax; fd--; )
365 if (anfds [fd].events) 498 if (anfds [fd].events)
366 { 499 {
367 close (fd);
368 fd_kill (EV_A_ fd); 500 fd_kill (EV_A_ fd);
369 return; 501 return;
370 } 502 }
371} 503}
372 504
373/* 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 */
374static void 506static void
375fd_rearm_all (EV_P) 507fd_rearm_all (EV_P)
376{ 508{
377 int fd; 509 int fd;
378 510
430 562
431/*****************************************************************************/ 563/*****************************************************************************/
432 564
433typedef struct 565typedef struct
434{ 566{
435 struct ev_watcher_list *head; 567 WL head;
436 sig_atomic_t volatile gotsig; 568 sig_atomic_t volatile gotsig;
437} ANSIG; 569} ANSIG;
438 570
439static ANSIG *signals; 571static ANSIG *signals;
440static int signalmax; 572static int signalmax;
456} 588}
457 589
458static void 590static void
459sighandler (int signum) 591sighandler (int signum)
460{ 592{
593#if WIN32
594 signal (signum, sighandler);
595#endif
596
461 signals [signum - 1].gotsig = 1; 597 signals [signum - 1].gotsig = 1;
462 598
463 if (!gotsig) 599 if (!gotsig)
464 { 600 {
465 int old_errno = errno; 601 int old_errno = errno;
470} 606}
471 607
472static void 608static void
473sigcb (EV_P_ struct ev_io *iow, int revents) 609sigcb (EV_P_ struct ev_io *iow, int revents)
474{ 610{
475 struct ev_watcher_list *w; 611 WL w;
476 int signum; 612 int signum;
477 613
478 read (sigpipe [0], &revents, 1); 614 read (sigpipe [0], &revents, 1);
479 gotsig = 0; 615 gotsig = 0;
480 616
505 ev_unref (EV_A); /* child watcher should not keep loop alive */ 641 ev_unref (EV_A); /* child watcher should not keep loop alive */
506} 642}
507 643
508/*****************************************************************************/ 644/*****************************************************************************/
509 645
646static struct ev_child *childs [PID_HASHSIZE];
647
510#ifndef WIN32 648#ifndef WIN32
511 649
512static struct ev_child *childs [PID_HASHSIZE];
513static struct ev_signal childev; 650static struct ev_signal childev;
514 651
515#ifndef WCONTINUED 652#ifndef WCONTINUED
516# define WCONTINUED 0 653# define WCONTINUED 0
517#endif 654#endif
631 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); 768 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods);
632#endif 769#endif
633#if EV_USE_SELECT 770#if EV_USE_SELECT
634 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); 771 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods);
635#endif 772#endif
773
774 ev_watcher_init (&sigev, sigcb);
775 ev_set_priority (&sigev, EV_MAXPRI);
636 } 776 }
637} 777}
638 778
639void 779void
640loop_destroy (EV_P) 780loop_destroy (EV_P)
641{ 781{
782 int i;
783
642#if EV_USE_WIN32 784#if EV_USE_WIN32
643 if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A); 785 if (method == EVMETHOD_WIN32 ) win32_destroy (EV_A);
644#endif 786#endif
645#if EV_USE_KQUEUE 787#if EV_USE_KQUEUE
646 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); 788 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A);
653#endif 795#endif
654#if EV_USE_SELECT 796#if EV_USE_SELECT
655 if (method == EVMETHOD_SELECT) select_destroy (EV_A); 797 if (method == EVMETHOD_SELECT) select_destroy (EV_A);
656#endif 798#endif
657 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
658 method = 0; 811 method = 0;
659 /*TODO*/
660} 812}
661 813
662void 814static void
663loop_fork (EV_P) 815loop_fork (EV_P)
664{ 816{
665 /*TODO*/
666#if EV_USE_EPOLL 817#if EV_USE_EPOLL
667 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); 818 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A);
668#endif 819#endif
669#if EV_USE_KQUEUE 820#if EV_USE_KQUEUE
670 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); 821 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A);
671#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;
672} 840}
673 841
674#if EV_MULTIPLICITY 842#if EV_MULTIPLICITY
675struct ev_loop * 843struct ev_loop *
676ev_loop_new (int methods) 844ev_loop_new (int methods)
677{ 845{
678 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));
679 849
680 loop_init (EV_A_ methods); 850 loop_init (EV_A_ methods);
681 851
682 if (ev_method (EV_A)) 852 if (ev_method (EV_A))
683 return loop; 853 return loop;
687 857
688void 858void
689ev_loop_destroy (EV_P) 859ev_loop_destroy (EV_P)
690{ 860{
691 loop_destroy (EV_A); 861 loop_destroy (EV_A);
692 free (loop); 862 ev_free (loop);
693} 863}
694 864
695void 865void
696ev_loop_fork (EV_P) 866ev_loop_fork (EV_P)
697{ 867{
698 loop_fork (EV_A); 868 postfork = 1;
699} 869}
700 870
701#endif 871#endif
702 872
703#if EV_MULTIPLICITY 873#if EV_MULTIPLICITY
711int 881int
712#endif 882#endif
713ev_default_loop (int methods) 883ev_default_loop (int methods)
714{ 884{
715 if (sigpipe [0] == sigpipe [1]) 885 if (sigpipe [0] == sigpipe [1])
716 if (pipe (sigpipe)) 886 if (ev_pipe (sigpipe))
717 return 0; 887 return 0;
718 888
719 if (!default_loop) 889 if (!default_loop)
720 { 890 {
721#if EV_MULTIPLICITY 891#if EV_MULTIPLICITY
726 896
727 loop_init (EV_A_ methods); 897 loop_init (EV_A_ methods);
728 898
729 if (ev_method (EV_A)) 899 if (ev_method (EV_A))
730 { 900 {
731 ev_watcher_init (&sigev, sigcb);
732 ev_set_priority (&sigev, EV_MAXPRI);
733 siginit (EV_A); 901 siginit (EV_A);
734 902
735#ifndef WIN32 903#ifndef WIN32
736 ev_signal_init (&childev, childcb, SIGCHLD); 904 ev_signal_init (&childev, childcb, SIGCHLD);
737 ev_set_priority (&childev, EV_MAXPRI); 905 ev_set_priority (&childev, EV_MAXPRI);
751{ 919{
752#if EV_MULTIPLICITY 920#if EV_MULTIPLICITY
753 struct ev_loop *loop = default_loop; 921 struct ev_loop *loop = default_loop;
754#endif 922#endif
755 923
924#ifndef WIN32
756 ev_ref (EV_A); /* child watcher */ 925 ev_ref (EV_A); /* child watcher */
757 ev_signal_stop (EV_A_ &childev); 926 ev_signal_stop (EV_A_ &childev);
927#endif
758 928
759 ev_ref (EV_A); /* signal watcher */ 929 ev_ref (EV_A); /* signal watcher */
760 ev_io_stop (EV_A_ &sigev); 930 ev_io_stop (EV_A_ &sigev);
761 931
762 close (sigpipe [0]); sigpipe [0] = 0; 932 close (sigpipe [0]); sigpipe [0] = 0;
770{ 940{
771#if EV_MULTIPLICITY 941#if EV_MULTIPLICITY
772 struct ev_loop *loop = default_loop; 942 struct ev_loop *loop = default_loop;
773#endif 943#endif
774 944
775 loop_fork (EV_A); 945 if (method)
776 946 postfork = 1;
777 ev_io_stop (EV_A_ &sigev);
778 close (sigpipe [0]);
779 close (sigpipe [1]);
780 pipe (sigpipe);
781
782 ev_ref (EV_A); /* signal watcher */
783 siginit (EV_A);
784} 947}
785 948
786/*****************************************************************************/ 949/*****************************************************************************/
787 950
788static void 951static void
796 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 959 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
797 960
798 if (p->w) 961 if (p->w)
799 { 962 {
800 p->w->pending = 0; 963 p->w->pending = 0;
801
802 (*(void (**)(EV_P_ W, int))&p->w->cb) (EV_A_ p->w, p->events); 964 p->w->cb (EV_A_ p->w, p->events);
803 } 965 }
804 } 966 }
805} 967}
806 968
807static void 969static void
967 { 1129 {
968 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 1130 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
969 call_pending (EV_A); 1131 call_pending (EV_A);
970 } 1132 }
971 1133
1134 /* we might have forked, so reify kernel state if necessary */
1135 if (expect_false (postfork))
1136 loop_fork (EV_A);
1137
972 /* update fd-related kernel structures */ 1138 /* update fd-related kernel structures */
973 fd_reify (EV_A); 1139 fd_reify (EV_A);
974 1140
975 /* calculate blocking time */ 1141 /* calculate blocking time */
976 1142
1130 ((WT)w)->at += mn_now; 1296 ((WT)w)->at += mn_now;
1131 1297
1132 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.));
1133 1299
1134 ev_start (EV_A_ (W)w, ++timercnt); 1300 ev_start (EV_A_ (W)w, ++timercnt);
1135 array_needsize (timers, timermax, timercnt, ); 1301 array_needsize (timers, timermax, timercnt, (void));
1136 timers [timercnt - 1] = w; 1302 timers [timercnt - 1] = w;
1137 upheap ((WT *)timers, timercnt - 1); 1303 upheap ((WT *)timers, timercnt - 1);
1138 1304
1139 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1305 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1140} 1306}
1187 /* 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 */
1188 if (w->interval) 1354 if (w->interval)
1189 ((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;
1190 1356
1191 ev_start (EV_A_ (W)w, ++periodiccnt); 1357 ev_start (EV_A_ (W)w, ++periodiccnt);
1192 array_needsize (periodics, periodicmax, periodiccnt, ); 1358 array_needsize (periodics, periodicmax, periodiccnt, (void));
1193 periodics [periodiccnt - 1] = w; 1359 periodics [periodiccnt - 1] = w;
1194 upheap ((WT *)periodics, periodiccnt - 1); 1360 upheap ((WT *)periodics, periodiccnt - 1);
1195 1361
1196 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1362 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1197} 1363}
1219{ 1385{
1220 if (ev_is_active (w)) 1386 if (ev_is_active (w))
1221 return; 1387 return;
1222 1388
1223 ev_start (EV_A_ (W)w, ++idlecnt); 1389 ev_start (EV_A_ (W)w, ++idlecnt);
1224 array_needsize (idles, idlemax, idlecnt, ); 1390 array_needsize (idles, idlemax, idlecnt, (void));
1225 idles [idlecnt - 1] = w; 1391 idles [idlecnt - 1] = w;
1226} 1392}
1227 1393
1228void 1394void
1229ev_idle_stop (EV_P_ struct ev_idle *w) 1395ev_idle_stop (EV_P_ struct ev_idle *w)
1241{ 1407{
1242 if (ev_is_active (w)) 1408 if (ev_is_active (w))
1243 return; 1409 return;
1244 1410
1245 ev_start (EV_A_ (W)w, ++preparecnt); 1411 ev_start (EV_A_ (W)w, ++preparecnt);
1246 array_needsize (prepares, preparemax, preparecnt, ); 1412 array_needsize (prepares, preparemax, preparecnt, (void));
1247 prepares [preparecnt - 1] = w; 1413 prepares [preparecnt - 1] = w;
1248} 1414}
1249 1415
1250void 1416void
1251ev_prepare_stop (EV_P_ struct ev_prepare *w) 1417ev_prepare_stop (EV_P_ struct ev_prepare *w)
1263{ 1429{
1264 if (ev_is_active (w)) 1430 if (ev_is_active (w))
1265 return; 1431 return;
1266 1432
1267 ev_start (EV_A_ (W)w, ++checkcnt); 1433 ev_start (EV_A_ (W)w, ++checkcnt);
1268 array_needsize (checks, checkmax, checkcnt, ); 1434 array_needsize (checks, checkmax, checkcnt, (void));
1269 checks [checkcnt - 1] = w; 1435 checks [checkcnt - 1] = w;
1270} 1436}
1271 1437
1272void 1438void
1273ev_check_stop (EV_P_ struct ev_check *w) 1439ev_check_stop (EV_P_ struct ev_check *w)
1299 array_needsize (signals, signalmax, w->signum, signals_init); 1465 array_needsize (signals, signalmax, w->signum, signals_init);
1300 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); 1466 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
1301 1467
1302 if (!((WL)w)->next) 1468 if (!((WL)w)->next)
1303 { 1469 {
1470#if WIN32
1471 signal (w->signum, sighandler);
1472#else
1304 struct sigaction sa; 1473 struct sigaction sa;
1305 sa.sa_handler = sighandler; 1474 sa.sa_handler = sighandler;
1306 sigfillset (&sa.sa_mask); 1475 sigfillset (&sa.sa_mask);
1307 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 */
1308 sigaction (w->signum, &sa, 0); 1477 sigaction (w->signum, &sa, 0);
1478#endif
1309 } 1479 }
1310} 1480}
1311 1481
1312void 1482void
1313ev_signal_stop (EV_P_ struct ev_signal *w) 1483ev_signal_stop (EV_P_ struct ev_signal *w)
1363 void (*cb)(int revents, void *arg) = once->cb; 1533 void (*cb)(int revents, void *arg) = once->cb;
1364 void *arg = once->arg; 1534 void *arg = once->arg;
1365 1535
1366 ev_io_stop (EV_A_ &once->io); 1536 ev_io_stop (EV_A_ &once->io);
1367 ev_timer_stop (EV_A_ &once->to); 1537 ev_timer_stop (EV_A_ &once->to);
1368 free (once); 1538 ev_free (once);
1369 1539
1370 cb (revents, arg); 1540 cb (revents, arg);
1371} 1541}
1372 1542
1373static void 1543static void
1383} 1553}
1384 1554
1385void 1555void
1386ev_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)
1387{ 1557{
1388 struct ev_once *once = malloc (sizeof (struct ev_once)); 1558 struct ev_once *once = ev_malloc (sizeof (struct ev_once));
1389 1559
1390 if (!once) 1560 if (!once)
1391 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); 1561 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg);
1392 else 1562 else
1393 { 1563 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines