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

Comparing libev/ev.c (file contents):
Revision 1.67 by root, Mon Nov 5 16:42:15 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
149 152
150#if WIN32 153#if WIN32
151/* note: the comment below could not be substantiated, but what would I care */ 154/* note: the comment below could not be substantiated, but what would I care */
152/* MSDN says this is required to handle SIGFPE */ 155/* MSDN says this is required to handle SIGFPE */
153volatile double SIGFPE_REQ = 0.0f; 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)
154#endif 210#endif
155 211
156/*****************************************************************************/ 212/*****************************************************************************/
157 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
158typedef struct 262typedef struct
159{ 263{
160 struct ev_watcher_list *head; 264 WL head;
161 unsigned char events; 265 unsigned char events;
162 unsigned char reify; 266 unsigned char reify;
163} ANFD; 267} ANFD;
164 268
165typedef struct 269typedef struct
223 return rt_now; 327 return rt_now;
224} 328}
225 329
226#define array_roundsize(base,n) ((n) | 4 & ~3) 330#define array_roundsize(base,n) ((n) | 4 & ~3)
227 331
228#define array_needsize(base,cur,cnt,init) \ 332#define array_needsize(base,cur,cnt,init) \
229 if (expect_false ((cnt) > cur)) \ 333 if (expect_false ((cnt) > cur)) \
230 { \ 334 { \
231 int newcnt = cur; \ 335 int newcnt = cur; \
232 do \ 336 do \
233 { \ 337 { \
234 newcnt = array_roundsize (base, newcnt << 1); \ 338 newcnt = array_roundsize (base, newcnt << 1); \
235 } \ 339 } \
236 while ((cnt) > newcnt); \ 340 while ((cnt) > newcnt); \
237 \ 341 \
238 base = realloc (base, sizeof (*base) * (newcnt)); \ 342 base = ev_realloc (base, sizeof (*base) * (newcnt)); \
239 init (base + cur, newcnt - cur); \ 343 init (base + cur, newcnt - cur); \
240 cur = newcnt; \ 344 cur = newcnt; \
241 } 345 }
242 346
243#define array_slim(stem) \ 347#define array_slim(stem) \
244 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ 348 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \
245 { \ 349 { \
246 stem ## max = array_roundsize (stem ## cnt >> 1); \ 350 stem ## max = array_roundsize (stem ## cnt >> 1); \
247 base = realloc (base, sizeof (*base) * (stem ## max)); \ 351 base = ev_realloc (base, sizeof (*base) * (stem ## max)); \
248 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ 352 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\
249 } 353 }
250 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
251#define array_free(stem, idx) \ 360#define array_free(stem, idx) \
252 free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; 361 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0;
253 362
254/*****************************************************************************/ 363/*****************************************************************************/
255 364
256static void 365static void
257anfds_init (ANFD *base, int count) 366anfds_init (ANFD *base, int count)
274 pendings [ABSPRI (w)][w->pending - 1].events |= events; 383 pendings [ABSPRI (w)][w->pending - 1].events |= events;
275 return; 384 return;
276 } 385 }
277 386
278 w->pending = ++pendingcnt [ABSPRI (w)]; 387 w->pending = ++pendingcnt [ABSPRI (w)];
279 array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], ); 388 array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], (void));
280 pendings [ABSPRI (w)][w->pending - 1].w = w; 389 pendings [ABSPRI (w)][w->pending - 1].w = w;
281 pendings [ABSPRI (w)][w->pending - 1].events = events; 390 pendings [ABSPRI (w)][w->pending - 1].events = events;
282} 391}
283 392
284static void 393static void
333} 442}
334 443
335static void 444static void
336fd_change (EV_P_ int fd) 445fd_change (EV_P_ int fd)
337{ 446{
338 if (anfds [fd].reify || fdchangecnt < 0) 447 if (anfds [fd].reify)
339 return; 448 return;
340 449
341 anfds [fd].reify = 1; 450 anfds [fd].reify = 1;
342 451
343 ++fdchangecnt; 452 ++fdchangecnt;
344 array_needsize (fdchanges, fdchangemax, fdchangecnt, ); 453 array_needsize (fdchanges, fdchangemax, fdchangecnt, (void));
345 fdchanges [fdchangecnt - 1] = fd; 454 fdchanges [fdchangecnt - 1] = fd;
346} 455}
347 456
348static void 457static void
349fd_kill (EV_P_ int fd) 458fd_kill (EV_P_ int fd)
355 ev_io_stop (EV_A_ w); 464 ev_io_stop (EV_A_ w);
356 event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); 465 event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE);
357 } 466 }
358} 467}
359 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
360/* called on EBADF to verify fds */ 479/* called on EBADF to verify fds */
361static void 480static void
362fd_ebadf (EV_P) 481fd_ebadf (EV_P)
363{ 482{
364 int fd; 483 int fd;
365 484
366 for (fd = 0; fd < anfdmax; ++fd) 485 for (fd = 0; fd < anfdmax; ++fd)
367 if (anfds [fd].events) 486 if (anfds [fd].events)
368 if (fcntl (fd, F_GETFD) == -1 && errno == EBADF) 487 if (!fd_valid (fd) == -1 && errno == EBADF)
369 fd_kill (EV_A_ fd); 488 fd_kill (EV_A_ fd);
370} 489}
371 490
372/* 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 */
373static void 492static void
376 int fd; 495 int fd;
377 496
378 for (fd = anfdmax; fd--; ) 497 for (fd = anfdmax; fd--; )
379 if (anfds [fd].events) 498 if (anfds [fd].events)
380 { 499 {
381 close (fd);
382 fd_kill (EV_A_ fd); 500 fd_kill (EV_A_ fd);
383 return; 501 return;
384 } 502 }
385} 503}
386 504
387/* 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 */
388static void 506static void
389fd_rearm_all (EV_P) 507fd_rearm_all (EV_P)
390{ 508{
391 int fd; 509 int fd;
392 510
444 562
445/*****************************************************************************/ 563/*****************************************************************************/
446 564
447typedef struct 565typedef struct
448{ 566{
449 struct ev_watcher_list *head; 567 WL head;
450 sig_atomic_t volatile gotsig; 568 sig_atomic_t volatile gotsig;
451} ANSIG; 569} ANSIG;
452 570
453static ANSIG *signals; 571static ANSIG *signals;
454static int signalmax; 572static int signalmax;
488} 606}
489 607
490static void 608static void
491sigcb (EV_P_ struct ev_io *iow, int revents) 609sigcb (EV_P_ struct ev_io *iow, int revents)
492{ 610{
493 struct ev_watcher_list *w; 611 WL w;
494 int signum; 612 int signum;
495 613
496 read (sigpipe [0], &revents, 1); 614 read (sigpipe [0], &revents, 1);
497 gotsig = 0; 615 gotsig = 0;
498 616
523 ev_unref (EV_A); /* child watcher should not keep loop alive */ 641 ev_unref (EV_A); /* child watcher should not keep loop alive */
524} 642}
525 643
526/*****************************************************************************/ 644/*****************************************************************************/
527 645
646static struct ev_child *childs [PID_HASHSIZE];
647
528#ifndef WIN32 648#ifndef WIN32
529 649
530static struct ev_child *childs [PID_HASHSIZE];
531static struct ev_signal childev; 650static struct ev_signal childev;
532 651
533#ifndef WCONTINUED 652#ifndef WCONTINUED
534# define WCONTINUED 0 653# define WCONTINUED 0
535#endif 654#endif
649 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); 768 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods);
650#endif 769#endif
651#if EV_USE_SELECT 770#if EV_USE_SELECT
652 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); 771 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods);
653#endif 772#endif
773
774 ev_watcher_init (&sigev, sigcb);
775 ev_set_priority (&sigev, EV_MAXPRI);
654 } 776 }
655} 777}
656 778
657void 779void
658loop_destroy (EV_P) 780loop_destroy (EV_P)
676#endif 798#endif
677 799
678 for (i = NUMPRI; i--; ) 800 for (i = NUMPRI; i--; )
679 array_free (pending, [i]); 801 array_free (pending, [i]);
680 802
803 /* have to use the microsoft-never-gets-it-right macro */
681 array_free (fdchange, ); 804 array_free_microshit (fdchange);
682 array_free (timer, ); 805 array_free_microshit (timer);
683 array_free (periodic, ); 806 array_free_microshit (periodic);
684 array_free (idle, ); 807 array_free_microshit (idle);
685 array_free (prepare, ); 808 array_free_microshit (prepare);
686 array_free (check, ); 809 array_free_microshit (check);
687 810
688 method = 0; 811 method = 0;
689 /*TODO*/
690} 812}
691 813
692void 814static void
693loop_fork (EV_P) 815loop_fork (EV_P)
694{ 816{
695 /*TODO*/
696#if EV_USE_EPOLL 817#if EV_USE_EPOLL
697 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); 818 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A);
698#endif 819#endif
699#if EV_USE_KQUEUE 820#if EV_USE_KQUEUE
700 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); 821 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A);
701#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;
702} 840}
703 841
704#if EV_MULTIPLICITY 842#if EV_MULTIPLICITY
705struct ev_loop * 843struct ev_loop *
706ev_loop_new (int methods) 844ev_loop_new (int methods)
707{ 845{
708 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));
709 849
710 loop_init (EV_A_ methods); 850 loop_init (EV_A_ methods);
711 851
712 if (ev_method (EV_A)) 852 if (ev_method (EV_A))
713 return loop; 853 return loop;
717 857
718void 858void
719ev_loop_destroy (EV_P) 859ev_loop_destroy (EV_P)
720{ 860{
721 loop_destroy (EV_A); 861 loop_destroy (EV_A);
722 free (loop); 862 ev_free (loop);
723} 863}
724 864
725void 865void
726ev_loop_fork (EV_P) 866ev_loop_fork (EV_P)
727{ 867{
728 loop_fork (EV_A); 868 postfork = 1;
729} 869}
730 870
731#endif 871#endif
732 872
733#if EV_MULTIPLICITY 873#if EV_MULTIPLICITY
741int 881int
742#endif 882#endif
743ev_default_loop (int methods) 883ev_default_loop (int methods)
744{ 884{
745 if (sigpipe [0] == sigpipe [1]) 885 if (sigpipe [0] == sigpipe [1])
746 if (pipe (sigpipe)) 886 if (ev_pipe (sigpipe))
747 return 0; 887 return 0;
748 888
749 if (!default_loop) 889 if (!default_loop)
750 { 890 {
751#if EV_MULTIPLICITY 891#if EV_MULTIPLICITY
756 896
757 loop_init (EV_A_ methods); 897 loop_init (EV_A_ methods);
758 898
759 if (ev_method (EV_A)) 899 if (ev_method (EV_A))
760 { 900 {
761 ev_watcher_init (&sigev, sigcb);
762 ev_set_priority (&sigev, EV_MAXPRI);
763 siginit (EV_A); 901 siginit (EV_A);
764 902
765#ifndef WIN32 903#ifndef WIN32
766 ev_signal_init (&childev, childcb, SIGCHLD); 904 ev_signal_init (&childev, childcb, SIGCHLD);
767 ev_set_priority (&childev, EV_MAXPRI); 905 ev_set_priority (&childev, EV_MAXPRI);
781{ 919{
782#if EV_MULTIPLICITY 920#if EV_MULTIPLICITY
783 struct ev_loop *loop = default_loop; 921 struct ev_loop *loop = default_loop;
784#endif 922#endif
785 923
924#ifndef WIN32
786 ev_ref (EV_A); /* child watcher */ 925 ev_ref (EV_A); /* child watcher */
787 ev_signal_stop (EV_A_ &childev); 926 ev_signal_stop (EV_A_ &childev);
927#endif
788 928
789 ev_ref (EV_A); /* signal watcher */ 929 ev_ref (EV_A); /* signal watcher */
790 ev_io_stop (EV_A_ &sigev); 930 ev_io_stop (EV_A_ &sigev);
791 931
792 close (sigpipe [0]); sigpipe [0] = 0; 932 close (sigpipe [0]); sigpipe [0] = 0;
800{ 940{
801#if EV_MULTIPLICITY 941#if EV_MULTIPLICITY
802 struct ev_loop *loop = default_loop; 942 struct ev_loop *loop = default_loop;
803#endif 943#endif
804 944
805 loop_fork (EV_A); 945 if (method)
806 946 postfork = 1;
807 ev_io_stop (EV_A_ &sigev);
808 close (sigpipe [0]);
809 close (sigpipe [1]);
810 pipe (sigpipe);
811
812 ev_ref (EV_A); /* signal watcher */
813 siginit (EV_A);
814} 947}
815 948
816/*****************************************************************************/ 949/*****************************************************************************/
817 950
818static void 951static void
996 { 1129 {
997 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 1130 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
998 call_pending (EV_A); 1131 call_pending (EV_A);
999 } 1132 }
1000 1133
1134 /* we might have forked, so reify kernel state if necessary */
1135 if (expect_false (postfork))
1136 loop_fork (EV_A);
1137
1001 /* update fd-related kernel structures */ 1138 /* update fd-related kernel structures */
1002 fd_reify (EV_A); 1139 fd_reify (EV_A);
1003 1140
1004 /* calculate blocking time */ 1141 /* calculate blocking time */
1005 1142
1159 ((WT)w)->at += mn_now; 1296 ((WT)w)->at += mn_now;
1160 1297
1161 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.));
1162 1299
1163 ev_start (EV_A_ (W)w, ++timercnt); 1300 ev_start (EV_A_ (W)w, ++timercnt);
1164 array_needsize (timers, timermax, timercnt, ); 1301 array_needsize (timers, timermax, timercnt, (void));
1165 timers [timercnt - 1] = w; 1302 timers [timercnt - 1] = w;
1166 upheap ((WT *)timers, timercnt - 1); 1303 upheap ((WT *)timers, timercnt - 1);
1167 1304
1168 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1305 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1169} 1306}
1216 /* 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 */
1217 if (w->interval) 1354 if (w->interval)
1218 ((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;
1219 1356
1220 ev_start (EV_A_ (W)w, ++periodiccnt); 1357 ev_start (EV_A_ (W)w, ++periodiccnt);
1221 array_needsize (periodics, periodicmax, periodiccnt, ); 1358 array_needsize (periodics, periodicmax, periodiccnt, (void));
1222 periodics [periodiccnt - 1] = w; 1359 periodics [periodiccnt - 1] = w;
1223 upheap ((WT *)periodics, periodiccnt - 1); 1360 upheap ((WT *)periodics, periodiccnt - 1);
1224 1361
1225 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1362 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1226} 1363}
1248{ 1385{
1249 if (ev_is_active (w)) 1386 if (ev_is_active (w))
1250 return; 1387 return;
1251 1388
1252 ev_start (EV_A_ (W)w, ++idlecnt); 1389 ev_start (EV_A_ (W)w, ++idlecnt);
1253 array_needsize (idles, idlemax, idlecnt, ); 1390 array_needsize (idles, idlemax, idlecnt, (void));
1254 idles [idlecnt - 1] = w; 1391 idles [idlecnt - 1] = w;
1255} 1392}
1256 1393
1257void 1394void
1258ev_idle_stop (EV_P_ struct ev_idle *w) 1395ev_idle_stop (EV_P_ struct ev_idle *w)
1270{ 1407{
1271 if (ev_is_active (w)) 1408 if (ev_is_active (w))
1272 return; 1409 return;
1273 1410
1274 ev_start (EV_A_ (W)w, ++preparecnt); 1411 ev_start (EV_A_ (W)w, ++preparecnt);
1275 array_needsize (prepares, preparemax, preparecnt, ); 1412 array_needsize (prepares, preparemax, preparecnt, (void));
1276 prepares [preparecnt - 1] = w; 1413 prepares [preparecnt - 1] = w;
1277} 1414}
1278 1415
1279void 1416void
1280ev_prepare_stop (EV_P_ struct ev_prepare *w) 1417ev_prepare_stop (EV_P_ struct ev_prepare *w)
1292{ 1429{
1293 if (ev_is_active (w)) 1430 if (ev_is_active (w))
1294 return; 1431 return;
1295 1432
1296 ev_start (EV_A_ (W)w, ++checkcnt); 1433 ev_start (EV_A_ (W)w, ++checkcnt);
1297 array_needsize (checks, checkmax, checkcnt, ); 1434 array_needsize (checks, checkmax, checkcnt, (void));
1298 checks [checkcnt - 1] = w; 1435 checks [checkcnt - 1] = w;
1299} 1436}
1300 1437
1301void 1438void
1302ev_check_stop (EV_P_ struct ev_check *w) 1439ev_check_stop (EV_P_ struct ev_check *w)
1396 void (*cb)(int revents, void *arg) = once->cb; 1533 void (*cb)(int revents, void *arg) = once->cb;
1397 void *arg = once->arg; 1534 void *arg = once->arg;
1398 1535
1399 ev_io_stop (EV_A_ &once->io); 1536 ev_io_stop (EV_A_ &once->io);
1400 ev_timer_stop (EV_A_ &once->to); 1537 ev_timer_stop (EV_A_ &once->to);
1401 free (once); 1538 ev_free (once);
1402 1539
1403 cb (revents, arg); 1540 cb (revents, arg);
1404} 1541}
1405 1542
1406static void 1543static void
1416} 1553}
1417 1554
1418void 1555void
1419ev_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)
1420{ 1557{
1421 struct ev_once *once = malloc (sizeof (struct ev_once)); 1558 struct ev_once *once = ev_malloc (sizeof (struct ev_once));
1422 1559
1423 if (!once) 1560 if (!once)
1424 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); 1561 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg);
1425 else 1562 else
1426 { 1563 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines