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

Comparing EV/EV.xs (file contents):
Revision 1.23 by root, Wed Oct 31 19:07:43 2007 UTC vs.
Revision 1.57 by root, Tue Nov 6 17:20:42 2007 UTC

2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4 4
5/*#include <netinet/in.h>*/ 5/*#include <netinet/in.h>*/
6 6
7#define TIMEOUT_NONE HUGE_VAL
8#define HAVE_EPOLL 1
9
10#define EV_PROTOTYPES 1 7#define EV_PROTOTYPES 1
11#include "EV/EVAPI.h" 8#include "EV/EVAPI.h"
12 9
10/* fix perl api breakage */
11#undef signal
12#undef sigaction
13
14/* due to bugs in OS X we have to use libev/ explicitly here */
13#include "libev/ev.c" 15#include "libev/ev.c"
16#include "event.c"
17
18#ifndef WIN32
19#define DNS_USE_GETTIMEOFDAY_FOR_ID 1
20#if !defined (WIN32) && !defined(__CYGWIN__)
21# define HAVE_STRUCT_IN6_ADDR 1
22#endif
23#undef HAVE_STRTOK_R
24#undef strtok_r
25#define strtok_r fake_strtok_r
26#include "evdns.c"
27#endif
28
29#ifndef WIN32
30# include <pthread.h>
31#endif
14 32
15typedef int Signal; 33typedef int Signal;
16 34
17static struct EVAPI evapi; 35static struct EVAPI evapi;
18 36
19static HV 37static HV
20 *stash_watcher, 38 *stash_watcher,
21 *stash_io, 39 *stash_io,
22 *stash_time,
23 *stash_timer, 40 *stash_timer,
24 *stash_periodic, 41 *stash_periodic,
25 *stash_signal, 42 *stash_signal,
26 *stash_idle, 43 *stash_idle,
27 *stash_prepare, 44 *stash_prepare,
28 *stash_check, 45 *stash_check,
29 *stash_child; 46 *stash_child;
30 47
48#ifndef SIG_SIZE
49/* kudos to Slaven Rezic for the idea */
50static char sig_size [] = { SIG_NUM };
51# define SIG_SIZE (sizeof (sig_size) + 1)
52#endif
53
31static int 54static int
32sv_signum (SV *sig) 55sv_signum (SV *sig)
33{ 56{
34 int signum; 57 int signum;
35 58
36 if (SvIV (sig) > 0) 59 SvGETMAGIC (sig);
37 return SvIV (sig);
38 60
39 for (signum = 1; signum < SIG_SIZE; ++signum) 61 for (signum = 1; signum < SIG_SIZE; ++signum)
40 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) 62 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum]))
41 return signum; 63 return signum;
42 64
65 if (SvIV (sig) > 0)
66 return SvIV (sig);
67
43 return -1; 68 return -1;
44} 69}
45 70
46///////////////////////////////////////////////////////////////////////////// 71/////////////////////////////////////////////////////////////////////////////
47// Event 72// Event
57 fh = SvRV (fh); 82 fh = SvRV (fh);
58 83
59 if (SvTYPE (fh) == SVt_PVGV) 84 if (SvTYPE (fh) == SVt_PVGV)
60 return PerlIO_fileno (IoIFP (sv_2io (fh))); 85 return PerlIO_fileno (IoIFP (sv_2io (fh)));
61 86
62 if (SvIOK (fh)) 87 if ((SvIV (fh) >= 0) && (SvIV (fh) < 0x7ffffff))
63 return SvIV (fh); 88 return SvIV (fh);
64 89
65 return -1; 90 return -1;
66} 91}
67 92
73 SvPOK_only (self); 98 SvPOK_only (self);
74 SvCUR_set (self, size); 99 SvCUR_set (self, size);
75 100
76 w = (struct ev_watcher *)SvPVX (self); 101 w = (struct ev_watcher *)SvPVX (self);
77 102
78 evw_init (w, e_cb); 103 ev_watcher_init (w, e_cb);
79 104
80 w->fh = 0; 105 w->fh = 0;
81 w->cb_sv = newSVsv (cb_sv); 106 w->cb_sv = newSVsv (cb_sv);
82 w->self = self; 107 w->self = self;
83 108
84 return (void *)w; 109 return (void *)w;
110}
111
112static void
113e_destroy (void *w_)
114{
115 struct ev_watcher *w = (struct ev_watcher *)w_;
116
117 SvREFCNT_dec (w->fh ); w->fh = 0;
118 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0;
85} 119}
86 120
87static SV * 121static SV *
88e_bless (struct ev_watcher *w, HV *stash) 122e_bless (struct ev_watcher *w, HV *stash)
89{ 123{
104static void 138static void
105e_cb (struct ev_watcher *w, int revents) 139e_cb (struct ev_watcher *w, int revents)
106{ 140{
107 dSP; 141 dSP;
108 I32 mark = SP - PL_stack_base; 142 I32 mark = SP - PL_stack_base;
109 SV *sv_self, *sv_events; 143 SV *sv_self, *sv_events, *sv_status = 0;
110 static SV *sv_events_cache; 144 static SV *sv_events_cache;
111 145
112 sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ 146 sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */
113 147
114 if (sv_events_cache) 148 if (sv_events_cache)
121 155
122 PUSHMARK (SP); 156 PUSHMARK (SP);
123 EXTEND (SP, 2); 157 EXTEND (SP, 2);
124 PUSHs (sv_self); 158 PUSHs (sv_self);
125 PUSHs (sv_events); 159 PUSHs (sv_events);
160
126 PUTBACK; 161 PUTBACK;
127 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); 162 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
128 SP = PL_stack_base + mark; PUTBACK; 163 SP = PL_stack_base + mark; PUTBACK;
129 164
130 SvREFCNT_dec (sv_self); 165 SvREFCNT_dec (sv_self);
166 SvREFCNT_dec (sv_status);
131 167
132 if (sv_events_cache) 168 if (sv_events_cache)
133 SvREFCNT_dec (sv_events); 169 SvREFCNT_dec (sv_events);
134 else 170 else
135 sv_events_cache = sv_events; 171 sv_events_cache = sv_events;
141 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 177 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
142 SP = PL_stack_base + mark; PUTBACK; 178 SP = PL_stack_base + mark; PUTBACK;
143 } 179 }
144} 180}
145 181
146#if 0
147///////////////////////////////////////////////////////////////////////////// 182/////////////////////////////////////////////////////////////////////////////
148// DNS 183// DNS
149 184
185#ifndef WIN32
150static void 186static void
151dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) 187dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg)
152{ 188{
153 dSP; 189 dSP;
154 SV *cb = (SV *)arg; 190 SV *cb = (SV *)arg;
198#endif 234#endif
199 235
200#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 236#define CHECK_REPEAT(repeat) if (repeat < 0.) \
201 croak (# repeat " value must be >= 0"); 237 croak (# repeat " value must be >= 0");
202 238
239#define CHECK_FD(fh,fd) if ((fd) < 0) \
240 croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh));
241
203///////////////////////////////////////////////////////////////////////////// 242/////////////////////////////////////////////////////////////////////////////
204// XS interface functions 243// XS interface functions
205 244
206MODULE = EV PACKAGE = EV PREFIX = ev_ 245MODULE = EV PACKAGE = EV PREFIX = ev_
207 246
208PROTOTYPES: ENABLE 247PROTOTYPES: ENABLE
209 248
210BOOT: 249BOOT:
211{ 250{
212 int i;
213 HV *stash = gv_stashpv ("EV", 1); 251 HV *stash = gv_stashpv ("EV", 1);
214 252
215 static const struct { 253 static const struct {
216 const char *name; 254 const char *name;
217 IV iv; 255 IV iv;
218 } *civ, const_iv[] = { 256 } *civ, const_iv[] = {
219# define const_iv(pfx, name) { # name, (IV) pfx ## name }, 257# define const_iv(pfx, name) { # name, (IV) pfx ## name },
258 const_iv (EV_, MINPRI)
259 const_iv (EV_, MAXPRI)
260
220 const_iv (EV_, UNDEF) 261 const_iv (EV_, UNDEF)
221 const_iv (EV_, NONE) 262 const_iv (EV_, NONE)
222 const_iv (EV_, TIMEOUT) 263 const_iv (EV_, TIMEOUT)
223 const_iv (EV_, READ) 264 const_iv (EV_, READ)
224 const_iv (EV_, WRITE) 265 const_iv (EV_, WRITE)
228 const_iv (EV_, ERROR) 269 const_iv (EV_, ERROR)
229 270
230 const_iv (EV, LOOP_ONESHOT) 271 const_iv (EV, LOOP_ONESHOT)
231 const_iv (EV, LOOP_NONBLOCK) 272 const_iv (EV, LOOP_NONBLOCK)
232 273
233 const_iv (EV, METHOD_NONE) 274 const_iv (EV, METHOD_AUTO)
234 const_iv (EV, METHOD_SELECT) 275 const_iv (EV, METHOD_SELECT)
276 const_iv (EV, METHOD_POLL)
235 const_iv (EV, METHOD_EPOLL) 277 const_iv (EV, METHOD_EPOLL)
278 const_iv (EV, METHOD_KQUEUE)
279 const_iv (EV, METHOD_DEVPOLL)
280 const_iv (EV, METHOD_PORT)
281 const_iv (EV, METHOD_ANY)
236 }; 282 };
237 283
238 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 284 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
239 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 285 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
240 286
241 stash_watcher = gv_stashpv ("EV::Watcher" , 1); 287 stash_watcher = gv_stashpv ("EV::Watcher" , 1);
242 stash_io = gv_stashpv ("EV::IO" , 1); 288 stash_io = gv_stashpv ("EV::Io" , 1);
243 stash_time = gv_stashpv ("EV::Time" , 1);
244 stash_timer = gv_stashpv ("EV::Timer" , 1); 289 stash_timer = gv_stashpv ("EV::Timer" , 1);
245 stash_periodic = gv_stashpv ("EV::Periodic", 1); 290 stash_periodic = gv_stashpv ("EV::Periodic", 1);
246 stash_signal = gv_stashpv ("EV::Signal" , 1); 291 stash_signal = gv_stashpv ("EV::Signal" , 1);
247 stash_idle = gv_stashpv ("EV::Idle" , 1); 292 stash_idle = gv_stashpv ("EV::Idle" , 1);
248 stash_prepare = gv_stashpv ("EV::Prepare" , 1); 293 stash_prepare = gv_stashpv ("EV::Prepare" , 1);
256 /* the poor man's shared library emulator */ 301 /* the poor man's shared library emulator */
257 evapi.ver = EV_API_VERSION; 302 evapi.ver = EV_API_VERSION;
258 evapi.rev = EV_API_REVISION; 303 evapi.rev = EV_API_REVISION;
259 evapi.sv_fileno = sv_fileno; 304 evapi.sv_fileno = sv_fileno;
260 evapi.sv_signum = sv_signum; 305 evapi.sv_signum = sv_signum;
261 evapi.now = &ev_now; 306 evapi.now = ev_now;
262 evapi.method = &ev_method; 307 evapi.method = ev_method;
263 evapi.loop_done = &ev_loop_done; 308 evapi.unloop = ev_unloop;
264 evapi.time = ev_time; 309 evapi.time = ev_time;
265 evapi.loop = ev_loop; 310 evapi.loop = ev_loop;
266 evapi.once = ev_once; 311 evapi.once = ev_once;
267 evapi.io_start = evio_start; 312 evapi.io_start = ev_io_start;
268 evapi.io_stop = evio_stop; 313 evapi.io_stop = ev_io_stop;
269 evapi.timer_start = evtimer_start; 314 evapi.timer_start = ev_timer_start;
270 evapi.timer_stop = evtimer_stop; 315 evapi.timer_stop = ev_timer_stop;
271 evapi.timer_again = evtimer_again; 316 evapi.timer_again = ev_timer_again;
272 evapi.periodic_start = evperiodic_start; 317 evapi.periodic_start = ev_periodic_start;
273 evapi.periodic_stop = evperiodic_stop; 318 evapi.periodic_stop = ev_periodic_stop;
274 evapi.signal_start = evsignal_start; 319 evapi.signal_start = ev_signal_start;
275 evapi.signal_stop = evsignal_stop; 320 evapi.signal_stop = ev_signal_stop;
276 evapi.idle_start = evidle_start; 321 evapi.idle_start = ev_idle_start;
277 evapi.idle_stop = evidle_stop; 322 evapi.idle_stop = ev_idle_stop;
278 evapi.prepare_start = evprepare_start; 323 evapi.prepare_start = ev_prepare_start;
279 evapi.prepare_stop = evprepare_stop; 324 evapi.prepare_stop = ev_prepare_stop;
280 evapi.check_start = evcheck_start; 325 evapi.check_start = ev_check_start;
281 evapi.check_stop = evcheck_stop; 326 evapi.check_stop = ev_check_stop;
327 evapi.child_start = ev_child_start;
328 evapi.child_stop = ev_child_stop;
282 329
283 sv_setiv (sv, (IV)&evapi); 330 sv_setiv (sv, (IV)&evapi);
284 SvREADONLY_on (sv); 331 SvREADONLY_on (sv);
285 } 332 }
333#ifndef WIN32
334 pthread_atfork (0, 0, ev_default_fork);
335#endif
286} 336}
287 337
288NV ev_now () 338NV ev_now ()
289 CODE:
290 RETVAL = ev_now;
291 OUTPUT:
292 RETVAL
293 339
294int ev_method () 340int ev_method ()
295 CODE:
296 RETVAL = ev_method;
297 OUTPUT:
298 RETVAL
299 341
300NV ev_time () 342NV ev_time ()
301 343
302void ev_init (int flags = 0) 344int ev_default_loop (int methods = EVMETHOD_AUTO)
303 345
304void ev_loop (int flags = 0) 346void ev_loop (int flags = 0)
305 347
306void ev_loop_done (int value = 1) 348void ev_unloop (int how = 1)
307 CODE:
308 ev_loop_done = value;
309 349
310struct ev_io *io (SV *fh, int events, SV *cb) 350struct ev_io *io (SV *fh, int events, SV *cb)
311 ALIAS: 351 ALIAS:
312 io_ns = 1 352 io_ns = 1
313 CODE: 353 CODE:
354{
355 int fd = sv_fileno (fh);
356 CHECK_FD (fh, fd);
357
314 RETVAL = e_new (sizeof (struct ev_io), cb); 358 RETVAL = e_new (sizeof (struct ev_io), cb);
315 RETVAL->fh = newSVsv (fh); 359 RETVAL->fh = newSVsv (fh);
316 evio_set (RETVAL, sv_fileno (RETVAL->fh), events); 360 ev_io_set (RETVAL, fd, events);
317 if (!ix) evio_start (RETVAL); 361 if (!ix) ev_io_start (RETVAL);
362}
318 OUTPUT: 363 OUTPUT:
319 RETVAL 364 RETVAL
320 365
321struct ev_timer *timer (NV after, NV repeat, SV *cb) 366struct ev_timer *timer (NV after, NV repeat, SV *cb)
322 ALIAS: 367 ALIAS:
323 timer_ns = 1 368 timer_ns = 1
324 INIT: 369 INIT:
325 CHECK_REPEAT (repeat); 370 CHECK_REPEAT (repeat);
326 CODE: 371 CODE:
327 RETVAL = e_new (sizeof (struct ev_timer), cb); 372 RETVAL = e_new (sizeof (struct ev_timer), cb);
328 evtimer_set (RETVAL, after, repeat); 373 ev_timer_set (RETVAL, after, repeat);
329 if (!ix) evtimer_start (RETVAL); 374 if (!ix) ev_timer_start (RETVAL);
330 OUTPUT: 375 OUTPUT:
331 RETVAL 376 RETVAL
332 377
333struct ev_periodic *periodic (NV at, NV interval, SV *cb) 378struct ev_periodic *periodic (NV at, NV interval, SV *cb)
334 ALIAS: 379 ALIAS:
335 periodic_ns = 1 380 periodic_ns = 1
336 INIT: 381 INIT:
337 CHECK_REPEAT (interval); 382 CHECK_REPEAT (interval);
338 CODE: 383 CODE:
339 RETVAL = e_new (sizeof (struct ev_periodic), cb); 384 RETVAL = e_new (sizeof (struct ev_periodic), cb);
340 evperiodic_set (RETVAL, at, interval); 385 ev_periodic_set (RETVAL, at, interval);
341 if (!ix) evperiodic_start (RETVAL); 386 if (!ix) ev_periodic_start (RETVAL);
342 OUTPUT: 387 OUTPUT:
343 RETVAL 388 RETVAL
344 389
345struct ev_signal *signal (Signal signum, SV *cb) 390struct ev_signal *signal (Signal signum, SV *cb)
346 ALIAS: 391 ALIAS:
347 signal_ns = 1 392 signal_ns = 1
348 CODE: 393 CODE:
349 RETVAL = e_new (sizeof (struct ev_signal), cb); 394 RETVAL = e_new (sizeof (struct ev_signal), cb);
350 evsignal_set (RETVAL, signum); 395 ev_signal_set (RETVAL, signum);
351 if (!ix) evsignal_start (RETVAL); 396 if (!ix) ev_signal_start (RETVAL);
352 OUTPUT: 397 OUTPUT:
353 RETVAL 398 RETVAL
354 399
355struct ev_idle *idle (SV *cb) 400struct ev_idle *idle (SV *cb)
356 ALIAS: 401 ALIAS:
357 idle_ns = 1 402 idle_ns = 1
358 CODE: 403 CODE:
359 RETVAL = e_new (sizeof (struct ev_idle), cb); 404 RETVAL = e_new (sizeof (struct ev_idle), cb);
360 evidle_set (RETVAL); 405 ev_idle_set (RETVAL);
361 if (!ix) evidle_start (RETVAL); 406 if (!ix) ev_idle_start (RETVAL);
362 OUTPUT: 407 OUTPUT:
363 RETVAL 408 RETVAL
364 409
365struct ev_prepare *prepare (SV *cb) 410struct ev_prepare *prepare (SV *cb)
366 ALIAS: 411 ALIAS:
367 prepare_ns = 1 412 prepare_ns = 1
368 CODE: 413 CODE:
369 RETVAL = e_new (sizeof (struct ev_prepare), cb); 414 RETVAL = e_new (sizeof (struct ev_prepare), cb);
370 evprepare_set (RETVAL); 415 ev_prepare_set (RETVAL);
371 if (!ix) evprepare_start (RETVAL); 416 if (!ix) ev_prepare_start (RETVAL);
372 OUTPUT: 417 OUTPUT:
373 RETVAL 418 RETVAL
374 419
375struct ev_check *check (SV *cb) 420struct ev_check *check (SV *cb)
376 ALIAS: 421 ALIAS:
377 check_ns = 1 422 check_ns = 1
378 CODE: 423 CODE:
379 RETVAL = e_new (sizeof (struct ev_check), cb); 424 RETVAL = e_new (sizeof (struct ev_check), cb);
380 evcheck_set (RETVAL); 425 ev_check_set (RETVAL);
381 if (!ix) evcheck_start (RETVAL); 426 if (!ix) ev_check_start (RETVAL);
382 OUTPUT: 427 OUTPUT:
383 RETVAL 428 RETVAL
384 429
385struct ev_child *child (SV *cb, int pid) 430struct ev_child *child (int pid, SV *cb)
386 ALIAS: 431 ALIAS:
387 check_ns = 1 432 check_ns = 1
388 CODE: 433 CODE:
389 RETVAL = e_new (sizeof (struct ev_check), cb); 434 RETVAL = e_new (sizeof (struct ev_child), cb);
390 evchild (RETVAL, pid); 435 ev_child_set (RETVAL, pid);
391 if (!ix) evchild_start (RETVAL); 436 if (!ix) ev_child_start (RETVAL);
392 OUTPUT: 437 OUTPUT:
393 RETVAL 438 RETVAL
394 439
395 440
396PROTOTYPES: DISABLE 441PROTOTYPES: DISABLE
408 sv_setsv (w->cb_sv, new_cb); 453 sv_setsv (w->cb_sv, new_cb);
409} 454}
410 OUTPUT: 455 OUTPUT:
411 RETVAL 456 RETVAL
412 457
413MODULE = EV PACKAGE = EV::IO PREFIX = evio_ 458void trigger (struct ev_watcher *w, int revents = EV_NONE)
414
415void evio_start (struct ev_io *w)
416
417void evio_stop (struct ev_io *w)
418
419void set (struct ev_io *w, SV *fh, int events)
420 CODE: 459 CODE:
421{ 460 w->cb (w, revents);
422 int active = w->active;
423 if (active) evio_stop (w);
424 461
425 sv_setsv (w->fh, fh); 462int priority (struct ev_watcher *w, int new_priority = 0)
426 evio_set (w, sv_fileno (w->fh), events);
427
428 if (active) evio_start (w);
429}
430
431SV *fh (struct ev_io *w, SV *new_fh = 0)
432 CODE: 463 CODE:
433{ 464{
434 RETVAL = newSVsv (w->fh); 465 RETVAL = w->priority;
435 466
436 if (items > 1) 467 if (items > 1)
437 { 468 {
438 int active = w->active; 469 int active = ev_is_active (w);
470
471 if (new_priority < EV_MINPRI || new_priority > EV_MAXPRI)
472 croak ("watcher priority out of range, value must be between %d and %d, inclusive", EV_MINPRI, EV_MAXPRI);
473
439 if (active) evio_stop (w); 474 if (active)
475 {
476 /* grrr. */
477 PUSHMARK (SP);
478 XPUSHs (ST (0));
479 call_method ("stop", G_DISCARD | G_VOID);
480 }
440 481
441 sv_setsv (w->fh, new_fh); 482 ev_set_priority (w, new_priority);
442 evio_set (w, sv_fileno (w->fh), w->events);
443 483
444 if (active) evio_start (w); 484 if (active)
485 {
486 PUSHMARK (SP);
487 XPUSHs (ST (0));
488 call_method ("start", G_DISCARD | G_VOID);
489 }
445 } 490 }
446} 491}
447 OUTPUT: 492 OUTPUT:
448 RETVAL 493 RETVAL
449 494
450short events (struct ev_io *w, short new_events = EV_UNDEF) 495MODULE = EV PACKAGE = EV::Io PREFIX = ev_io_
496
497void ev_io_start (struct ev_io *w)
498
499void ev_io_stop (struct ev_io *w)
500
501void DESTROY (struct ev_io *w)
451 CODE: 502 CODE:
503 ev_io_stop (w);
504 e_destroy (w);
505
506void set (struct ev_io *w, SV *fh, int events)
507 CODE:
452{ 508{
453 RETVAL = w->events; 509 int active = ev_is_active (w);
510 int fd = sv_fileno (fh);
511 CHECK_FD (fh, fd);
512
513 if (active) ev_io_stop (w);
514
515 sv_setsv (w->fh, fh);
516 ev_io_set (w, fd, events);
517
518 if (active) ev_io_start (w);
519}
520
521SV *fh (struct ev_io *w, SV *new_fh = 0)
522 CODE:
523{
524 RETVAL = newSVsv (w->fh);
454 525
455 if (items > 1) 526 if (items > 1)
456 { 527 {
457 int active = w->active; 528 int active = ev_is_active (w);
458 if (active) evio_stop (w); 529 if (active) ev_io_stop (w);
459 530
531 sv_setsv (w->fh, new_fh);
460 evio_set (w, w->fd, new_events); 532 ev_io_set (w, sv_fileno (w->fh), w->events);
461 533
462 if (active) evio_start (w); 534 if (active) ev_io_start (w);
463 } 535 }
464} 536}
465 OUTPUT: 537 OUTPUT:
466 RETVAL 538 RETVAL
467 539
540int events (struct ev_io *w, int new_events = EV_UNDEF)
541 CODE:
542{
543 RETVAL = w->events;
544
545 if (items > 1)
546 {
547 int active = ev_is_active (w);
548 if (active) ev_io_stop (w);
549
550 ev_io_set (w, w->fd, new_events);
551
552 if (active) ev_io_start (w);
553 }
554}
555 OUTPUT:
556 RETVAL
557
468MODULE = EV PACKAGE = EV::Signal PREFIX = evsignal_ 558MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_
469 559
470void evsignal_start (struct ev_signal *w) 560void ev_signal_start (struct ev_signal *w)
471 561
472void evsignal_stop (struct ev_signal *w) 562void ev_signal_stop (struct ev_signal *w)
473 563
564void DESTROY (struct ev_signal *w)
565 CODE:
566 ev_signal_stop (w);
567 e_destroy (w);
568
474void set (struct ev_signal *w, SV *signal = 0) 569void set (struct ev_signal *w, SV *signal)
475 CODE: 570 CODE:
476{ 571{
477 Signal signum = sv_signum (signal); /* may croak here */ 572 Signal signum = sv_signum (signal); /* may croak here */
478 int active = w->active; 573 int active = ev_is_active (w);
479 574
480 if (active) evsignal_stop (w); 575 if (active) ev_signal_stop (w);
576
481 evsignal_set (w, signum); 577 ev_signal_set (w, signum);
578
482 if (active) evsignal_start (w); 579 if (active) ev_signal_start (w);
483} 580}
484 581
485MODULE = EV PACKAGE = EV::Time 582int signal (struct ev_signal *w, SV *new_signal = 0)
583 CODE:
584{
585 RETVAL = w->signum;
486 586
587 if (items > 1)
588 {
589 Signal signum = sv_signum (new_signal); /* may croak here */
590 int active = ev_is_active (w);
591 if (active) ev_signal_stop (w);
592
593 ev_signal_set (w, signum);
594
595 if (active) ev_signal_start (w);
596 }
597}
598 OUTPUT:
599 RETVAL
600
487MODULE = EV PACKAGE = EV::Timer PREFIX = evtimer_ 601MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_
488 602
489void evtimer_start (struct ev_timer *w) 603void ev_timer_start (struct ev_timer *w)
490 INIT: 604 INIT:
491 CHECK_REPEAT (w->repeat); 605 CHECK_REPEAT (w->repeat);
492 606
493void evtimer_stop (struct ev_timer *w) 607void ev_timer_stop (struct ev_timer *w)
494 608
495void evtimer_again (struct ev_timer *w) 609void ev_timer_again (struct ev_timer *w)
496 INIT: 610 INIT:
497 CHECK_REPEAT (w->repeat); 611 CHECK_REPEAT (w->repeat);
612
613void DESTROY (struct ev_timer *w)
614 CODE:
615 ev_timer_stop (w);
616 e_destroy (w);
498 617
499void set (struct ev_timer *w, NV after, NV repeat = 0.) 618void set (struct ev_timer *w, NV after, NV repeat = 0.)
500 INIT: 619 INIT:
501 CHECK_REPEAT (repeat); 620 CHECK_REPEAT (repeat);
502 CODE: 621 CODE:
503{ 622{
504 int active = w->active; 623 int active = ev_is_active (w);
505 if (active) evtimer_stop (w); 624 if (active) ev_timer_stop (w);
506 evtimer_set (w, after, repeat); 625 ev_timer_set (w, after, repeat);
507 if (active) evtimer_start (w); 626 if (active) ev_timer_start (w);
508} 627}
509 628
510MODULE = EV PACKAGE = EV::Periodic PREFIX = evperiodic_ 629MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
511 630
512void evperiodic_start (struct ev_periodic *w) 631void ev_periodic_start (struct ev_periodic *w)
513 INIT: 632 INIT:
514 CHECK_REPEAT (w->interval); 633 CHECK_REPEAT (w->interval);
515 634
516void evperiodic_stop (struct ev_periodic *w) 635void ev_periodic_stop (struct ev_periodic *w)
636
637void DESTROY (struct ev_periodic *w)
638 CODE:
639 ev_periodic_stop (w);
640 e_destroy (w);
517 641
518void set (struct ev_periodic *w, NV at, NV interval = 0.) 642void set (struct ev_periodic *w, NV at, NV interval = 0.)
519 INIT: 643 INIT:
520 CHECK_REPEAT (interval); 644 CHECK_REPEAT (interval);
521 CODE: 645 CODE:
522{ 646{
523 int active = w->active; 647 int active = ev_is_active (w);
524 if (active) evperiodic_stop (w); 648 if (active) ev_periodic_stop (w);
649
525 evperiodic_set (w, at, interval); 650 ev_periodic_set (w, at, interval);
651
526 if (active) evperiodic_start (w); 652 if (active) ev_periodic_start (w);
527} 653}
528 654
529MODULE = EV PACKAGE = EV::Idle PREFIX = evidle_ 655MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
530 656
531void evidle_start (struct ev_idle *w) 657void ev_idle_start (struct ev_idle *w)
532 658
533void evidle_stop (struct ev_idle *w) 659void ev_idle_stop (struct ev_idle *w)
534 660
661void DESTROY (struct ev_idle *w)
662 CODE:
663 ev_idle_stop (w);
664 e_destroy (w);
665
535MODULE = EV PACKAGE = EV::Prepare PREFIX = evcheck_ 666MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_
536 667
537void evprepare_start (struct ev_prepare *w) 668void ev_prepare_start (struct ev_prepare *w)
538 669
539void evprepare_stop (struct ev_prepare *w) 670void ev_prepare_stop (struct ev_prepare *w)
540 671
672void DESTROY (struct ev_prepare *w)
673 CODE:
674 ev_prepare_stop (w);
675 e_destroy (w);
676
541MODULE = EV PACKAGE = EV::Check PREFIX = evcheck_ 677MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_
542 678
543void evcheck_start (struct ev_check *w) 679void ev_check_start (struct ev_check *w)
544 680
545void evcheck_stop (struct ev_check *w) 681void ev_check_stop (struct ev_check *w)
546 682
683void DESTROY (struct ev_check *w)
684 CODE:
685 ev_check_stop (w);
686 e_destroy (w);
687
547MODULE = EV PACKAGE = EV::Child PREFIX = evchild_ 688MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
548 689
549void evchild_start (struct ev_child *w) 690void ev_child_start (struct ev_child *w)
550 691
551void evchild_stop (struct ev_child *w) 692void ev_child_stop (struct ev_child *w)
693
694void DESTROY (struct ev_child *w)
695 CODE:
696 ev_child_stop (w);
697 e_destroy (w);
552 698
553void set (struct ev_child *w, int pid) 699void set (struct ev_child *w, int pid)
554 CODE: 700 CODE:
555{ 701{
556 int active = w->active; 702 int active = ev_is_active (w);
557 if (active) evchild_stop (w); 703 if (active) ev_child_stop (w);
704
558 evchild_set (w, pid); 705 ev_child_set (w, pid);
706
559 if (active) evchild_start (w); 707 if (active) ev_child_start (w);
560} 708}
561 709
562#if 0 710int pid (struct ev_child *w, int new_pid = 0)
711 CODE:
712{
713 RETVAL = w->pid;
714
715 if (items > 1)
716 {
717 int active = ev_is_active (w);
718 if (active) ev_child_stop (w);
719
720 ev_child_set (w, new_pid);
721
722 if (active) ev_child_start (w);
723 }
724}
725 OUTPUT:
726 RETVAL
727
728
729int rstatus (struct ev_child *w)
730 ALIAS:
731 rpid = 1
732 CODE:
733 RETVAL = ix ? w->rpid : w->rstatus;
734 OUTPUT:
735 RETVAL
736
737#ifndef WIN32
563 738
564MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ 739MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_
565 740
566BOOT: 741BOOT:
567{ 742{
650 825
651void evdns_search_add (char *domain) 826void evdns_search_add (char *domain)
652 827
653void evdns_search_ndots_set (int ndots) 828void evdns_search_ndots_set (int ndots)
654 829
830#if 0
655 831
656MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ 832MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
657 833
658BOOT: 834BOOT:
659{ 835{
691 867
692#void DESTROY (struct evhttp_request *req); 868#void DESTROY (struct evhttp_request *req);
693 869
694#endif 870#endif
695 871
872#endif
696 873
697 874
698 875
699 876
700 877

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines