… | |
… | |
6 | #undef signal |
6 | #undef signal |
7 | #undef sigaction |
7 | #undef sigaction |
8 | |
8 | |
9 | #include "schmorp.h" |
9 | #include "schmorp.h" |
10 | |
10 | |
|
|
11 | /* old API compatibility */ |
|
|
12 | static int |
|
|
13 | sv_fileno (SV *fh) |
|
|
14 | { |
|
|
15 | return s_fileno (fh, 0); |
|
|
16 | } |
|
|
17 | |
|
|
18 | #define EV_STANDALONE 1 |
11 | #define EV_PROTOTYPES 1 |
19 | #define EV_PROTOTYPES 1 |
12 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
20 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
13 | #define EV_H <ev.h> |
21 | #define EV_H <ev.h> |
|
|
22 | #define EV_CONFIG_H error |
14 | #include "EV/EVAPI.h" |
23 | #include "EV/EVAPI.h" |
15 | |
24 | |
16 | #define EV_SELECT_IS_WINSOCKET 0 |
25 | #define EV_SELECT_IS_WINSOCKET 0 |
17 | #ifdef _WIN32 |
26 | #ifdef _WIN32 |
18 | # define EV_SELECT_USE_FD_SET 0 |
27 | # define EV_SELECT_USE_FD_SET 0 |
… | |
… | |
57 | REF (w); \ |
66 | REF (w); \ |
58 | ev_ ## type ## _stop (e_loop (w), w); \ |
67 | ev_ ## type ## _stop (e_loop (w), w); \ |
59 | } while (0) |
68 | } while (0) |
60 | |
69 | |
61 | #define RESET(type,w,seta) \ |
70 | #define RESET(type,w,seta) \ |
62 | do { \ |
71 | do { \ |
63 | int active = ev_is_active (w); \ |
72 | int active = ev_is_active (w); \ |
64 | if (active) STOP (type, w); \ |
73 | if (active) STOP (type, w); \ |
65 | ev_ ## type ## _set seta; \ |
74 | ev_ ## type ## _set seta; \ |
66 | if (active) START (type, w); \ |
75 | if (active) START (type, w); \ |
67 | } while (0) |
76 | } while (0) |
68 | |
77 | |
69 | typedef int Signal; |
78 | typedef int Signal; |
|
|
79 | |
|
|
80 | /* horrible... */ |
|
|
81 | #define CHECK_SIGNAL_CAN_START(w) \ |
|
|
82 | do { \ |
|
|
83 | /* dive into the internals of libev to avoid aborting in libev */ \ |
|
|
84 | if (signals [(w)->signum - 1].loop \ |
|
|
85 | && signals [(w)->signum - 1].loop != e_loop (w)) \ |
|
|
86 | croak ("unable to start signal watcher, signal %d already registered in another loop", w->signum); \ |
|
|
87 | } while (0) |
|
|
88 | |
|
|
89 | #define START_SIGNAL(w) \ |
|
|
90 | do { \ |
|
|
91 | CHECK_SIGNAL_CAN_START (w); \ |
|
|
92 | START (signal, w); \ |
|
|
93 | } while (0) \ |
|
|
94 | |
|
|
95 | #define RESET_SIGNAL(w,seta) \ |
|
|
96 | do { \ |
|
|
97 | int active = ev_is_active (w); \ |
|
|
98 | if (active) STOP (signal, w); \ |
|
|
99 | ev_ ## signal ## _set seta; \ |
|
|
100 | if (active) START_SIGNAL (w); \ |
|
|
101 | } while (0) |
70 | |
102 | |
71 | static SV *default_loop_sv; |
103 | static SV *default_loop_sv; |
72 | |
104 | |
73 | static struct EVAPI evapi; |
105 | static struct EVAPI evapi; |
74 | |
106 | |
… | |
… | |
328 | const_iv (EV_, UNDEF) |
360 | const_iv (EV_, UNDEF) |
329 | const_iv (EV_, NONE) |
361 | const_iv (EV_, NONE) |
330 | const_iv (EV_, READ) |
362 | const_iv (EV_, READ) |
331 | const_iv (EV_, WRITE) |
363 | const_iv (EV_, WRITE) |
332 | const_iv (EV_, IO) |
364 | const_iv (EV_, IO) |
333 | const_iv (EV_, TIMEOUT) |
365 | const_iv (EV_, TIMEOUT) /* deprecated */ |
334 | const_iv (EV_, TIMER) |
366 | const_iv (EV_, TIMER) |
335 | const_iv (EV_, PERIODIC) |
367 | const_iv (EV_, PERIODIC) |
336 | const_iv (EV_, SIGNAL) |
368 | const_iv (EV_, SIGNAL) |
337 | const_iv (EV_, CHILD) |
369 | const_iv (EV_, CHILD) |
338 | const_iv (EV_, STAT) |
370 | const_iv (EV_, STAT) |
… | |
… | |
356 | const_iv (EV, BACKEND_POLL) |
388 | const_iv (EV, BACKEND_POLL) |
357 | const_iv (EV, BACKEND_EPOLL) |
389 | const_iv (EV, BACKEND_EPOLL) |
358 | const_iv (EV, BACKEND_KQUEUE) |
390 | const_iv (EV, BACKEND_KQUEUE) |
359 | const_iv (EV, BACKEND_DEVPOLL) |
391 | const_iv (EV, BACKEND_DEVPOLL) |
360 | const_iv (EV, BACKEND_PORT) |
392 | const_iv (EV, BACKEND_PORT) |
|
|
393 | const_iv (EV, BACKEND_ALL) |
361 | const_iv (EV, FLAG_AUTO) |
394 | const_iv (EV, FLAG_AUTO) |
|
|
395 | const_iv (EV, FLAG_FORKCHECK) |
|
|
396 | const_iv (EV, FLAG_SIGNALFD) |
362 | const_iv (EV, FLAG_NOENV) |
397 | const_iv (EV, FLAG_NOENV) |
|
|
398 | const_iv (EV, FLAG_NOSIGFD) /* compatibility, always 0 */ |
363 | const_iv (EV, FLAG_FORKCHECK) |
399 | const_iv (EV, FLAG_NOINOTIFY) |
364 | |
400 | |
365 | const_iv (EV_, VERSION_MAJOR) |
401 | const_iv (EV_, VERSION_MAJOR) |
366 | const_iv (EV_, VERSION_MINOR) |
402 | const_iv (EV_, VERSION_MINOR) |
367 | }; |
403 | }; |
368 | |
404 | |
… | |
… | |
389 | perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ |
425 | perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ |
390 | |
426 | |
391 | /* the poor man's shared library emulator */ |
427 | /* the poor man's shared library emulator */ |
392 | evapi.ver = EV_API_VERSION; |
428 | evapi.ver = EV_API_VERSION; |
393 | evapi.rev = EV_API_REVISION; |
429 | evapi.rev = EV_API_REVISION; |
394 | evapi.sv_fileno = s_fileno; |
430 | evapi.sv_fileno = sv_fileno; |
395 | evapi.sv_signum = s_signum; |
431 | evapi.sv_signum = s_signum; |
396 | evapi.supported_backends = ev_supported_backends (); |
432 | evapi.supported_backends = ev_supported_backends (); |
397 | evapi.recommended_backends = ev_recommended_backends (); |
433 | evapi.recommended_backends = ev_recommended_backends (); |
398 | evapi.embeddable_backends = ev_embeddable_backends (); |
434 | evapi.embeddable_backends = ev_embeddable_backends (); |
399 | evapi.time_ = ev_time; |
435 | evapi.time_ = ev_time; |
400 | evapi.sleep_ = ev_sleep; |
436 | evapi.sleep_ = ev_sleep; |
401 | evapi.loop_new = ev_loop_new; |
437 | evapi.loop_new = ev_loop_new; |
402 | evapi.loop_destroy = ev_loop_destroy; |
438 | evapi.loop_destroy = ev_loop_destroy; |
403 | evapi.loop_fork = ev_loop_fork; |
439 | evapi.loop_fork = ev_loop_fork; |
404 | evapi.loop_count = ev_loop_count; |
440 | evapi.iteration = ev_iteration; |
405 | evapi.loop_depth = ev_loop_depth; |
441 | evapi.depth = ev_depth; |
406 | evapi.set_userdata = ev_set_userdata; |
442 | evapi.set_userdata = ev_set_userdata; |
407 | evapi.userdata = ev_userdata; |
443 | evapi.userdata = ev_userdata; |
408 | evapi.now = ev_now; |
444 | evapi.now = ev_now; |
409 | evapi.now_update = ev_now_update; |
445 | evapi.now_update = ev_now_update; |
410 | evapi.suspend = ev_suspend; |
446 | evapi.suspend = ev_suspend; |
411 | evapi.resume = ev_resume; |
447 | evapi.resume = ev_resume; |
412 | evapi.backend = ev_backend; |
448 | evapi.backend = ev_backend; |
413 | evapi.unloop = ev_unloop; |
449 | evapi.unloop = ev_unloop; |
414 | evapi.invoke_pending = ev_invoke_pending; |
450 | evapi.invoke_pending = ev_invoke_pending; |
|
|
451 | evapi.pending_count = ev_pending_count; |
|
|
452 | evapi.verify = ev_verify; |
415 | evapi.set_loop_release_cb = ev_set_loop_release_cb; |
453 | evapi.set_loop_release_cb = ev_set_loop_release_cb; |
416 | evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb; |
454 | evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb; |
417 | evapi.ref = ev_ref; |
455 | evapi.ref = ev_ref; |
418 | evapi.unref = ev_unref; |
456 | evapi.unref = ev_unref; |
419 | evapi.loop = ev_loop; |
457 | evapi.loop = ev_loop; |
… | |
… | |
421 | evapi.io_start = ev_io_start; |
459 | evapi.io_start = ev_io_start; |
422 | evapi.io_stop = ev_io_stop; |
460 | evapi.io_stop = ev_io_stop; |
423 | evapi.timer_start = ev_timer_start; |
461 | evapi.timer_start = ev_timer_start; |
424 | evapi.timer_stop = ev_timer_stop; |
462 | evapi.timer_stop = ev_timer_stop; |
425 | evapi.timer_again = ev_timer_again; |
463 | evapi.timer_again = ev_timer_again; |
|
|
464 | evapi.timer_remaining = ev_timer_remaining; |
426 | evapi.periodic_start = ev_periodic_start; |
465 | evapi.periodic_start = ev_periodic_start; |
427 | evapi.periodic_stop = ev_periodic_stop; |
466 | evapi.periodic_stop = ev_periodic_stop; |
428 | evapi.signal_start = ev_signal_start; |
467 | evapi.signal_start = ev_signal_start; |
429 | evapi.signal_stop = ev_signal_stop; |
468 | evapi.signal_stop = ev_signal_stop; |
430 | evapi.idle_start = ev_idle_start; |
469 | evapi.idle_start = ev_idle_start; |
… | |
… | |
504 | C_ARGS: evapi.default_loop |
543 | C_ARGS: evapi.default_loop |
505 | |
544 | |
506 | unsigned int ev_backend () |
545 | unsigned int ev_backend () |
507 | C_ARGS: evapi.default_loop |
546 | C_ARGS: evapi.default_loop |
508 | |
547 | |
509 | void ev_loop_verify () |
548 | void ev_verify () |
510 | C_ARGS: evapi.default_loop |
549 | C_ARGS: evapi.default_loop |
511 | |
550 | |
512 | unsigned int ev_loop_count () |
551 | unsigned int ev_iteration () |
513 | C_ARGS: evapi.default_loop |
552 | C_ARGS: evapi.default_loop |
514 | |
553 | |
515 | unsigned int ev_loop_depth () |
554 | unsigned int ev_depth () |
516 | C_ARGS: evapi.default_loop |
555 | C_ARGS: evapi.default_loop |
517 | |
556 | |
518 | void ev_set_io_collect_interval (NV interval) |
557 | void ev_set_io_collect_interval (NV interval) |
519 | C_ARGS: evapi.default_loop, interval |
558 | C_ARGS: evapi.default_loop, interval |
520 | |
559 | |
… | |
… | |
537 | CHECK_SIG (signal, signum); |
576 | CHECK_SIG (signal, signum); |
538 | |
577 | |
539 | ev_feed_signal_event (evapi.default_loop, signum); |
578 | ev_feed_signal_event (evapi.default_loop, signum); |
540 | } |
579 | } |
541 | |
580 | |
|
|
581 | unsigned int ev_pending_count () |
|
|
582 | C_ARGS: evapi.default_loop |
|
|
583 | |
|
|
584 | void ev_invoke_pending () |
|
|
585 | C_ARGS: evapi.default_loop |
|
|
586 | |
542 | ev_io *io (SV *fh, int events, SV *cb) |
587 | ev_io *io (SV *fh, int events, SV *cb) |
543 | ALIAS: |
588 | ALIAS: |
544 | io_ns = 1 |
589 | io_ns = 1 |
|
|
590 | _ae_io = 2 |
545 | CODE: |
591 | CODE: |
546 | { |
592 | { |
547 | int fd = s_fileno (fh, events & EV_WRITE); |
593 | int fd = s_fileno (fh, events & EV_WRITE); |
548 | CHECK_FD (fh, fd); |
594 | CHECK_FD (fh, fd); |
|
|
595 | |
|
|
596 | if (ix == 2) |
|
|
597 | { |
|
|
598 | ix = 0; |
|
|
599 | events = events ? EV_WRITE : EV_READ; |
|
|
600 | } |
549 | |
601 | |
550 | RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); |
602 | RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); |
551 | RETVAL->fh = newSVsv (fh); |
603 | RETVAL->fh = newSVsv (fh); |
552 | ev_io_set (RETVAL, fd, events); |
604 | ev_io_set (RETVAL, fd, events); |
553 | if (!ix) START (io, RETVAL); |
605 | if (!ix) START (io, RETVAL); |
… | |
… | |
592 | Signal signum = s_signum (signal); |
644 | Signal signum = s_signum (signal); |
593 | CHECK_SIG (signal, signum); |
645 | CHECK_SIG (signal, signum); |
594 | |
646 | |
595 | RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv); |
647 | RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv); |
596 | ev_signal_set (RETVAL, signum); |
648 | ev_signal_set (RETVAL, signum); |
597 | if (!ix) START (signal, RETVAL); |
649 | if (!ix) START_SIGNAL (RETVAL); |
598 | } |
650 | } |
599 | OUTPUT: |
651 | OUTPUT: |
600 | RETVAL |
652 | RETVAL |
601 | |
653 | |
602 | ev_idle *idle (SV *cb) |
654 | ev_idle *idle (SV *cb) |
… | |
… | |
853 | |
905 | |
854 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
906 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
855 | |
907 | |
856 | void ev_signal_start (ev_signal *w) |
908 | void ev_signal_start (ev_signal *w) |
857 | CODE: |
909 | CODE: |
858 | START (signal, w); |
910 | START_SIGNAL (w); |
859 | |
911 | |
860 | void ev_signal_stop (ev_signal *w) |
912 | void ev_signal_stop (ev_signal *w) |
861 | CODE: |
913 | CODE: |
862 | STOP (signal, w); |
914 | STOP (signal, w); |
863 | |
915 | |
… | |
… | |
870 | CODE: |
922 | CODE: |
871 | { |
923 | { |
872 | Signal signum = s_signum (signal); |
924 | Signal signum = s_signum (signal); |
873 | CHECK_SIG (signal, signum); |
925 | CHECK_SIG (signal, signum); |
874 | |
926 | |
875 | RESET (signal, w, (w, signum)); |
927 | RESET_SIGNAL (w, (w, signum)); |
876 | } |
928 | } |
877 | |
929 | |
878 | int signal (ev_signal *w, SV *new_signal = 0) |
930 | int signal (ev_signal *w, SV *new_signal = 0) |
879 | CODE: |
931 | CODE: |
880 | { |
932 | { |
… | |
… | |
883 | if (items > 1) |
935 | if (items > 1) |
884 | { |
936 | { |
885 | Signal signum = s_signum (new_signal); |
937 | Signal signum = s_signum (new_signal); |
886 | CHECK_SIG (new_signal, signum); |
938 | CHECK_SIG (new_signal, signum); |
887 | |
939 | |
888 | RESET (signal, w, (w, signum)); |
940 | RESET_SIGNAL (w, (w, signum)); |
889 | } |
941 | } |
890 | } |
942 | } |
891 | OUTPUT: |
943 | OUTPUT: |
892 | RETVAL |
944 | RETVAL |
893 | |
945 | |
… | |
… | |
907 | INIT: |
959 | INIT: |
908 | CHECK_REPEAT (w->repeat); |
960 | CHECK_REPEAT (w->repeat); |
909 | CODE: |
961 | CODE: |
910 | ev_timer_again (e_loop (w), w); |
962 | ev_timer_again (e_loop (w), w); |
911 | UNREF (w); |
963 | UNREF (w); |
|
|
964 | |
|
|
965 | NV ev_timer_remaining (ev_timer *w) |
|
|
966 | C_ARGS: e_loop (w), w |
912 | |
967 | |
913 | void DESTROY (ev_timer *w) |
968 | void DESTROY (ev_timer *w) |
914 | CODE: |
969 | CODE: |
915 | STOP (timer, w); |
970 | STOP (timer, w); |
916 | e_destroy (w); |
971 | e_destroy (w); |
… | |
… | |
1219 | if (loop != evapi.default_loop) /* global destruction sucks */ |
1274 | if (loop != evapi.default_loop) /* global destruction sucks */ |
1220 | ev_loop_destroy (loop); |
1275 | ev_loop_destroy (loop); |
1221 | |
1276 | |
1222 | void ev_loop_fork (struct ev_loop *loop) |
1277 | void ev_loop_fork (struct ev_loop *loop) |
1223 | |
1278 | |
1224 | void ev_loop_verify (struct ev_loop *loop) |
1279 | void ev_verify (struct ev_loop *loop) |
1225 | |
1280 | |
1226 | NV ev_now (struct ev_loop *loop) |
1281 | NV ev_now (struct ev_loop *loop) |
1227 | |
1282 | |
1228 | void ev_now_update (struct ev_loop *loop) |
1283 | void ev_now_update (struct ev_loop *loop) |
1229 | |
1284 | |
… | |
… | |
1235 | |
1290 | |
1236 | void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) |
1291 | void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) |
1237 | |
1292 | |
1238 | unsigned int ev_backend (struct ev_loop *loop) |
1293 | unsigned int ev_backend (struct ev_loop *loop) |
1239 | |
1294 | |
1240 | unsigned int ev_loop_count (struct ev_loop *loop) |
1295 | unsigned int ev_iteration (struct ev_loop *loop) |
1241 | |
1296 | |
1242 | unsigned int ev_loop_depth (struct ev_loop *loop) |
1297 | unsigned int ev_depth (struct ev_loop *loop) |
1243 | |
1298 | |
1244 | void ev_loop (struct ev_loop *loop, int flags = 0) |
1299 | void ev_loop (struct ev_loop *loop, int flags = 0) |
1245 | |
1300 | |
1246 | void ev_unloop (struct ev_loop *loop, int how = 1) |
1301 | void ev_unloop (struct ev_loop *loop, int how = 1) |
1247 | |
1302 | |
1248 | void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE) |
1303 | void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE) |
|
|
1304 | |
|
|
1305 | unsigned int ev_pending_count (struct ev_loop *loop) |
|
|
1306 | |
|
|
1307 | void ev_invoke_pending (struct ev_loop *loop) |
1249 | |
1308 | |
1250 | #if 0 |
1309 | #if 0 |
1251 | |
1310 | |
1252 | void ev_feed_signal_event (struct ev_loop *loop, SV *signal) |
1311 | void ev_feed_signal_event (struct ev_loop *loop, SV *signal) |
1253 | CODE: |
1312 | CODE: |
… | |
… | |
1303 | if (!ix) START (periodic, w); |
1362 | if (!ix) START (periodic, w); |
1304 | } |
1363 | } |
1305 | OUTPUT: |
1364 | OUTPUT: |
1306 | RETVAL |
1365 | RETVAL |
1307 | |
1366 | |
1308 | #if 0 |
|
|
1309 | |
|
|
1310 | ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb) |
1367 | ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb) |
1311 | ALIAS: |
1368 | ALIAS: |
1312 | signal_ns = 1 |
1369 | signal_ns = 1 |
1313 | CODE: |
1370 | CODE: |
1314 | { |
1371 | { |
1315 | Signal signum = s_signum (signal); |
1372 | Signal signum = s_signum (signal); |
1316 | CHECK_SIG (signal, signum); |
1373 | CHECK_SIG (signal, signum); |
1317 | |
1374 | |
1318 | RETVAL = e_new (sizeof (ev_signal), cb, ST (0)); |
1375 | RETVAL = e_new (sizeof (ev_signal), cb, ST (0)); |
1319 | ev_signal_set (RETVAL, signum); |
1376 | ev_signal_set (RETVAL, signum); |
1320 | if (!ix) START (signal, RETVAL); |
1377 | if (!ix) START_SIGNAL (RETVAL); |
1321 | } |
1378 | } |
1322 | OUTPUT: |
1379 | OUTPUT: |
1323 | RETVAL |
1380 | RETVAL |
1324 | |
|
|
1325 | #endif |
|
|
1326 | |
1381 | |
1327 | ev_idle *idle (struct ev_loop *loop, SV *cb) |
1382 | ev_idle *idle (struct ev_loop *loop, SV *cb) |
1328 | ALIAS: |
1383 | ALIAS: |
1329 | idle_ns = 1 |
1384 | idle_ns = 1 |
1330 | CODE: |
1385 | CODE: |