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

Comparing libev/ev.c (file contents):
Revision 1.66 by root, Sun Nov 4 23:30:53 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;
236 359
237#define array_free(stem, idx) \ 360#define array_free(stem, idx) \
238 free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; 361 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0;
239 362
240/*****************************************************************************/ 363/*****************************************************************************/
241 364
242static void 365static void
243anfds_init (ANFD *base, int count) 366anfds_init (ANFD *base, int count)
260 pendings [ABSPRI (w)][w->pending - 1].events |= events; 383 pendings [ABSPRI (w)][w->pending - 1].events |= events;
261 return; 384 return;
262 } 385 }
263 386
264 w->pending = ++pendingcnt [ABSPRI (w)]; 387 w->pending = ++pendingcnt [ABSPRI (w)];
265 array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], ); 388 array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], (void));
266 pendings [ABSPRI (w)][w->pending - 1].w = w; 389 pendings [ABSPRI (w)][w->pending - 1].w = w;
267 pendings [ABSPRI (w)][w->pending - 1].events = events; 390 pendings [ABSPRI (w)][w->pending - 1].events = events;
268} 391}
269 392
270static void 393static void
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)
658#endif 798#endif
659 799
660 for (i = NUMPRI; i--; ) 800 for (i = NUMPRI; i--; )
661 array_free (pending, [i]); 801 array_free (pending, [i]);
662 802
803 /* have to use the microsoft-never-gets-it-right macro */
663 array_free (fdchange, ); 804 array_free_microshit (fdchange);
664 array_free (timer, ); 805 array_free_microshit (timer);
665 array_free (periodic, ); 806 array_free_microshit (periodic);
666 array_free (idle, ); 807 array_free_microshit (idle);
667 array_free (prepare, ); 808 array_free_microshit (prepare);
668 array_free (check, ); 809 array_free_microshit (check);
669 810
670 method = 0; 811 method = 0;
671 /*TODO*/
672} 812}
673 813
674void 814static void
675loop_fork (EV_P) 815loop_fork (EV_P)
676{ 816{
677 /*TODO*/
678#if EV_USE_EPOLL 817#if EV_USE_EPOLL
679 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); 818 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A);
680#endif 819#endif
681#if EV_USE_KQUEUE 820#if EV_USE_KQUEUE
682 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); 821 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A);
683#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;
684} 840}
685 841
686#if EV_MULTIPLICITY 842#if EV_MULTIPLICITY
687struct ev_loop * 843struct ev_loop *
688ev_loop_new (int methods) 844ev_loop_new (int methods)
689{ 845{
690 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));
691 849
692 loop_init (EV_A_ methods); 850 loop_init (EV_A_ methods);
693 851
694 if (ev_method (EV_A)) 852 if (ev_method (EV_A))
695 return loop; 853 return loop;
699 857
700void 858void
701ev_loop_destroy (EV_P) 859ev_loop_destroy (EV_P)
702{ 860{
703 loop_destroy (EV_A); 861 loop_destroy (EV_A);
704 free (loop); 862 ev_free (loop);
705} 863}
706 864
707void 865void
708ev_loop_fork (EV_P) 866ev_loop_fork (EV_P)
709{ 867{
710 loop_fork (EV_A); 868 postfork = 1;
711} 869}
712 870
713#endif 871#endif
714 872
715#if EV_MULTIPLICITY 873#if EV_MULTIPLICITY
723int 881int
724#endif 882#endif
725ev_default_loop (int methods) 883ev_default_loop (int methods)
726{ 884{
727 if (sigpipe [0] == sigpipe [1]) 885 if (sigpipe [0] == sigpipe [1])
728 if (pipe (sigpipe)) 886 if (ev_pipe (sigpipe))
729 return 0; 887 return 0;
730 888
731 if (!default_loop) 889 if (!default_loop)
732 { 890 {
733#if EV_MULTIPLICITY 891#if EV_MULTIPLICITY
738 896
739 loop_init (EV_A_ methods); 897 loop_init (EV_A_ methods);
740 898
741 if (ev_method (EV_A)) 899 if (ev_method (EV_A))
742 { 900 {
743 ev_watcher_init (&sigev, sigcb);
744 ev_set_priority (&sigev, EV_MAXPRI);
745 siginit (EV_A); 901 siginit (EV_A);
746 902
747#ifndef WIN32 903#ifndef WIN32
748 ev_signal_init (&childev, childcb, SIGCHLD); 904 ev_signal_init (&childev, childcb, SIGCHLD);
749 ev_set_priority (&childev, EV_MAXPRI); 905 ev_set_priority (&childev, EV_MAXPRI);
763{ 919{
764#if EV_MULTIPLICITY 920#if EV_MULTIPLICITY
765 struct ev_loop *loop = default_loop; 921 struct ev_loop *loop = default_loop;
766#endif 922#endif
767 923
924#ifndef WIN32
768 ev_ref (EV_A); /* child watcher */ 925 ev_ref (EV_A); /* child watcher */
769 ev_signal_stop (EV_A_ &childev); 926 ev_signal_stop (EV_A_ &childev);
927#endif
770 928
771 ev_ref (EV_A); /* signal watcher */ 929 ev_ref (EV_A); /* signal watcher */
772 ev_io_stop (EV_A_ &sigev); 930 ev_io_stop (EV_A_ &sigev);
773 931
774 close (sigpipe [0]); sigpipe [0] = 0; 932 close (sigpipe [0]); sigpipe [0] = 0;
782{ 940{
783#if EV_MULTIPLICITY 941#if EV_MULTIPLICITY
784 struct ev_loop *loop = default_loop; 942 struct ev_loop *loop = default_loop;
785#endif 943#endif
786 944
787 loop_fork (EV_A); 945 if (method)
788 946 postfork = 1;
789 ev_io_stop (EV_A_ &sigev);
790 close (sigpipe [0]);
791 close (sigpipe [1]);
792 pipe (sigpipe);
793
794 ev_ref (EV_A); /* signal watcher */
795 siginit (EV_A);
796} 947}
797 948
798/*****************************************************************************/ 949/*****************************************************************************/
799 950
800static void 951static void
978 { 1129 {
979 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 1130 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
980 call_pending (EV_A); 1131 call_pending (EV_A);
981 } 1132 }
982 1133
1134 /* we might have forked, so reify kernel state if necessary */
1135 if (expect_false (postfork))
1136 loop_fork (EV_A);
1137
983 /* update fd-related kernel structures */ 1138 /* update fd-related kernel structures */
984 fd_reify (EV_A); 1139 fd_reify (EV_A);
985 1140
986 /* calculate blocking time */ 1141 /* calculate blocking time */
987 1142
1141 ((WT)w)->at += mn_now; 1296 ((WT)w)->at += mn_now;
1142 1297
1143 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.));
1144 1299
1145 ev_start (EV_A_ (W)w, ++timercnt); 1300 ev_start (EV_A_ (W)w, ++timercnt);
1146 array_needsize (timers, timermax, timercnt, ); 1301 array_needsize (timers, timermax, timercnt, (void));
1147 timers [timercnt - 1] = w; 1302 timers [timercnt - 1] = w;
1148 upheap ((WT *)timers, timercnt - 1); 1303 upheap ((WT *)timers, timercnt - 1);
1149 1304
1150 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1305 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1151} 1306}
1198 /* 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 */
1199 if (w->interval) 1354 if (w->interval)
1200 ((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;
1201 1356
1202 ev_start (EV_A_ (W)w, ++periodiccnt); 1357 ev_start (EV_A_ (W)w, ++periodiccnt);
1203 array_needsize (periodics, periodicmax, periodiccnt, ); 1358 array_needsize (periodics, periodicmax, periodiccnt, (void));
1204 periodics [periodiccnt - 1] = w; 1359 periodics [periodiccnt - 1] = w;
1205 upheap ((WT *)periodics, periodiccnt - 1); 1360 upheap ((WT *)periodics, periodiccnt - 1);
1206 1361
1207 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1362 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1208} 1363}
1230{ 1385{
1231 if (ev_is_active (w)) 1386 if (ev_is_active (w))
1232 return; 1387 return;
1233 1388
1234 ev_start (EV_A_ (W)w, ++idlecnt); 1389 ev_start (EV_A_ (W)w, ++idlecnt);
1235 array_needsize (idles, idlemax, idlecnt, ); 1390 array_needsize (idles, idlemax, idlecnt, (void));
1236 idles [idlecnt - 1] = w; 1391 idles [idlecnt - 1] = w;
1237} 1392}
1238 1393
1239void 1394void
1240ev_idle_stop (EV_P_ struct ev_idle *w) 1395ev_idle_stop (EV_P_ struct ev_idle *w)
1252{ 1407{
1253 if (ev_is_active (w)) 1408 if (ev_is_active (w))
1254 return; 1409 return;
1255 1410
1256 ev_start (EV_A_ (W)w, ++preparecnt); 1411 ev_start (EV_A_ (W)w, ++preparecnt);
1257 array_needsize (prepares, preparemax, preparecnt, ); 1412 array_needsize (prepares, preparemax, preparecnt, (void));
1258 prepares [preparecnt - 1] = w; 1413 prepares [preparecnt - 1] = w;
1259} 1414}
1260 1415
1261void 1416void
1262ev_prepare_stop (EV_P_ struct ev_prepare *w) 1417ev_prepare_stop (EV_P_ struct ev_prepare *w)
1274{ 1429{
1275 if (ev_is_active (w)) 1430 if (ev_is_active (w))
1276 return; 1431 return;
1277 1432
1278 ev_start (EV_A_ (W)w, ++checkcnt); 1433 ev_start (EV_A_ (W)w, ++checkcnt);
1279 array_needsize (checks, checkmax, checkcnt, ); 1434 array_needsize (checks, checkmax, checkcnt, (void));
1280 checks [checkcnt - 1] = w; 1435 checks [checkcnt - 1] = w;
1281} 1436}
1282 1437
1283void 1438void
1284ev_check_stop (EV_P_ struct ev_check *w) 1439ev_check_stop (EV_P_ struct ev_check *w)
1310 array_needsize (signals, signalmax, w->signum, signals_init); 1465 array_needsize (signals, signalmax, w->signum, signals_init);
1311 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); 1466 wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w);
1312 1467
1313 if (!((WL)w)->next) 1468 if (!((WL)w)->next)
1314 { 1469 {
1470#if WIN32
1471 signal (w->signum, sighandler);
1472#else
1315 struct sigaction sa; 1473 struct sigaction sa;
1316 sa.sa_handler = sighandler; 1474 sa.sa_handler = sighandler;
1317 sigfillset (&sa.sa_mask); 1475 sigfillset (&sa.sa_mask);
1318 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 */
1319 sigaction (w->signum, &sa, 0); 1477 sigaction (w->signum, &sa, 0);
1478#endif
1320 } 1479 }
1321} 1480}
1322 1481
1323void 1482void
1324ev_signal_stop (EV_P_ struct ev_signal *w) 1483ev_signal_stop (EV_P_ struct ev_signal *w)
1374 void (*cb)(int revents, void *arg) = once->cb; 1533 void (*cb)(int revents, void *arg) = once->cb;
1375 void *arg = once->arg; 1534 void *arg = once->arg;
1376 1535
1377 ev_io_stop (EV_A_ &once->io); 1536 ev_io_stop (EV_A_ &once->io);
1378 ev_timer_stop (EV_A_ &once->to); 1537 ev_timer_stop (EV_A_ &once->to);
1379 free (once); 1538 ev_free (once);
1380 1539
1381 cb (revents, arg); 1540 cb (revents, arg);
1382} 1541}
1383 1542
1384static void 1543static void
1394} 1553}
1395 1554
1396void 1555void
1397ev_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)
1398{ 1557{
1399 struct ev_once *once = malloc (sizeof (struct ev_once)); 1558 struct ev_once *once = ev_malloc (sizeof (struct ev_once));
1400 1559
1401 if (!once) 1560 if (!once)
1402 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); 1561 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg);
1403 else 1562 else
1404 { 1563 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines