ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV.xs
(Generate patch)

Comparing EV/EV.xs (file contents):
Revision 1.127 by root, Tue Jul 14 02:33:55 2009 UTC vs.
Revision 1.136 by root, Tue Mar 16 17:11:48 2010 UTC

13sv_fileno (SV *fh) 13sv_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
76typedef int Signal; 78typedef 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
78static SV *default_loop_sv; 103static SV *default_loop_sv;
79 104
80static struct EVAPI evapi; 105static 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
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;
451 evapi.pending_count = ev_pending_count;
422 evapi.set_loop_release_cb = ev_set_loop_release_cb; 452 evapi.set_loop_release_cb = ev_set_loop_release_cb;
423 evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb; 453 evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb;
424 evapi.ref = ev_ref; 454 evapi.ref = ev_ref;
425 evapi.unref = ev_unref; 455 evapi.unref = ev_unref;
426 evapi.loop = ev_loop; 456 evapi.loop = ev_loop;
428 evapi.io_start = ev_io_start; 458 evapi.io_start = ev_io_start;
429 evapi.io_stop = ev_io_stop; 459 evapi.io_stop = ev_io_stop;
430 evapi.timer_start = ev_timer_start; 460 evapi.timer_start = ev_timer_start;
431 evapi.timer_stop = ev_timer_stop; 461 evapi.timer_stop = ev_timer_stop;
432 evapi.timer_again = ev_timer_again; 462 evapi.timer_again = ev_timer_again;
463 evapi.timer_remaining = ev_timer_remaining;
433 evapi.periodic_start = ev_periodic_start; 464 evapi.periodic_start = ev_periodic_start;
434 evapi.periodic_stop = ev_periodic_stop; 465 evapi.periodic_stop = ev_periodic_stop;
435 evapi.signal_start = ev_signal_start; 466 evapi.signal_start = ev_signal_start;
436 evapi.signal_stop = ev_signal_stop; 467 evapi.signal_stop = ev_signal_stop;
437 evapi.idle_start = ev_idle_start; 468 evapi.idle_start = ev_idle_start;
544 CHECK_SIG (signal, signum); 575 CHECK_SIG (signal, signum);
545 576
546 ev_feed_signal_event (evapi.default_loop, signum); 577 ev_feed_signal_event (evapi.default_loop, signum);
547} 578}
548 579
580unsigned int ev_pending_count ()
581 C_ARGS: evapi.default_loop
582
583void ev_invoke_pending ()
584 C_ARGS: evapi.default_loop
585
549ev_io *io (SV *fh, int events, SV *cb) 586ev_io *io (SV *fh, int events, SV *cb)
550 ALIAS: 587 ALIAS:
551 io_ns = 1 588 io_ns = 1
589 _ae_io = 2
552 CODE: 590 CODE:
553{ 591{
554 int fd = s_fileno (fh, events & EV_WRITE); 592 int fd = s_fileno (fh, events & EV_WRITE);
555 CHECK_FD (fh, fd); 593 CHECK_FD (fh, fd);
594
595 if (ix == 2)
596 {
597 ix = 0;
598 events = events ? EV_WRITE : EV_READ;
599 }
556 600
557 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); 601 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
558 RETVAL->fh = newSVsv (fh); 602 RETVAL->fh = newSVsv (fh);
559 ev_io_set (RETVAL, fd, events); 603 ev_io_set (RETVAL, fd, events);
560 if (!ix) START (io, RETVAL); 604 if (!ix) START (io, RETVAL);
599 Signal signum = s_signum (signal); 643 Signal signum = s_signum (signal);
600 CHECK_SIG (signal, signum); 644 CHECK_SIG (signal, signum);
601 645
602 RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv); 646 RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv);
603 ev_signal_set (RETVAL, signum); 647 ev_signal_set (RETVAL, signum);
604 if (!ix) START (signal, RETVAL); 648 if (!ix) START_SIGNAL (RETVAL);
605} 649}
606 OUTPUT: 650 OUTPUT:
607 RETVAL 651 RETVAL
608 652
609ev_idle *idle (SV *cb) 653ev_idle *idle (SV *cb)
860 904
861MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ 905MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_
862 906
863void ev_signal_start (ev_signal *w) 907void ev_signal_start (ev_signal *w)
864 CODE: 908 CODE:
865 START (signal, w); 909 START_SIGNAL (w);
866 910
867void ev_signal_stop (ev_signal *w) 911void ev_signal_stop (ev_signal *w)
868 CODE: 912 CODE:
869 STOP (signal, w); 913 STOP (signal, w);
870 914
877 CODE: 921 CODE:
878{ 922{
879 Signal signum = s_signum (signal); 923 Signal signum = s_signum (signal);
880 CHECK_SIG (signal, signum); 924 CHECK_SIG (signal, signum);
881 925
882 RESET (signal, w, (w, signum)); 926 RESET_SIGNAL (w, (w, signum));
883} 927}
884 928
885int signal (ev_signal *w, SV *new_signal = 0) 929int signal (ev_signal *w, SV *new_signal = 0)
886 CODE: 930 CODE:
887{ 931{
890 if (items > 1) 934 if (items > 1)
891 { 935 {
892 Signal signum = s_signum (new_signal); 936 Signal signum = s_signum (new_signal);
893 CHECK_SIG (new_signal, signum); 937 CHECK_SIG (new_signal, signum);
894 938
895 RESET (signal, w, (w, signum)); 939 RESET_SIGNAL (w, (w, signum));
896 } 940 }
897} 941}
898 OUTPUT: 942 OUTPUT:
899 RETVAL 943 RETVAL
900 944
914 INIT: 958 INIT:
915 CHECK_REPEAT (w->repeat); 959 CHECK_REPEAT (w->repeat);
916 CODE: 960 CODE:
917 ev_timer_again (e_loop (w), w); 961 ev_timer_again (e_loop (w), w);
918 UNREF (w); 962 UNREF (w);
963
964NV ev_timer_remaining (ev_timer *w)
965 C_ARGS: e_loop (w), w
919 966
920void DESTROY (ev_timer *w) 967void DESTROY (ev_timer *w)
921 CODE: 968 CODE:
922 STOP (timer, w); 969 STOP (timer, w);
923 e_destroy (w); 970 e_destroy (w);
1252 1299
1253void ev_unloop (struct ev_loop *loop, int how = 1) 1300void ev_unloop (struct ev_loop *loop, int how = 1)
1254 1301
1255void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE) 1302void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE)
1256 1303
1304unsigned int ev_pending_count (struct ev_loop *loop)
1305
1306void ev_invoke_pending (struct ev_loop *loop)
1307
1257#if 0 1308#if 0
1258 1309
1259void ev_feed_signal_event (struct ev_loop *loop, SV *signal) 1310void ev_feed_signal_event (struct ev_loop *loop, SV *signal)
1260 CODE: 1311 CODE:
1261{ 1312{
1310 if (!ix) START (periodic, w); 1361 if (!ix) START (periodic, w);
1311} 1362}
1312 OUTPUT: 1363 OUTPUT:
1313 RETVAL 1364 RETVAL
1314 1365
1315#if 0
1316
1317ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb) 1366ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb)
1318 ALIAS: 1367 ALIAS:
1319 signal_ns = 1 1368 signal_ns = 1
1320 CODE: 1369 CODE:
1321{ 1370{
1322 Signal signum = s_signum (signal); 1371 Signal signum = s_signum (signal);
1323 CHECK_SIG (signal, signum); 1372 CHECK_SIG (signal, signum);
1324 1373
1325 RETVAL = e_new (sizeof (ev_signal), cb, ST (0)); 1374 RETVAL = e_new (sizeof (ev_signal), cb, ST (0));
1326 ev_signal_set (RETVAL, signum); 1375 ev_signal_set (RETVAL, signum);
1327 if (!ix) START (signal, RETVAL); 1376 if (!ix) START_SIGNAL (RETVAL);
1328} 1377}
1329 OUTPUT: 1378 OUTPUT:
1330 RETVAL 1379 RETVAL
1331
1332#endif
1333 1380
1334ev_idle *idle (struct ev_loop *loop, SV *cb) 1381ev_idle *idle (struct ev_loop *loop, SV *cb)
1335 ALIAS: 1382 ALIAS:
1336 idle_ns = 1 1383 idle_ns = 1
1337 CODE: 1384 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines