… | |
… | |
13 | sv_fileno (SV *fh) |
13 | sv_fileno (SV *fh) |
14 | { |
14 | { |
15 | return s_fileno (fh, 0); |
15 | return s_fileno (fh, 0); |
16 | } |
16 | } |
17 | |
17 | |
|
|
18 | #define EV_STANDALONE 1 |
18 | #define EV_PROTOTYPES 1 |
19 | #define EV_PROTOTYPES 1 |
19 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
20 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
20 | #define EV_H <ev.h> |
21 | #define EV_H <ev.h> |
|
|
22 | #define EV_CONFIG_H error |
21 | #include "EV/EVAPI.h" |
23 | #include "EV/EVAPI.h" |
22 | |
24 | |
23 | #define EV_SELECT_IS_WINSOCKET 0 |
25 | #define EV_SELECT_IS_WINSOCKET 0 |
24 | #ifdef _WIN32 |
26 | #ifdef _WIN32 |
25 | # define EV_SELECT_USE_FD_SET 0 |
27 | # define EV_SELECT_USE_FD_SET 0 |
… | |
… | |
64 | REF (w); \ |
66 | REF (w); \ |
65 | ev_ ## type ## _stop (e_loop (w), w); \ |
67 | ev_ ## type ## _stop (e_loop (w), w); \ |
66 | } while (0) |
68 | } while (0) |
67 | |
69 | |
68 | #define RESET(type,w,seta) \ |
70 | #define RESET(type,w,seta) \ |
69 | do { \ |
71 | do { \ |
70 | int active = ev_is_active (w); \ |
72 | int active = ev_is_active (w); \ |
71 | if (active) STOP (type, w); \ |
73 | if (active) STOP (type, w); \ |
72 | ev_ ## type ## _set seta; \ |
74 | ev_ ## type ## _set seta; \ |
73 | if (active) START (type, w); \ |
75 | if (active) START (type, w); \ |
74 | } while (0) |
76 | } while (0) |
75 | |
77 | |
76 | 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) |
77 | |
102 | |
78 | static SV *default_loop_sv; |
103 | static SV *default_loop_sv; |
79 | |
104 | |
80 | static struct EVAPI evapi; |
105 | static struct EVAPI evapi; |
81 | |
106 | |
… | |
… | |
335 | const_iv (EV_, UNDEF) |
360 | const_iv (EV_, UNDEF) |
336 | const_iv (EV_, NONE) |
361 | const_iv (EV_, NONE) |
337 | const_iv (EV_, READ) |
362 | const_iv (EV_, READ) |
338 | const_iv (EV_, WRITE) |
363 | const_iv (EV_, WRITE) |
339 | const_iv (EV_, IO) |
364 | const_iv (EV_, IO) |
340 | const_iv (EV_, TIMEOUT) |
365 | const_iv (EV_, TIMEOUT) /* deprecated */ |
341 | const_iv (EV_, TIMER) |
366 | const_iv (EV_, TIMER) |
342 | const_iv (EV_, PERIODIC) |
367 | const_iv (EV_, PERIODIC) |
343 | const_iv (EV_, SIGNAL) |
368 | const_iv (EV_, SIGNAL) |
344 | const_iv (EV_, CHILD) |
369 | const_iv (EV_, CHILD) |
345 | const_iv (EV_, STAT) |
370 | const_iv (EV_, STAT) |
… | |
… | |
363 | const_iv (EV, BACKEND_POLL) |
388 | const_iv (EV, BACKEND_POLL) |
364 | const_iv (EV, BACKEND_EPOLL) |
389 | const_iv (EV, BACKEND_EPOLL) |
365 | const_iv (EV, BACKEND_KQUEUE) |
390 | const_iv (EV, BACKEND_KQUEUE) |
366 | const_iv (EV, BACKEND_DEVPOLL) |
391 | const_iv (EV, BACKEND_DEVPOLL) |
367 | const_iv (EV, BACKEND_PORT) |
392 | const_iv (EV, BACKEND_PORT) |
|
|
393 | const_iv (EV, BACKEND_ALL) |
368 | const_iv (EV, FLAG_AUTO) |
394 | const_iv (EV, FLAG_AUTO) |
|
|
395 | const_iv (EV, FLAG_FORKCHECK) |
|
|
396 | const_iv (EV, FLAG_SIGNALFD) |
369 | const_iv (EV, FLAG_NOENV) |
397 | const_iv (EV, FLAG_NOENV) |
|
|
398 | const_iv (EV, FLAG_NOSIGFD) /* compatibility, always 0 */ |
370 | const_iv (EV, FLAG_FORKCHECK) |
399 | const_iv (EV, FLAG_NOINOTIFY) |
371 | |
400 | |
372 | const_iv (EV_, VERSION_MAJOR) |
401 | const_iv (EV_, VERSION_MAJOR) |
373 | const_iv (EV_, VERSION_MINOR) |
402 | const_iv (EV_, VERSION_MINOR) |
374 | }; |
403 | }; |
375 | |
404 | |
… | |
… | |
406 | evapi.time_ = ev_time; |
435 | evapi.time_ = ev_time; |
407 | evapi.sleep_ = ev_sleep; |
436 | evapi.sleep_ = ev_sleep; |
408 | evapi.loop_new = ev_loop_new; |
437 | evapi.loop_new = ev_loop_new; |
409 | evapi.loop_destroy = ev_loop_destroy; |
438 | evapi.loop_destroy = ev_loop_destroy; |
410 | evapi.loop_fork = ev_loop_fork; |
439 | evapi.loop_fork = ev_loop_fork; |
411 | evapi.loop_count = ev_loop_count; |
440 | evapi.iteration = ev_iteration; |
412 | evapi.loop_depth = ev_loop_depth; |
441 | evapi.depth = ev_depth; |
413 | evapi.set_userdata = ev_set_userdata; |
442 | evapi.set_userdata = ev_set_userdata; |
414 | evapi.userdata = ev_userdata; |
443 | evapi.userdata = ev_userdata; |
415 | evapi.now = ev_now; |
444 | evapi.now = ev_now; |
416 | evapi.now_update = ev_now_update; |
445 | evapi.now_update = ev_now_update; |
417 | evapi.suspend = ev_suspend; |
446 | evapi.suspend = ev_suspend; |
418 | evapi.resume = ev_resume; |
447 | evapi.resume = ev_resume; |
419 | evapi.backend = ev_backend; |
448 | evapi.backend = ev_backend; |
420 | evapi.unloop = ev_unloop; |
449 | evapi.unloop = ev_unloop; |
421 | evapi.invoke_pending = ev_invoke_pending; |
450 | evapi.invoke_pending = ev_invoke_pending; |
422 | evapi.pending_count = ev_pending_count; |
451 | evapi.pending_count = ev_pending_count; |
|
|
452 | evapi.verify = ev_verify; |
423 | evapi.set_loop_release_cb = ev_set_loop_release_cb; |
453 | evapi.set_loop_release_cb = ev_set_loop_release_cb; |
424 | evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb; |
454 | evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb; |
425 | evapi.ref = ev_ref; |
455 | evapi.ref = ev_ref; |
426 | evapi.unref = ev_unref; |
456 | evapi.unref = ev_unref; |
427 | evapi.loop = ev_loop; |
457 | evapi.loop = ev_loop; |
… | |
… | |
513 | C_ARGS: evapi.default_loop |
543 | C_ARGS: evapi.default_loop |
514 | |
544 | |
515 | unsigned int ev_backend () |
545 | unsigned int ev_backend () |
516 | C_ARGS: evapi.default_loop |
546 | C_ARGS: evapi.default_loop |
517 | |
547 | |
518 | void ev_loop_verify () |
548 | void ev_verify () |
519 | C_ARGS: evapi.default_loop |
549 | C_ARGS: evapi.default_loop |
520 | |
550 | |
521 | unsigned int ev_loop_count () |
551 | unsigned int ev_iteration () |
522 | C_ARGS: evapi.default_loop |
552 | C_ARGS: evapi.default_loop |
523 | |
553 | |
524 | unsigned int ev_loop_depth () |
554 | unsigned int ev_depth () |
525 | C_ARGS: evapi.default_loop |
555 | C_ARGS: evapi.default_loop |
526 | |
556 | |
527 | void ev_set_io_collect_interval (NV interval) |
557 | void ev_set_io_collect_interval (NV interval) |
528 | C_ARGS: evapi.default_loop, interval |
558 | C_ARGS: evapi.default_loop, interval |
529 | |
559 | |
… | |
… | |
555 | C_ARGS: evapi.default_loop |
585 | C_ARGS: evapi.default_loop |
556 | |
586 | |
557 | ev_io *io (SV *fh, int events, SV *cb) |
587 | ev_io *io (SV *fh, int events, SV *cb) |
558 | ALIAS: |
588 | ALIAS: |
559 | io_ns = 1 |
589 | io_ns = 1 |
|
|
590 | _ae_io = 2 |
560 | CODE: |
591 | CODE: |
561 | { |
592 | { |
562 | int fd = s_fileno (fh, events & EV_WRITE); |
593 | int fd = s_fileno (fh, events & EV_WRITE); |
563 | 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 | } |
564 | |
601 | |
565 | RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); |
602 | RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); |
566 | RETVAL->fh = newSVsv (fh); |
603 | RETVAL->fh = newSVsv (fh); |
567 | ev_io_set (RETVAL, fd, events); |
604 | ev_io_set (RETVAL, fd, events); |
568 | if (!ix) START (io, RETVAL); |
605 | if (!ix) START (io, RETVAL); |
… | |
… | |
607 | Signal signum = s_signum (signal); |
644 | Signal signum = s_signum (signal); |
608 | CHECK_SIG (signal, signum); |
645 | CHECK_SIG (signal, signum); |
609 | |
646 | |
610 | RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv); |
647 | RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv); |
611 | ev_signal_set (RETVAL, signum); |
648 | ev_signal_set (RETVAL, signum); |
612 | if (!ix) START (signal, RETVAL); |
649 | if (!ix) START_SIGNAL (RETVAL); |
613 | } |
650 | } |
614 | OUTPUT: |
651 | OUTPUT: |
615 | RETVAL |
652 | RETVAL |
616 | |
653 | |
617 | ev_idle *idle (SV *cb) |
654 | ev_idle *idle (SV *cb) |
… | |
… | |
868 | |
905 | |
869 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
906 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
870 | |
907 | |
871 | void ev_signal_start (ev_signal *w) |
908 | void ev_signal_start (ev_signal *w) |
872 | CODE: |
909 | CODE: |
873 | START (signal, w); |
910 | START_SIGNAL (w); |
874 | |
911 | |
875 | void ev_signal_stop (ev_signal *w) |
912 | void ev_signal_stop (ev_signal *w) |
876 | CODE: |
913 | CODE: |
877 | STOP (signal, w); |
914 | STOP (signal, w); |
878 | |
915 | |
… | |
… | |
885 | CODE: |
922 | CODE: |
886 | { |
923 | { |
887 | Signal signum = s_signum (signal); |
924 | Signal signum = s_signum (signal); |
888 | CHECK_SIG (signal, signum); |
925 | CHECK_SIG (signal, signum); |
889 | |
926 | |
890 | RESET (signal, w, (w, signum)); |
927 | RESET_SIGNAL (w, (w, signum)); |
891 | } |
928 | } |
892 | |
929 | |
893 | int signal (ev_signal *w, SV *new_signal = 0) |
930 | int signal (ev_signal *w, SV *new_signal = 0) |
894 | CODE: |
931 | CODE: |
895 | { |
932 | { |
… | |
… | |
898 | if (items > 1) |
935 | if (items > 1) |
899 | { |
936 | { |
900 | Signal signum = s_signum (new_signal); |
937 | Signal signum = s_signum (new_signal); |
901 | CHECK_SIG (new_signal, signum); |
938 | CHECK_SIG (new_signal, signum); |
902 | |
939 | |
903 | RESET (signal, w, (w, signum)); |
940 | RESET_SIGNAL (w, (w, signum)); |
904 | } |
941 | } |
905 | } |
942 | } |
906 | OUTPUT: |
943 | OUTPUT: |
907 | RETVAL |
944 | RETVAL |
908 | |
945 | |
… | |
… | |
1237 | if (loop != evapi.default_loop) /* global destruction sucks */ |
1274 | if (loop != evapi.default_loop) /* global destruction sucks */ |
1238 | ev_loop_destroy (loop); |
1275 | ev_loop_destroy (loop); |
1239 | |
1276 | |
1240 | void ev_loop_fork (struct ev_loop *loop) |
1277 | void ev_loop_fork (struct ev_loop *loop) |
1241 | |
1278 | |
1242 | void ev_loop_verify (struct ev_loop *loop) |
1279 | void ev_verify (struct ev_loop *loop) |
1243 | |
1280 | |
1244 | NV ev_now (struct ev_loop *loop) |
1281 | NV ev_now (struct ev_loop *loop) |
1245 | |
1282 | |
1246 | void ev_now_update (struct ev_loop *loop) |
1283 | void ev_now_update (struct ev_loop *loop) |
1247 | |
1284 | |
… | |
… | |
1253 | |
1290 | |
1254 | 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) |
1255 | |
1292 | |
1256 | unsigned int ev_backend (struct ev_loop *loop) |
1293 | unsigned int ev_backend (struct ev_loop *loop) |
1257 | |
1294 | |
1258 | unsigned int ev_loop_count (struct ev_loop *loop) |
1295 | unsigned int ev_iteration (struct ev_loop *loop) |
1259 | |
1296 | |
1260 | unsigned int ev_loop_depth (struct ev_loop *loop) |
1297 | unsigned int ev_depth (struct ev_loop *loop) |
1261 | |
1298 | |
1262 | void ev_loop (struct ev_loop *loop, int flags = 0) |
1299 | void ev_loop (struct ev_loop *loop, int flags = 0) |
1263 | |
1300 | |
1264 | void ev_unloop (struct ev_loop *loop, int how = 1) |
1301 | void ev_unloop (struct ev_loop *loop, int how = 1) |
1265 | |
1302 | |
… | |
… | |
1325 | if (!ix) START (periodic, w); |
1362 | if (!ix) START (periodic, w); |
1326 | } |
1363 | } |
1327 | OUTPUT: |
1364 | OUTPUT: |
1328 | RETVAL |
1365 | RETVAL |
1329 | |
1366 | |
1330 | #if 0 |
|
|
1331 | |
|
|
1332 | ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb) |
1367 | ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb) |
1333 | ALIAS: |
1368 | ALIAS: |
1334 | signal_ns = 1 |
1369 | signal_ns = 1 |
1335 | CODE: |
1370 | CODE: |
1336 | { |
1371 | { |
1337 | Signal signum = s_signum (signal); |
1372 | Signal signum = s_signum (signal); |
1338 | CHECK_SIG (signal, signum); |
1373 | CHECK_SIG (signal, signum); |
1339 | |
1374 | |
1340 | RETVAL = e_new (sizeof (ev_signal), cb, ST (0)); |
1375 | RETVAL = e_new (sizeof (ev_signal), cb, ST (0)); |
1341 | ev_signal_set (RETVAL, signum); |
1376 | ev_signal_set (RETVAL, signum); |
1342 | if (!ix) START (signal, RETVAL); |
1377 | if (!ix) START_SIGNAL (RETVAL); |
1343 | } |
1378 | } |
1344 | OUTPUT: |
1379 | OUTPUT: |
1345 | RETVAL |
1380 | RETVAL |
1346 | |
|
|
1347 | #endif |
|
|
1348 | |
1381 | |
1349 | ev_idle *idle (struct ev_loop *loop, SV *cb) |
1382 | ev_idle *idle (struct ev_loop *loop, SV *cb) |
1350 | ALIAS: |
1383 | ALIAS: |
1351 | idle_ns = 1 |
1384 | idle_ns = 1 |
1352 | CODE: |
1385 | CODE: |