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

Comparing EV/EV.xs (file contents):
Revision 1.76 by root, Fri Nov 23 13:08:56 2007 UTC vs.
Revision 1.164 by root, Fri Apr 5 21:04:18 2013 UTC

1#include "EXTERN.h" 1#include "EXTERN.h"
2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4 4
5/*#include <netinet/in.h>*/
6
7#define EV_PROTOTYPES 1
8#include "EV/EVAPI.h"
9
10/* fix perl api breakage */ 5/* fix perl api breakage */
11#undef signal 6#undef signal
12#undef sigaction 7#undef sigaction
8
9#include "schmorp.h"
10
11/* old API compatibility */
12static int
13sv_fileno (SV *fh)
14{
15 return s_fileno (fh, 0);
16}
17
18#ifndef GvCV_set
19# define GvCV_set(gv,cv) GvCV (gv) = cv
20#endif
21
22#define EV_STANDALONE 1
23#define EV_PROTOTYPES 1
24#define EV_USE_NANOSLEEP EV_USE_MONOTONIC
25#define EV_USE_FLOOR 1
26#define EV_API_STATIC
27#define EV_H <ev.h>
28#define EV_CONFIG_H error
29#include "EV/EVAPI.h"
13 30
14#define EV_SELECT_IS_WINSOCKET 0 31#define EV_SELECT_IS_WINSOCKET 0
15#ifdef _WIN32 32#ifdef _WIN32
16# define EV_SELECT_USE_FD_SET 0 33# define EV_SELECT_USE_FD_SET 0
17# define NFDBITS PERL_NFDBITS 34# define NFDBITS PERL_NFDBITS
18# define fd_mask Perl_fd_mask 35# define fd_mask Perl_fd_mask
19#endif 36#endif
20/* due to bugs in OS X we have to use libev/ explicitly here */ 37/* due to bugs in OS X we have to use libev/ explicitly here */
21#include "libev/ev.c" 38#include "libev/ev.c"
22#include "event.c"
23 39
24#ifndef _WIN32
25#define DNS_USE_GETTIMEOFDAY_FOR_ID 1
26#if !defined (WIN32) && !defined(__CYGWIN__) 40#if !defined _WIN32 && !defined _MINIX
27# define HAVE_STRUCT_IN6_ADDR 1
28#endif
29#undef HAVE_STRTOK_R
30#undef strtok_r
31#define strtok_r fake_strtok_r
32#include "evdns.h"
33#include "evdns.c"
34#endif
35
36#ifndef _WIN32
37# include <pthread.h> 41# include <pthread.h>
38#endif 42#endif
39 43
44#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop))
45#define e_flags(w) ((ev_watcher *)(w))->e_flags
46#define e_self(w) ((ev_watcher *)(w))->self
47#define e_fh(w) ((ev_watcher *)(w))->fh
48#define e_data(w) ((ev_watcher *)(w))->data
49
50#define WFLAG_KEEPALIVE 1
51#define WFLAG_UNREFED 2 /* has been unref'ed */
52#define WFLAG_NOARGS 4 /* do not pass anything to the callback */
53
54#define UNREF(w) \
55 if (!(e_flags (w) & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \
56 && ev_is_active (w)) \
57 { \
58 ev_unref (e_loop (w)); \
59 e_flags (w) |= WFLAG_UNREFED; \
60 }
61
62#define REF(w) \
63 if (e_flags (w) & WFLAG_UNREFED) \
64 { \
65 e_flags (w) &= ~WFLAG_UNREFED; \
66 ev_ref (e_loop (w)); \
67 }
68
69#define START(type,w) \
70 do { \
71 ev_ ## type ## _start (e_loop (w), w); \
72 UNREF (w); \
73 } while (0)
74
75#define STOP(type,w) \
76 do { \
77 REF (w); \
78 ev_ ## type ## _stop (e_loop (w), w); \
79 } while (0)
80
81#define RESET(type,w,seta) \
82 do { \
83 int active = ev_is_active (w); \
84 if (active) STOP (type, w); \
85 ev_ ## type ## _set seta; \
86 if (active) START (type, w); \
87 } while (0)
88
40typedef int Signal; 89typedef int Signal;
41 90
91/* horrible... */
92#define CHECK_SIGNAL_CAN_START(w) \
93 do { \
94 /* dive into the internals of libev to avoid aborting in libev */ \
95 if (signals [(w)->signum - 1].loop \
96 && signals [(w)->signum - 1].loop != e_loop (w)) \
97 croak ("unable to start signal watcher, signal %d already registered in another loop", w->signum); \
98 } while (0)
99
100#define START_SIGNAL(w) \
101 do { \
102 CHECK_SIGNAL_CAN_START (w); \
103 START (signal, w); \
104 } while (0) \
105
106#define RESET_SIGNAL(w,seta) \
107 do { \
108 int active = ev_is_active (w); \
109 if (active) STOP (signal, w); \
110 ev_ ## signal ## _set seta; \
111 if (active) START_SIGNAL (w); \
112 } while (0)
113
114static SV *default_loop_sv;
115
42static struct EVAPI evapi; 116static struct EVAPI evapi;
43 117
44static HV 118static HV
119 *stash_loop,
45 *stash_watcher, 120 *stash_watcher,
46 *stash_io, 121 *stash_io,
47 *stash_timer, 122 *stash_timer,
48 *stash_periodic, 123 *stash_periodic,
49 *stash_signal, 124 *stash_signal,
125 *stash_child,
126 *stash_stat,
50 *stash_idle, 127 *stash_idle,
51 *stash_prepare, 128 *stash_prepare,
52 *stash_check, 129 *stash_check,
53 *stash_child; 130 *stash_embed,
54 131 *stash_fork,
55#ifndef SIG_SIZE 132 *stash_cleanup,
56/* kudos to Slaven Rezic for the idea */ 133 *stash_async;
57static char sig_size [] = { SIG_NUM };
58# define SIG_SIZE (sizeof (sig_size) + 1)
59#endif
60
61static int
62sv_signum (SV *sig)
63{
64 int signum;
65
66 SvGETMAGIC (sig);
67
68 for (signum = 1; signum < SIG_SIZE; ++signum)
69 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum]))
70 return signum;
71
72 if (SvIV (sig) > 0)
73 return SvIV (sig);
74
75 return -1;
76}
77 134
78///////////////////////////////////////////////////////////////////////////// 135/////////////////////////////////////////////////////////////////////////////
79// Event 136// Event
80 137
81static void e_cb (struct ev_watcher *w, int revents); 138static void e_cb (EV_P_ ev_watcher *w, int revents);
82
83static int
84sv_fileno (SV *fh)
85{
86 SvGETMAGIC (fh);
87
88 if (SvROK (fh))
89 fh = SvRV (fh);
90
91 if (SvTYPE (fh) == SVt_PVGV)
92 return PerlIO_fileno (IoIFP (sv_2io (fh)));
93
94 if (SvOK (fh) && (SvIV (fh) >= 0) && (SvIV (fh) < 0x7fffffffL))
95 return SvIV (fh);
96
97 return -1;
98}
99 139
100static void * 140static void *
101e_new (int size, SV *cb_sv) 141e_new (int size, SV *cb_sv, SV *loop)
102{ 142{
143 SV *cv = cb_sv ? s_get_cv_croak (cb_sv) : 0;
103 struct ev_watcher *w; 144 ev_watcher *w;
104 SV *self = NEWSV (0, size); 145 SV *self = NEWSV (0, size);
105 SvPOK_only (self); 146 SvPOK_only (self);
106 SvCUR_set (self, size); 147 SvCUR_set (self, size);
107 148
108 w = (struct ev_watcher *)SvPVX (self); 149 w = (ev_watcher *)SvPVX (self);
109 150
110 ev_init (w, e_cb); 151 ev_init (w, cv ? e_cb : 0);
111 152
153 w->loop = SvREFCNT_inc (SvRV (loop));
154 w->e_flags = WFLAG_KEEPALIVE;
112 w->data = 0; 155 w->data = 0;
113 w->fh = 0; 156 w->fh = 0;
114 w->cb_sv = newSVsv (cb_sv); 157 w->cb_sv = SvREFCNT_inc (cv);
115 w->self = self; 158 w->self = self;
116 159
117 return (void *)w; 160 return (void *)w;
118} 161}
119 162
120static void 163static void
121e_destroy (void *w_) 164e_destroy (void *w_)
122{ 165{
123 struct ev_watcher *w = (struct ev_watcher *)w_; 166 ev_watcher *w = (ev_watcher *)w_;
124 167
168 SvREFCNT_dec (w->loop ); w->loop = 0;
125 SvREFCNT_dec (w->fh ); w->fh = 0; 169 SvREFCNT_dec (w->fh ); w->fh = 0;
126 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; 170 SvREFCNT_dec (w->cb_sv); w->cb_sv = 0;
127 SvREFCNT_dec (w->data ); w->data = 0; 171 SvREFCNT_dec (w->data ); w->data = 0;
128} 172}
129 173
130static SV * 174static SV *
131e_bless (struct ev_watcher *w, HV *stash) 175e_bless (ev_watcher *w, HV *stash)
132{ 176{
133 SV *rv; 177 SV *rv;
134 178
135 if (SvOBJECT (w->self)) 179 if (SvOBJECT (w->self))
136 rv = newRV_inc (w->self); 180 rv = newRV_inc (w->self);
142 } 186 }
143 187
144 return rv; 188 return rv;
145} 189}
146 190
147static SV *sv_events_cache; 191static SV *sv_self_cache, *sv_events_cache;
148 192
149static void 193static void
150e_cb (struct ev_watcher *w, int revents) 194e_cb (EV_P_ ev_watcher *w, int revents)
151{ 195{
152 dSP; 196 dSP;
153 I32 mark = SP - PL_stack_base; 197 I32 mark = SP - PL_stack_base;
154 SV *sv_self, *sv_events; 198 SV *sv_self, *sv_events;
155 199
200 /* libev might have stopped the watcher */
201 if (expect_false (w->e_flags & WFLAG_UNREFED)
202 && !ev_is_active (w))
203 REF (w);
204
205 PUSHMARK (SP);
206
207 if (!expect_true (e_flags (w) & WFLAG_NOARGS))
208 {
209 if (expect_true (sv_self_cache))
210 {
211 sv_self = sv_self_cache; sv_self_cache = 0;
212 SvRV_set (sv_self, SvREFCNT_inc_NN (w->self));
213 }
214 else
215 {
156 sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ 216 sv_self = newRV_inc (w->self); /* e_self (w) MUST be blessed by now */
217 SvREADONLY_on (sv_self);
218 }
219
220 if (expect_true (sv_events_cache))
221 {
222 sv_events = sv_events_cache; sv_events_cache = 0;
223 SvIV_set (sv_events, revents);
224 SvIOK_only (sv_events);
225 }
226 else
227 {
228 sv_events = newSViv (revents);
229 SvREADONLY_on (sv_events);
230 }
231
232 EXTEND (SP, 2);
233 PUSHs (sv_self);
234 PUSHs (sv_events);
235
236 PUTBACK;
237 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
238
239 if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache))
240 SvREFCNT_dec (sv_self);
241 else
242 {
243 SvREFCNT_dec (SvRV (sv_self));
244 SvRV_set (sv_self, &PL_sv_undef);
245 sv_self_cache = sv_self;
246 }
247
248 if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache))
249 SvREFCNT_dec (sv_events);
250 else
251 sv_events_cache = sv_events;
252 }
253 else
254 {
255 EXTEND (SP, 2);
256 PUSHs (sv_self);
257 PUSHs (sv_events);
258
259 PUTBACK;
260 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
261 }
262
263 if (expect_false (SvTRUE (ERRSV)))
264 {
265 SPAGAIN;
266 PUSHMARK (SP);
267 PUTBACK;
268 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
269 }
270
271 SP = PL_stack_base + mark;
272 PUTBACK;
273}
274
275static void
276e_once_cb (int revents, void *arg)
277{
278 dSP;
279 I32 mark = SP - PL_stack_base;
280 SV *sv_events;
157 281
158 if (sv_events_cache) 282 if (sv_events_cache)
159 { 283 {
160 sv_events = sv_events_cache; sv_events_cache = 0; 284 sv_events = sv_events_cache; sv_events_cache = 0;
161 SvIV_set (sv_events, revents); 285 SvIV_set (sv_events, revents);
162 } 286 }
163 else 287 else
164 sv_events = newSViv (revents); 288 sv_events = newSViv (revents);
165 289
166 PUSHMARK (SP); 290 PUSHMARK (SP);
167 EXTEND (SP, 2);
168 PUSHs (sv_self);
169 PUSHs (sv_events); 291 XPUSHs (sv_events);
170 292
171 PUTBACK; 293 PUTBACK;
172 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); 294 call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL);
173 295
174 SvREFCNT_dec (sv_self); 296 SvREFCNT_dec ((SV *)arg);
175 297
176 if (sv_events_cache) 298 if (sv_events_cache)
177 SvREFCNT_dec (sv_events); 299 SvREFCNT_dec (sv_events);
178 else 300 else
179 sv_events_cache = sv_events; 301 sv_events_cache = sv_events;
180 302
181 if (SvTRUE (ERRSV)) 303 if (SvTRUE (ERRSV))
182 { 304 {
305 SPAGAIN;
183 PUSHMARK (SP); 306 PUSHMARK (SP);
184 PUTBACK; 307 PUTBACK;
185 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 308 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
186 } 309 }
187 310
188 SP = PL_stack_base + mark; 311 SP = PL_stack_base + mark;
189 PUTBACK; 312 PUTBACK;
190} 313}
191 314
192static void
193e_once_cb (int revents, void *arg)
194{
195 dSP;
196 I32 mark = SP - PL_stack_base;
197 SV *sv_events;
198
199 if (sv_events_cache)
200 {
201 sv_events = sv_events_cache; sv_events_cache = 0;
202 SvIV_set (sv_events, revents);
203 }
204 else
205 sv_events = newSViv (revents);
206
207 PUSHMARK (SP);
208 XPUSHs (sv_events);
209
210 PUTBACK;
211 call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL);
212
213 SvREFCNT_dec ((SV *)arg);
214
215 if (sv_events_cache)
216 SvREFCNT_dec (sv_events);
217 else
218 sv_events_cache = sv_events;
219
220 if (SvTRUE (ERRSV))
221 {
222 PUSHMARK (SP);
223 PUTBACK;
224 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
225 }
226
227 SP = PL_stack_base + mark;
228 PUTBACK;
229}
230
231static ev_tstamp 315static ev_tstamp
232e_periodic_cb (struct ev_periodic *w, ev_tstamp now) 316e_periodic_cb (ev_periodic *w, ev_tstamp now)
233{ 317{
234 ev_tstamp retval; 318 ev_tstamp retval;
235 int count; 319 int count;
236 dSP; 320 dSP;
237 321
238 ENTER; 322 ENTER;
239 SAVETMPS; 323 SAVETMPS;
240 324
241 PUSHMARK (SP); 325 PUSHMARK (SP);
242 EXTEND (SP, 2); 326 EXTEND (SP, 2);
243 PUSHs (newRV_inc (w->self)); /* w->self MUST be blessed by now */ 327 PUSHs (newRV_inc (e_self (w))); /* e_self (w) MUST be blessed by now */
244 PUSHs (newSVnv (now)); 328 PUSHs (newSVnv (now));
245 329
246 PUTBACK; 330 PUTBACK;
247 count = call_sv (w->fh, G_SCALAR | G_EVAL); 331 count = call_sv (w->fh, G_SCALAR | G_EVAL);
248 SPAGAIN; 332 SPAGAIN;
269 LEAVE; 353 LEAVE;
270 354
271 return retval; 355 return retval;
272} 356}
273 357
274/////////////////////////////////////////////////////////////////////////////
275// DNS
276
277#ifndef _WIN32
278static void
279dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg)
280{
281 dSP;
282 SV *cb = (SV *)arg;
283
284 ENTER;
285 SAVETMPS;
286 PUSHMARK (SP);
287 EXTEND (SP, count + 3);
288 PUSHs (sv_2mortal (newSViv (result)));
289
290 if (result == DNS_ERR_NONE && ttl >= 0)
291 {
292 int i;
293
294 PUSHs (sv_2mortal (newSViv (type)));
295 PUSHs (sv_2mortal (newSViv (ttl)));
296
297 for (i = 0; i < count; ++i)
298 switch (type)
299 {
300 case DNS_IPv6_AAAA:
301 PUSHs (sv_2mortal (newSVpvn (i * 16 + (char *)addresses, 16)));
302 break;
303 case DNS_IPv4_A:
304 PUSHs (sv_2mortal (newSVpvn (i * 4 + (char *)addresses, 4)));
305 break;
306 case DNS_PTR:
307 PUSHs (sv_2mortal (newSVpv (*(char **)addresses, 0)));
308 break;
309 }
310 }
311
312 PUTBACK;
313 call_sv (sv_2mortal (cb), G_DISCARD | G_VOID | G_EVAL);
314
315 FREETMPS;
316
317 if (SvTRUE (ERRSV))
318 {
319 PUSHMARK (SP);
320 PUTBACK;
321 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
322 }
323
324 LEAVE;
325}
326#endif
327
328#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 358#define CHECK_REPEAT(repeat) if (repeat < 0.) \
329 croak (# repeat " value must be >= 0"); 359 croak (# repeat " value must be >= 0");
330 360
331#define CHECK_FD(fh,fd) if ((fd) < 0) \ 361#define CHECK_FD(fh,fd) if ((fd) < 0) \
332 croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh)); 362 croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh));
363
364#define CHECK_SIG(sv,num) if ((num) < 0) \
365 croak ("illegal signal number or name: %s", SvPV_nolen (sv));
366
367static void
368default_fork (void)
369{
370 ev_loop_fork (EV_DEFAULT_UC);
371}
333 372
334///////////////////////////////////////////////////////////////////////////// 373/////////////////////////////////////////////////////////////////////////////
335// XS interface functions 374// XS interface functions
336 375
337MODULE = EV PACKAGE = EV PREFIX = ev_ 376MODULE = EV PACKAGE = EV PREFIX = ev_
350 const_iv (EV_, MINPRI) 389 const_iv (EV_, MINPRI)
351 const_iv (EV_, MAXPRI) 390 const_iv (EV_, MAXPRI)
352 391
353 const_iv (EV_, UNDEF) 392 const_iv (EV_, UNDEF)
354 const_iv (EV_, NONE) 393 const_iv (EV_, NONE)
355 const_iv (EV_, TIMEOUT)
356 const_iv (EV_, READ) 394 const_iv (EV_, READ)
357 const_iv (EV_, WRITE) 395 const_iv (EV_, WRITE)
396 const_iv (EV_, IO)
397 const_iv (EV_, TIMER)
398 const_iv (EV_, PERIODIC)
358 const_iv (EV_, SIGNAL) 399 const_iv (EV_, SIGNAL)
400 const_iv (EV_, CHILD)
401 const_iv (EV_, STAT)
359 const_iv (EV_, IDLE) 402 const_iv (EV_, IDLE)
403 const_iv (EV_, PREPARE)
404 /*const_iv (EV_, CHECK) needs special tretament */
405 const_iv (EV_, EMBED)
360 const_iv (EV_, CHECK) 406 const_iv (EV_, FORK)
407 const_iv (EV_, CLEANUP)
408 const_iv (EV_, ASYNC)
409 const_iv (EV_, CUSTOM)
361 const_iv (EV_, ERROR) 410 const_iv (EV_, ERROR)
362 411
363 const_iv (EV, LOOP_ONESHOT) 412 const_iv (EV, RUN_NOWAIT)
364 const_iv (EV, LOOP_NONBLOCK)
365 const_iv (EV, UNLOOP_ONE) 413 const_iv (EV, RUN_ONCE)
414
415 const_iv (EV, BREAK_CANCEL)
416 const_iv (EV, BREAK_ONE)
366 const_iv (EV, UNLOOP_ALL) 417 const_iv (EV, BREAK_ALL)
367
368 const_iv (EV, BACKEND_SELECT) 418 const_iv (EV, BACKEND_SELECT)
369 const_iv (EV, BACKEND_POLL) 419 const_iv (EV, BACKEND_POLL)
370 const_iv (EV, BACKEND_EPOLL) 420 const_iv (EV, BACKEND_EPOLL)
371 const_iv (EV, BACKEND_KQUEUE) 421 const_iv (EV, BACKEND_KQUEUE)
372 const_iv (EV, BACKEND_DEVPOLL) 422 const_iv (EV, BACKEND_DEVPOLL)
373 const_iv (EV, BACKEND_PORT) 423 const_iv (EV, BACKEND_PORT)
424 const_iv (EV, BACKEND_ALL)
425 const_iv (EV, BACKEND_MASK)
374 const_iv (EV, FLAG_AUTO) 426 const_iv (EV, FLAG_AUTO)
427 const_iv (EV, FLAG_FORKCHECK)
428 const_iv (EV, FLAG_SIGNALFD)
429 const_iv (EV, FLAG_NOSIGMASK)
375 const_iv (EV, FLAG_NOENV) 430 const_iv (EV, FLAG_NOENV)
431 const_iv (EV, FLAG_NOINOTIFY)
432
433 const_iv (EV_, VERSION_MAJOR)
434 const_iv (EV_, VERSION_MINOR)
435#if EV_COMPAT3
436 const_iv (EV, FLAG_NOSIGFD) /* compatibility, always 0 */
437 const_iv (EV_, TIMEOUT)
438 const_iv (EV, LOOP_NONBLOCK)
439 const_iv (EV, LOOP_ONESHOT)
440 const_iv (EV, UNLOOP_CANCEL)
441 const_iv (EV, UNLOOP_ONE)
442 const_iv (EV, UNLOOP_ALL)
443#endif
376 }; 444 };
377 445
378 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 446 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
379 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 447 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
380 448
449 /* since this clashes with perl CHECK blocks, */
450 /* but we are interested in constants, */
451 /* and not blocks, we treat CHECK specially. */
452 {
453 /* the local $^W = 0 takes care of the warning */
454 CV *cv = newCONSTSUB (stash, "CHECK", newSViv (EV_CHECK));
455 /* now we need to re-set the gv, in case it was hijacked */
456 GvCV_set (gv_fetchpv ("EV::CHECK", GV_ADD, SVt_PVCV), cv);
457 }
458
459 stash_loop = gv_stashpv ("EV::Loop" , 1);
381 stash_watcher = gv_stashpv ("EV::Watcher" , 1); 460 stash_watcher = gv_stashpv ("EV::Watcher" , 1);
382 stash_io = gv_stashpv ("EV::Io" , 1); 461 stash_io = gv_stashpv ("EV::IO" , 1);
383 stash_timer = gv_stashpv ("EV::Timer" , 1); 462 stash_timer = gv_stashpv ("EV::Timer" , 1);
384 stash_periodic = gv_stashpv ("EV::Periodic", 1); 463 stash_periodic = gv_stashpv ("EV::Periodic", 1);
385 stash_signal = gv_stashpv ("EV::Signal" , 1); 464 stash_signal = gv_stashpv ("EV::Signal" , 1);
386 stash_idle = gv_stashpv ("EV::Idle" , 1); 465 stash_idle = gv_stashpv ("EV::Idle" , 1);
387 stash_prepare = gv_stashpv ("EV::Prepare" , 1); 466 stash_prepare = gv_stashpv ("EV::Prepare" , 1);
388 stash_check = gv_stashpv ("EV::Check" , 1); 467 stash_check = gv_stashpv ("EV::Check" , 1);
389 stash_child = gv_stashpv ("EV::Child" , 1); 468 stash_child = gv_stashpv ("EV::Child" , 1);
469 stash_embed = gv_stashpv ("EV::Embed" , 1);
470 stash_stat = gv_stashpv ("EV::Stat" , 1);
471 stash_fork = gv_stashpv ("EV::Fork" , 1);
472 stash_cleanup = gv_stashpv ("EV::Cleanup" , 1);
473 stash_async = gv_stashpv ("EV::Async" , 1);
390 474
391 { 475 {
392 SV *sv = perl_get_sv ("EV::API", TRUE); 476 SV *sv = perl_get_sv ("EV::API", TRUE);
393 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 477 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
394 478
395 /* the poor man's shared library emulator */ 479 /* the poor man's shared library emulator */
396 evapi.ver = EV_API_VERSION; 480 evapi.ver = EV_API_VERSION;
397 evapi.rev = EV_API_REVISION; 481 evapi.rev = EV_API_REVISION;
398 evapi.sv_fileno = sv_fileno; 482 evapi.sv_fileno = sv_fileno;
399 evapi.sv_signum = sv_signum; 483 evapi.sv_signum = s_signum;
484 evapi.supported_backends = ev_supported_backends ();
485 evapi.recommended_backends = ev_recommended_backends ();
486 evapi.embeddable_backends = ev_embeddable_backends ();
487 evapi.time_ = ev_time;
488 evapi.sleep_ = ev_sleep;
489 evapi.loop_new = ev_loop_new;
490 evapi.loop_destroy = ev_loop_destroy;
491 evapi.loop_fork = ev_loop_fork;
492 evapi.iteration = ev_iteration;
493 evapi.depth = ev_depth;
494 evapi.set_userdata = ev_set_userdata;
495 evapi.userdata = ev_userdata;
400 evapi.now = ev_now; 496 evapi.now = ev_now;
497 evapi.now_update = ev_now_update;
498 evapi.suspend = ev_suspend;
499 evapi.resume = ev_resume;
401 evapi.backend = ev_backend; 500 evapi.backend = ev_backend;
402 evapi.unloop = ev_unloop; 501 evapi.break_ = ev_break;
502 evapi.invoke_pending = ev_invoke_pending;
503 evapi.pending_count = ev_pending_count;
504 evapi.verify = ev_verify;
505 evapi.set_loop_release_cb = ev_set_loop_release_cb;
506 evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb;
403 evapi.time = ev_time; 507 evapi.ref = ev_ref;
404 evapi.loop = ev_loop; 508 evapi.unref = ev_unref;
509 evapi.run = ev_run;
405 evapi.once = ev_once; 510 evapi.once = ev_once;
406 evapi.io_start = ev_io_start; 511 evapi.io_start = ev_io_start;
407 evapi.io_stop = ev_io_stop; 512 evapi.io_stop = ev_io_stop;
408 evapi.timer_start = ev_timer_start; 513 evapi.timer_start = ev_timer_start;
409 evapi.timer_stop = ev_timer_stop; 514 evapi.timer_stop = ev_timer_stop;
410 evapi.timer_again = ev_timer_again; 515 evapi.timer_again = ev_timer_again;
516 evapi.timer_remaining = ev_timer_remaining;
411 evapi.periodic_start = ev_periodic_start; 517 evapi.periodic_start = ev_periodic_start;
412 evapi.periodic_stop = ev_periodic_stop; 518 evapi.periodic_stop = ev_periodic_stop;
413 evapi.signal_start = ev_signal_start; 519 evapi.signal_start = ev_signal_start;
414 evapi.signal_stop = ev_signal_stop; 520 evapi.signal_stop = ev_signal_stop;
415 evapi.idle_start = ev_idle_start; 521 evapi.idle_start = ev_idle_start;
416 evapi.idle_stop = ev_idle_stop; 522 evapi.idle_stop = ev_idle_stop;
417 evapi.prepare_start = ev_prepare_start; 523 evapi.prepare_start = ev_prepare_start;
418 evapi.prepare_stop = ev_prepare_stop; 524 evapi.prepare_stop = ev_prepare_stop;
419 evapi.check_start = ev_check_start; 525 evapi.check_start = ev_check_start;
420 evapi.check_stop = ev_check_stop; 526 evapi.check_stop = ev_check_stop;
527#if EV_CHILD_ENABLE
421 evapi.child_start = ev_child_start; 528 evapi.child_start = ev_child_start;
422 evapi.child_stop = ev_child_stop; 529 evapi.child_stop = ev_child_stop;
530#endif
531 evapi.stat_start = ev_stat_start;
532 evapi.stat_stop = ev_stat_stop;
533 evapi.stat_stat = ev_stat_stat;
534 evapi.embed_start = ev_embed_start;
535 evapi.embed_stop = ev_embed_stop;
536 evapi.embed_sweep = ev_embed_sweep;
537 evapi.fork_start = ev_fork_start;
538 evapi.fork_stop = ev_fork_stop;
539 evapi.cleanup_start = ev_cleanup_start;
540 evapi.cleanup_stop = ev_cleanup_stop;
541 evapi.async_start = ev_async_start;
542 evapi.async_stop = ev_async_stop;
543 evapi.async_send = ev_async_send;
544 evapi.clear_pending = ev_clear_pending;
545 evapi.invoke = ev_invoke;
423 546
424 sv_setiv (sv, (IV)&evapi); 547 sv_setiv (sv, (IV)&evapi);
425 SvREADONLY_on (sv); 548 SvREADONLY_on (sv);
426 } 549 }
427#ifndef _WIN32 550#if !defined _WIN32 && !defined _MINIX
551#if __linux
552 int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void * __dso_handle);
553 __register_atfork (0, 0, default_fork, 0);
554#else
428 pthread_atfork (0, 0, ev_default_fork); 555 pthread_atfork (0, 0, default_fork);
429#endif 556#endif
557#endif
558}
559
560SV *ev_default_loop (unsigned int flags = 0)
561 CODE:
562{
563 if (!default_loop_sv)
564 {
565 evapi.default_loop = ev_default_loop (flags);
566
567 if (!evapi.default_loop)
568 XSRETURN_UNDEF;
569
570 default_loop_sv = sv_bless (newRV_noinc (newSViv (PTR2IV (evapi.default_loop))), stash_loop);
571 }
572
573 RETVAL = newSVsv (default_loop_sv);
574}
575 OUTPUT:
576 RETVAL
577
578void ev_default_destroy ()
579 CODE:
580 ev_loop_destroy (EV_DEFAULT_UC);
581 SvREFCNT_dec (default_loop_sv);
582 default_loop_sv = 0;
583
584unsigned int ev_supported_backends ()
585
586unsigned int ev_recommended_backends ()
587
588unsigned int ev_embeddable_backends ()
589
590void ev_sleep (NV interval)
591
592NV ev_time ()
593
594void ev_feed_signal (SV *signal)
595 CODE:
596{
597 Signal signum = s_signum (signal);
598 CHECK_SIG (signal, signum);
599
600 ev_feed_signal (signum);
430} 601}
431 602
432NV ev_now () 603NV ev_now ()
604 C_ARGS: evapi.default_loop
605
606void ev_now_update ()
607 C_ARGS: evapi.default_loop
608
609void ev_suspend ()
610 C_ARGS: evapi.default_loop
611
612void ev_resume ()
613 C_ARGS: evapi.default_loop
433 614
434unsigned int ev_backend () 615unsigned int ev_backend ()
616 C_ARGS: evapi.default_loop
435 617
436NV ev_time () 618void ev_verify ()
619 ALIAS:
620 loop_verify = 1
621 C_ARGS: evapi.default_loop
437 622
438unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) 623unsigned int ev_iteration ()
624 ALIAS:
625 loop_count = 1
626 C_ARGS: evapi.default_loop
439 627
628unsigned int ev_depth ()
629 ALIAS:
630 loop_depth = 1
631 C_ARGS: evapi.default_loop
632
633void ev_set_io_collect_interval (NV interval)
634 C_ARGS: evapi.default_loop, interval
635
636void ev_set_timeout_collect_interval (NV interval)
637 C_ARGS: evapi.default_loop, interval
638
440void ev_loop (int flags = 0) 639int ev_run (int flags = 0)
640 ALIAS:
641 loop = 1
642 C_ARGS: evapi.default_loop, flags
441 643
442void ev_unloop (int how = 1) 644void ev_break (int how = EVBREAK_ONE)
645 ALIAS:
646 unloop = 1
647 C_ARGS: evapi.default_loop, how
443 648
649void ev_feed_fd_event (int fd, int revents = EV_NONE)
650 C_ARGS: evapi.default_loop, fd, revents
651
652void ev_feed_signal_event (SV *signal)
653 CODE:
654{
655 Signal signum = s_signum (signal);
656 CHECK_SIG (signal, signum);
657
658 ev_feed_signal_event (evapi.default_loop, signum);
659}
660
661unsigned int ev_pending_count ()
662 C_ARGS: evapi.default_loop
663
664void ev_invoke_pending ()
665 C_ARGS: evapi.default_loop
666
444struct ev_io *io (SV *fh, int events, SV *cb) 667ev_io *io (SV *fh, int events, SV *cb)
445 ALIAS: 668 ALIAS:
446 io_ns = 1 669 io_ns = 1
670 _ae_io = 2
447 CODE: 671 CODE:
448{ 672{
449 int fd = sv_fileno (fh); 673 int fd = s_fileno (fh, events & EV_WRITE);
450 CHECK_FD (fh, fd); 674 CHECK_FD (fh, fd);
451
452 RETVAL = e_new (sizeof (struct ev_io), cb); 675 RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv);
453 RETVAL->fh = newSVsv (fh); 676 e_fh (RETVAL) = newSVsv (fh);
677
678 if (ix == 2)
679 {
680 events = events ? EV_WRITE : EV_READ;
681 e_flags (RETVAL) |= WFLAG_NOARGS;
682 }
683
454 ev_io_set (RETVAL, fd, events); 684 ev_io_set (RETVAL, fd, events);
455 if (!ix) ev_io_start (RETVAL); 685 if (ix != 1) START (io, RETVAL);
456} 686}
457 OUTPUT: 687 OUTPUT:
458 RETVAL 688 RETVAL
459 689
460struct ev_timer *timer (NV after, NV repeat, SV *cb) 690ev_timer *timer (NV after, NV repeat, SV *cb)
461 ALIAS: 691 ALIAS:
462 timer_ns = 1 692 timer_ns = 1
463 INIT: 693 INIT:
464 CHECK_REPEAT (repeat); 694 CHECK_REPEAT (repeat);
465 CODE: 695 CODE:
466 RETVAL = e_new (sizeof (struct ev_timer), cb); 696 RETVAL = e_new (sizeof (ev_timer), cb, default_loop_sv);
467 ev_timer_set (RETVAL, after, repeat); 697 ev_timer_set (RETVAL, after, repeat);
468 if (!ix) ev_timer_start (RETVAL); 698 if (!ix) START (timer, RETVAL);
469 OUTPUT: 699 OUTPUT:
470 RETVAL 700 RETVAL
471 701
472SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb) 702SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb)
473 ALIAS: 703 ALIAS:
474 periodic_ns = 1 704 periodic_ns = 1
475 INIT: 705 INIT:
476 CHECK_REPEAT (interval); 706 CHECK_REPEAT (interval);
477 CODE: 707 CODE:
478{ 708{
479 struct ev_periodic *w; 709 ev_periodic *w;
480 w = e_new (sizeof (struct ev_periodic), cb); 710 w = e_new (sizeof (ev_periodic), cb, default_loop_sv);
481 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 711 e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
482 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); 712 ev_periodic_set (w, at, interval, e_fh (w) ? e_periodic_cb : 0);
483 RETVAL = e_bless ((struct ev_watcher *)w, stash_periodic); 713 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
484 if (!ix) ev_periodic_start (w); 714 if (!ix) START (periodic, w);
485} 715}
486 OUTPUT: 716 OUTPUT:
487 RETVAL 717 RETVAL
488 718
489struct ev_signal *signal (Signal signum, SV *cb) 719ev_signal *signal (SV *signal, SV *cb)
490 ALIAS: 720 ALIAS:
491 signal_ns = 1 721 signal_ns = 1
492 CODE: 722 CODE:
723{
724 Signal signum = s_signum (signal);
725 CHECK_SIG (signal, signum);
726
493 RETVAL = e_new (sizeof (struct ev_signal), cb); 727 RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv);
494 ev_signal_set (RETVAL, signum); 728 ev_signal_set (RETVAL, signum);
495 if (!ix) ev_signal_start (RETVAL); 729 if (!ix) START_SIGNAL (RETVAL);
730}
496 OUTPUT: 731 OUTPUT:
497 RETVAL 732 RETVAL
498 733
499struct ev_idle *idle (SV *cb) 734ev_idle *idle (SV *cb)
500 ALIAS: 735 ALIAS:
501 idle_ns = 1 736 idle_ns = 1
502 CODE: 737 CODE:
503 RETVAL = e_new (sizeof (struct ev_idle), cb); 738 RETVAL = e_new (sizeof (ev_idle), cb, default_loop_sv);
504 ev_idle_set (RETVAL); 739 ev_idle_set (RETVAL);
505 if (!ix) ev_idle_start (RETVAL); 740 if (!ix) START (idle, RETVAL);
506 OUTPUT: 741 OUTPUT:
507 RETVAL 742 RETVAL
508 743
509struct ev_prepare *prepare (SV *cb) 744ev_prepare *prepare (SV *cb)
510 ALIAS: 745 ALIAS:
511 prepare_ns = 1 746 prepare_ns = 1
512 CODE: 747 CODE:
513 RETVAL = e_new (sizeof (struct ev_prepare), cb); 748 RETVAL = e_new (sizeof (ev_prepare), cb, default_loop_sv);
514 ev_prepare_set (RETVAL); 749 ev_prepare_set (RETVAL);
515 if (!ix) ev_prepare_start (RETVAL); 750 if (!ix) START (prepare, RETVAL);
516 OUTPUT: 751 OUTPUT:
517 RETVAL 752 RETVAL
518 753
519struct ev_check *check (SV *cb) 754ev_check *check (SV *cb)
520 ALIAS: 755 ALIAS:
521 check_ns = 1 756 check_ns = 1
522 CODE: 757 CODE:
523 RETVAL = e_new (sizeof (struct ev_check), cb); 758 RETVAL = e_new (sizeof (ev_check), cb, default_loop_sv);
524 ev_check_set (RETVAL); 759 ev_check_set (RETVAL);
525 if (!ix) ev_check_start (RETVAL); 760 if (!ix) START (check, RETVAL);
526 OUTPUT: 761 OUTPUT:
527 RETVAL 762 RETVAL
528 763
764ev_fork *fork (SV *cb)
765 ALIAS:
766 fork_ns = 1
767 CODE:
768 RETVAL = e_new (sizeof (ev_fork), cb, default_loop_sv);
769 ev_fork_set (RETVAL);
770 if (!ix) START (fork, RETVAL);
771 OUTPUT:
772 RETVAL
773
774#if CLEANUP_ENABLED
775
776ev_cleanup *cleanup (SV *cb)
777 ALIAS:
778 cleanup_ns = 1
779 CODE:
780 RETVAL = e_new (sizeof (ev_cleanup), cb, default_loop_sv);
781 SvREFCNT_dec (RETVAL->loop); /* must not keep loop object alive */
782 ev_cleanup_set (RETVAL);
783 if (!ix) START (cleanup, RETVAL);
784 OUTPUT:
785 RETVAL
786
787#endif
788
529struct ev_child *child (int pid, SV *cb) 789ev_child *child (int pid, int trace, SV *cb)
530 ALIAS: 790 ALIAS:
531 child_ns = 1 791 child_ns = 1
532 CODE: 792 CODE:
793#if EV_CHILD_ENABLE
533 RETVAL = e_new (sizeof (struct ev_child), cb); 794 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
534 ev_child_set (RETVAL, pid); 795 ev_child_set (RETVAL, pid, trace);
535 if (!ix) ev_child_start (RETVAL); 796 if (!ix) START (child, RETVAL);
797#else
798 croak ("EV::child watchers not supported on this platform");
799#endif
800 OUTPUT:
801 RETVAL
802
803
804ev_stat *stat (SV *path, NV interval, SV *cb)
805 ALIAS:
806 stat_ns = 1
807 CODE:
808 RETVAL = e_new (sizeof (ev_stat), cb, default_loop_sv);
809 e_fh (RETVAL) = newSVsv (path);
810 ev_stat_set (RETVAL, SvPVbyte_nolen (e_fh (RETVAL)), interval);
811 if (!ix) START (stat, RETVAL);
812 OUTPUT:
813 RETVAL
814
815#ifndef EV_NO_LOOPS
816
817ev_embed *embed (struct ev_loop *loop, SV *cb = 0)
818 ALIAS:
819 embed_ns = 1
820 CODE:
821{
822 if (!(ev_backend (loop) & ev_embeddable_backends ()))
823 croak ("passed loop is not embeddable via EV::embed,");
824
825 RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv);
826 e_fh (RETVAL) = newSVsv (ST (0));
827 ev_embed_set (RETVAL, loop);
828 if (!ix) START (embed, RETVAL);
829}
830 OUTPUT:
831 RETVAL
832
833#endif
834
835ev_async *async (SV *cb)
836 ALIAS:
837 async_ns = 1
838 CODE:
839 RETVAL = e_new (sizeof (ev_async), cb, default_loop_sv);
840 ev_async_set (RETVAL);
841 if (!ix) START (async, RETVAL);
536 OUTPUT: 842 OUTPUT:
537 RETVAL 843 RETVAL
538 844
539void once (SV *fh, int events, SV *timeout, SV *cb) 845void once (SV *fh, int events, SV *timeout, SV *cb)
540 CODE: 846 CODE:
541 ev_once ( 847 ev_once (
848 evapi.default_loop,
542 sv_fileno (fh), events, 849 s_fileno (fh, events & EV_WRITE), events,
543 SvOK (timeout) ? SvNV (timeout) : -1., 850 SvOK (timeout) ? SvNV (timeout) : -1.,
544 e_once_cb, 851 e_once_cb,
545 newSVsv (cb) 852 newSVsv (cb)
546 ); 853 );
547 854
548PROTOTYPES: DISABLE 855PROTOTYPES: DISABLE
549 856
550MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ 857MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_
551 858
552int ev_is_active (struct ev_watcher *w) 859int ev_is_active (ev_watcher *w)
553 860
861int ev_is_pending (ev_watcher *w)
862
863void ev_invoke (ev_watcher *w, int revents = EV_NONE)
864 C_ARGS: e_loop (w), w, revents
865
866int ev_clear_pending (ev_watcher *w)
867 C_ARGS: e_loop (w), w
868
869void ev_feed_event (ev_watcher *w, int revents = EV_NONE)
870 C_ARGS: e_loop (w), w, revents
871
872int keepalive (ev_watcher *w, int new_value = 0)
873 CODE:
874{
875 RETVAL = w->e_flags & WFLAG_KEEPALIVE;
876 new_value = new_value ? WFLAG_KEEPALIVE : 0;
877
878 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE))
879 {
880 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
881 REF (w);
882 UNREF (w);
883 }
884}
885 OUTPUT:
886 RETVAL
887
554SV *cb (struct ev_watcher *w, SV *new_cb = 0) 888SV *cb (ev_watcher *w, SV *new_cb = 0)
555 CODE: 889 CODE:
556{ 890{
557 RETVAL = newSVsv (w->cb_sv);
558
559 if (items > 1) 891 if (items > 1)
560 sv_setsv (w->cb_sv, new_cb); 892 {
893 new_cb = s_get_cv_croak (new_cb);
894 RETVAL = newRV_noinc (w->cb_sv);
895 w->cb_sv = SvREFCNT_inc (new_cb);
896 }
897 else
898 RETVAL = newRV_inc (w->cb_sv);
561} 899}
562 OUTPUT: 900 OUTPUT:
563 RETVAL 901 RETVAL
564 902
565SV *data (struct ev_watcher *w, SV *new_data = 0) 903SV *data (ev_watcher *w, SV *new_data = 0)
566 CODE: 904 CODE:
567{ 905{
568 RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef; 906 RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef;
569}
570 OUTPUT:
571 RETVAL
572 907
573void trigger (struct ev_watcher *w, int revents = EV_NONE) 908 if (items > 1)
574 CODE: 909 {
575 w->cb (w, revents); 910 SvREFCNT_dec (w->data);
911 w->data = newSVsv (new_data);
912 }
913}
914 OUTPUT:
915 RETVAL
576 916
917SV *loop (ev_watcher *w)
918 CODE:
919 RETVAL = newRV_inc (w->loop);
920 OUTPUT:
921 RETVAL
922
577int priority (struct ev_watcher *w, int new_priority = 0) 923int priority (ev_watcher *w, int new_priority = 0)
578 CODE: 924 CODE:
579{ 925{
580 RETVAL = w->priority; 926 RETVAL = w->priority;
581 927
582 if (items > 1) 928 if (items > 1)
583 { 929 {
584 int active = ev_is_active (w); 930 int active = ev_is_active (w);
585
586 if (new_priority < EV_MINPRI || new_priority > EV_MAXPRI)
587 croak ("watcher priority out of range, value must be between %d and %d, inclusive", EV_MINPRI, EV_MAXPRI);
588 931
589 if (active) 932 if (active)
590 { 933 {
591 /* grrr. */ 934 /* grrr. */
592 PUSHMARK (SP); 935 PUSHMARK (SP);
593 XPUSHs (ST (0)); 936 XPUSHs (ST (0));
937 PUTBACK;
594 call_method ("stop", G_DISCARD | G_VOID); 938 call_method ("stop", G_DISCARD | G_VOID);
595 } 939 }
596 940
597 ev_set_priority (w, new_priority); 941 ev_set_priority (w, new_priority);
598 942
599 if (active) 943 if (active)
600 { 944 {
601 PUSHMARK (SP); 945 PUSHMARK (SP);
602 XPUSHs (ST (0)); 946 XPUSHs (ST (0));
947 PUTBACK;
603 call_method ("start", G_DISCARD | G_VOID); 948 call_method ("start", G_DISCARD | G_VOID);
604 } 949 }
605 } 950 }
606} 951}
607 OUTPUT: 952 OUTPUT:
608 RETVAL 953 RETVAL
609 954
610MODULE = EV PACKAGE = EV::Io PREFIX = ev_io_ 955MODULE = EV PACKAGE = EV::IO PREFIX = ev_io_
611 956
612void ev_io_start (struct ev_io *w) 957void ev_io_start (ev_io *w)
958 CODE:
959 START (io, w);
613 960
614void ev_io_stop (struct ev_io *w) 961void ev_io_stop (ev_io *w)
962 CODE:
963 STOP (io, w);
615 964
616void DESTROY (struct ev_io *w) 965void DESTROY (ev_io *w)
617 CODE: 966 CODE:
618 ev_io_stop (w); 967 STOP (io, w);
619 e_destroy (w); 968 e_destroy (w);
620 969
621void set (struct ev_io *w, SV *fh, int events) 970void set (ev_io *w, SV *fh, int events)
622 CODE: 971 CODE:
623{ 972{
624 int active = ev_is_active (w); 973 int fd = s_fileno (fh, events & EV_WRITE);
625 int fd = sv_fileno (fh);
626 CHECK_FD (fh, fd); 974 CHECK_FD (fh, fd);
627 975
628 if (active) ev_io_stop (w);
629
630 sv_setsv (w->fh, fh); 976 sv_setsv (e_fh (w), fh);
631 ev_io_set (w, fd, events); 977 RESET (io, w, (w, fd, events));
632
633 if (active) ev_io_start (w);
634} 978}
635 979
636SV *fh (struct ev_io *w, SV *new_fh = 0) 980SV *fh (ev_io *w, SV *new_fh = 0)
637 CODE: 981 CODE:
638{ 982{
639 RETVAL = newSVsv (w->fh);
640
641 if (items > 1) 983 if (items > 1)
642 { 984 {
643 int active = ev_is_active (w); 985 int fd = s_fileno (new_fh, w->events & EV_WRITE);
644 if (active) ev_io_stop (w); 986 CHECK_FD (new_fh, fd);
645 987
646 sv_setsv (w->fh, new_fh); 988 RETVAL = e_fh (w);
647 ev_io_set (w, sv_fileno (w->fh), w->events); 989 e_fh (w) = newSVsv (new_fh);
648 990
649 if (active) ev_io_start (w); 991 RESET (io, w, (w, fd, w->events));
650 } 992 }
993 else
994 RETVAL = newSVsv (e_fh (w));
651} 995}
652 OUTPUT: 996 OUTPUT:
653 RETVAL 997 RETVAL
654 998
655int events (struct ev_io *w, int new_events = EV_UNDEF) 999int events (ev_io *w, int new_events = EV_UNDEF)
656 CODE: 1000 CODE:
657{ 1001{
658 RETVAL = w->events; 1002 RETVAL = w->events;
1003
1004 if (items > 1)
1005 RESET (io, w, (w, w->fd, new_events));
1006}
1007 OUTPUT:
1008 RETVAL
1009
1010MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_
1011
1012void ev_signal_start (ev_signal *w)
1013 CODE:
1014 START_SIGNAL (w);
1015
1016void ev_signal_stop (ev_signal *w)
1017 CODE:
1018 STOP (signal, w);
1019
1020void DESTROY (ev_signal *w)
1021 CODE:
1022 STOP (signal, w);
1023 e_destroy (w);
1024
1025void set (ev_signal *w, SV *signal)
1026 CODE:
1027{
1028 Signal signum = s_signum (signal);
1029 CHECK_SIG (signal, signum);
1030
1031 RESET_SIGNAL (w, (w, signum));
1032}
1033
1034int signal (ev_signal *w, SV *new_signal = 0)
1035 CODE:
1036{
1037 RETVAL = w->signum;
659 1038
660 if (items > 1) 1039 if (items > 1)
661 { 1040 {
662 int active = ev_is_active (w); 1041 Signal signum = s_signum (new_signal);
663 if (active) ev_io_stop (w); 1042 CHECK_SIG (new_signal, signum);
664 1043
665 ev_io_set (w, w->fd, new_events); 1044 RESET_SIGNAL (w, (w, signum));
666
667 if (active) ev_io_start (w);
668 } 1045 }
669} 1046}
670 OUTPUT: 1047 OUTPUT:
671 RETVAL 1048 RETVAL
672 1049
673MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ 1050MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_
674 1051
675void ev_signal_start (struct ev_signal *w) 1052void ev_timer_start (ev_timer *w)
676 1053 INIT:
677void ev_signal_stop (struct ev_signal *w) 1054 CHECK_REPEAT (w->repeat);
678
679void DESTROY (struct ev_signal *w)
680 CODE: 1055 CODE:
681 ev_signal_stop (w); 1056 START (timer, w);
1057
1058void ev_timer_stop (ev_timer *w)
1059 CODE:
1060 STOP (timer, w);
1061
1062void ev_timer_again (ev_timer *w)
1063 INIT:
1064 CHECK_REPEAT (w->repeat);
1065 CODE:
1066 ev_timer_again (e_loop (w), w);
1067 UNREF (w);
1068
1069NV ev_timer_remaining (ev_timer *w)
1070 C_ARGS: e_loop (w), w
1071
1072void DESTROY (ev_timer *w)
1073 CODE:
1074 STOP (timer, w);
682 e_destroy (w); 1075 e_destroy (w);
683 1076
684void set (struct ev_signal *w, SV *signal) 1077void set (ev_timer *w, NV after, NV repeat = 0.)
1078 INIT:
1079 CHECK_REPEAT (repeat);
685 CODE: 1080 CODE:
686{ 1081 RESET (timer, w, (w, after, repeat));
687 Signal signum = sv_signum (signal); /* may croak here */
688 int active = ev_is_active (w);
689 1082
690 if (active) ev_signal_stop (w); 1083MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
691 1084
692 ev_signal_set (w, signum); 1085void ev_periodic_start (ev_periodic *w)
693 1086 INIT:
694 if (active) ev_signal_start (w); 1087 CHECK_REPEAT (w->interval);
695}
696
697int signal (struct ev_signal *w, SV *new_signal = 0)
698 CODE: 1088 CODE:
1089 START (periodic, w);
1090
1091void ev_periodic_stop (ev_periodic *w)
1092 CODE:
1093 STOP (periodic, w);
1094
1095void ev_periodic_again (ev_periodic *w)
1096 CODE:
1097 ev_periodic_again (e_loop (w), w);
1098 UNREF (w);
1099
1100void DESTROY (ev_periodic *w)
1101 CODE:
1102 STOP (periodic, w);
1103 e_destroy (w);
1104
1105void set (ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef)
1106 INIT:
1107 CHECK_REPEAT (interval);
1108 CODE:
699{ 1109{
1110 SvREFCNT_dec (e_fh (w));
1111 e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
1112
1113 RESET (periodic, w, (w, at, interval, e_fh (w) ? e_periodic_cb : 0));
1114}
1115
1116NV at (ev_periodic *w)
1117 CODE:
1118 RETVAL = ev_periodic_at (w);
1119 OUTPUT:
1120 RETVAL
1121
1122MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
1123
1124void ev_idle_start (ev_idle *w)
1125 CODE:
1126 START (idle, w);
1127
1128void ev_idle_stop (ev_idle *w)
1129 CODE:
1130 STOP (idle, w);
1131
1132void DESTROY (ev_idle *w)
1133 CODE:
1134 STOP (idle, w);
1135 e_destroy (w);
1136
1137MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_prepare_
1138
1139void ev_prepare_start (ev_prepare *w)
1140 CODE:
1141 START (prepare, w);
1142
1143void ev_prepare_stop (ev_prepare *w)
1144 CODE:
1145 STOP (prepare, w);
1146
1147void DESTROY (ev_prepare *w)
1148 CODE:
1149 STOP (prepare, w);
1150 e_destroy (w);
1151
1152MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_
1153
1154void ev_check_start (ev_check *w)
1155 CODE:
1156 START (check, w);
1157
1158void ev_check_stop (ev_check *w)
1159 CODE:
1160 STOP (check, w);
1161
1162void DESTROY (ev_check *w)
1163 CODE:
1164 STOP (check, w);
1165 e_destroy (w);
1166
1167MODULE = EV PACKAGE = EV::Fork PREFIX = ev_fork_
1168
1169void ev_fork_start (ev_fork *w)
1170 CODE:
1171 START (fork, w);
1172
1173void ev_fork_stop (ev_fork *w)
1174 CODE:
1175 STOP (fork, w);
1176
1177void DESTROY (ev_fork *w)
1178 CODE:
1179 STOP (fork, w);
1180 e_destroy (w);
1181
1182#if CLEANUP_ENABLED
1183
1184MODULE = EV PACKAGE = EV::Cleanup PREFIX = ev_cleanup_
1185
1186void ev_cleanup_start (ev_cleanup *w)
1187 CODE:
1188 START (cleanup, w);
1189
1190void ev_cleanup_stop (ev_cleanup *w)
1191 CODE:
1192 STOP (cleanup, w);
1193
1194void DESTROY (ev_cleanup *w)
1195 CODE:
1196 STOP (cleanup, w);
1197 SvREFCNT_inc (w->loop); /* has been dec'ed on creation */
1198 e_destroy (w);
1199
1200int keepalive (ev_watcher *w, SV *new_value = 0)
1201 CODE:
700 RETVAL = w->signum; 1202 RETVAL = 1;
1203 OUTPUT:
1204 RETVAL
1205
1206#endif
1207
1208MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
1209
1210#if EV_CHILD_ENABLE
1211
1212void ev_child_start (ev_child *w)
1213 CODE:
1214 START (child, w);
1215
1216void ev_child_stop (ev_child *w)
1217 CODE:
1218 STOP (child, w);
1219
1220void DESTROY (ev_child *w)
1221 CODE:
1222 STOP (child, w);
1223 e_destroy (w);
1224
1225void set (ev_child *w, int pid, int trace)
1226 CODE:
1227 RESET (child, w, (w, pid, trace));
1228
1229int pid (ev_child *w)
1230 ALIAS:
1231 rpid = 1
1232 rstatus = 2
1233 CODE:
1234 RETVAL = ix == 0 ? w->pid
1235 : ix == 1 ? w->rpid
1236 : w->rstatus;
1237 OUTPUT:
1238 RETVAL
1239
1240#endif
1241
1242MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
1243
1244void ev_stat_start (ev_stat *w)
1245 CODE:
1246 START (stat, w);
1247
1248void ev_stat_stop (ev_stat *w)
1249 CODE:
1250 STOP (stat, w);
1251
1252void DESTROY (ev_stat *w)
1253 CODE:
1254 STOP (stat, w);
1255 e_destroy (w);
1256
1257void set (ev_stat *w, SV *path, NV interval)
1258 CODE:
1259{
1260 sv_setsv (e_fh (w), path);
1261 RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), interval));
1262}
1263
1264SV *path (ev_stat *w, SV *new_path = 0)
1265 CODE:
1266{
1267 RETVAL = SvREFCNT_inc (e_fh (w));
701 1268
702 if (items > 1) 1269 if (items > 1)
703 { 1270 {
704 Signal signum = sv_signum (new_signal); /* may croak here */ 1271 SvREFCNT_dec (e_fh (w));
705 int active = ev_is_active (w); 1272 e_fh (w) = newSVsv (new_path);
706 if (active) ev_signal_stop (w); 1273 RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), w->interval));
707
708 ev_signal_set (w, signum);
709
710 if (active) ev_signal_start (w);
711 } 1274 }
712} 1275}
713 OUTPUT: 1276 OUTPUT:
714 RETVAL 1277 RETVAL
715 1278
1279NV interval (ev_stat *w, NV new_interval = 0.)
1280 CODE:
1281{
1282 RETVAL = w->interval;
1283
1284 if (items > 1)
1285 RESET (stat, w, (w, SvPVbyte_nolen (e_fh (w)), new_interval));
1286}
1287 OUTPUT:
1288 RETVAL
1289
1290void prev (ev_stat *w)
1291 ALIAS:
1292 stat = 1
1293 attr = 2
1294 PPCODE:
1295{
1296 ev_statdata *s = ix ? &w->attr : &w->prev;
1297
1298 if (ix == 1)
1299 ev_stat_stat (e_loop (w), w);
1300 else if (!s->st_nlink)
1301 errno = ENOENT;
1302
1303 PL_statcache.st_dev = s->st_nlink;
1304 PL_statcache.st_ino = s->st_ino;
1305 PL_statcache.st_mode = s->st_mode;
1306 PL_statcache.st_nlink = s->st_nlink;
1307 PL_statcache.st_uid = s->st_uid;
1308 PL_statcache.st_gid = s->st_gid;
1309 PL_statcache.st_rdev = s->st_rdev;
1310 PL_statcache.st_size = s->st_size;
1311 PL_statcache.st_atime = s->st_atime;
1312 PL_statcache.st_mtime = s->st_mtime;
1313 PL_statcache.st_ctime = s->st_ctime;
1314
1315 if (GIMME_V == G_SCALAR)
1316 XPUSHs (boolSV (s->st_nlink));
1317 else if (GIMME_V == G_ARRAY && s->st_nlink)
1318 {
1319 EXTEND (SP, 13);
1320 PUSHs (sv_2mortal (newSViv (s->st_dev)));
1321 PUSHs (sv_2mortal (newSViv (s->st_ino)));
1322 PUSHs (sv_2mortal (newSVuv (s->st_mode)));
1323 PUSHs (sv_2mortal (newSVuv (s->st_nlink)));
1324 PUSHs (sv_2mortal (newSViv (s->st_uid)));
1325 PUSHs (sv_2mortal (newSViv (s->st_gid)));
1326 PUSHs (sv_2mortal (newSViv (s->st_rdev)));
1327 PUSHs (sv_2mortal (newSVnv ((NV)s->st_size)));
1328 PUSHs (sv_2mortal (newSVnv (s->st_atime)));
1329 PUSHs (sv_2mortal (newSVnv (s->st_mtime)));
1330 PUSHs (sv_2mortal (newSVnv (s->st_ctime)));
1331 PUSHs (sv_2mortal (newSVuv (4096)));
1332 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096))));
1333 }
1334}
1335
716MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ 1336MODULE = EV PACKAGE = EV::Embed PREFIX = ev_embed_
717 1337
718void ev_timer_start (struct ev_timer *w) 1338void ev_embed_start (ev_embed *w)
719 INIT: 1339 CODE:
720 CHECK_REPEAT (w->repeat); 1340 START (embed, w);
721 1341
722void ev_timer_stop (struct ev_timer *w) 1342void ev_embed_stop (ev_embed *w)
1343 CODE:
1344 STOP (embed, w);
723 1345
724void ev_timer_again (struct ev_timer *w)
725 INIT:
726 CHECK_REPEAT (w->repeat);
727
728void DESTROY (struct ev_timer *w) 1346void DESTROY (ev_embed *w)
729 CODE: 1347 CODE:
730 ev_timer_stop (w); 1348 STOP (embed, w);
731 e_destroy (w); 1349 e_destroy (w);
732 1350
733void set (struct ev_timer *w, NV after, NV repeat = 0.) 1351void set (ev_embed *w, struct ev_loop *loop)
1352 CODE:
1353{
1354 sv_setsv (e_fh (w), ST (1));
1355 RESET (embed, w, (w, loop));
1356}
1357
1358SV *other (ev_embed *w)
1359 CODE:
1360 RETVAL = newSVsv (e_fh (w));
1361 OUTPUT:
1362 RETVAL
1363
1364void ev_embed_sweep (ev_embed *w)
1365 C_ARGS: e_loop (w), w
1366
1367MODULE = EV PACKAGE = EV::Async PREFIX = ev_async_
1368
1369void ev_async_start (ev_async *w)
1370 CODE:
1371 START (async, w);
1372
1373void ev_async_stop (ev_async *w)
1374 CODE:
1375 STOP (async, w);
1376
1377void DESTROY (ev_async *w)
1378 CODE:
1379 STOP (async, w);
1380 e_destroy (w);
1381
1382void ev_async_send (ev_async *w)
1383 C_ARGS: e_loop (w), w
1384
1385SV *ev_async_async_pending (ev_async *w)
1386 CODE:
1387 RETVAL = boolSV (ev_async_pending (w));
1388 OUTPUT:
1389 RETVAL
1390
1391#ifndef EV_NO_LOOPS
1392
1393MODULE = EV PACKAGE = EV::Loop PREFIX = ev_
1394
1395SV *new (SV *klass, unsigned int flags = 0)
1396 CODE:
1397{
1398 struct ev_loop *loop = ev_loop_new (flags);
1399
1400 if (!loop)
1401 XSRETURN_UNDEF;
1402
1403 RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (loop))), stash_loop);
1404}
1405 OUTPUT:
1406 RETVAL
1407
1408void DESTROY (struct ev_loop *loop)
1409 CODE:
1410 /* 1. the default loop shouldn't be freed by destroying it's perl loop object */
1411 /* 2. not doing so helps avoid many global destruction bugs in perl, too */
1412 if (loop != evapi.default_loop)
1413 ev_loop_destroy (loop);
1414
1415void ev_loop_fork (struct ev_loop *loop)
1416
1417NV ev_now (struct ev_loop *loop)
1418
1419void ev_now_update (struct ev_loop *loop)
1420
1421void ev_suspend (struct ev_loop *loop)
1422
1423void ev_resume (struct ev_loop *loop)
1424
1425void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1426
1427void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1428
1429unsigned int ev_backend (struct ev_loop *loop)
1430
1431void ev_verify (struct ev_loop *loop)
1432 ALIAS:
1433 loop_verify = 1
1434
1435unsigned int ev_iteration (struct ev_loop *loop)
1436 ALIAS:
1437 loop_count = 1
1438
1439unsigned int ev_depth (struct ev_loop *loop)
1440 ALIAS:
1441 loop_depth = 1
1442
1443int ev_run (struct ev_loop *loop, int flags = 0)
1444 ALIAS:
1445 loop = 1
1446
1447void ev_break (struct ev_loop *loop, int how = 1)
1448 ALIAS:
1449 unloop = 1
1450
1451void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE)
1452
1453unsigned int ev_pending_count (struct ev_loop *loop)
1454
1455void ev_invoke_pending (struct ev_loop *loop)
1456
1457#if 0
1458
1459void ev_feed_signal_event (struct ev_loop *loop, SV *signal)
1460 CODE:
1461{
1462 Signal signum = s_signum (signal);
1463 CHECK_SIG (signal, signum);
1464
1465 ev_feed_signal_event (loop, signum);
1466}
1467
1468#endif
1469
1470ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb)
1471 ALIAS:
1472 io_ns = 1
1473 CODE:
1474{
1475 int fd = s_fileno (fh, events & EV_WRITE);
1476 CHECK_FD (fh, fd);
1477
1478 RETVAL = e_new (sizeof (ev_io), cb, ST (0));
1479 e_fh (RETVAL) = newSVsv (fh);
1480 ev_io_set (RETVAL, fd, events);
1481 if (!ix) START (io, RETVAL);
1482}
1483 OUTPUT:
1484 RETVAL
1485
1486ev_timer *timer (struct ev_loop *loop, NV after, NV repeat, SV *cb)
1487 ALIAS:
1488 timer_ns = 1
734 INIT: 1489 INIT:
735 CHECK_REPEAT (repeat); 1490 CHECK_REPEAT (repeat);
736 CODE: 1491 CODE:
737{ 1492 RETVAL = e_new (sizeof (ev_timer), cb, ST (0));
738 int active = ev_is_active (w);
739 if (active) ev_timer_stop (w);
740 ev_timer_set (w, after, repeat); 1493 ev_timer_set (RETVAL, after, repeat);
741 if (active) ev_timer_start (w); 1494 if (!ix) START (timer, RETVAL);
742} 1495 OUTPUT:
1496 RETVAL
743 1497
744MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ 1498SV *periodic (struct ev_loop *loop, NV at, NV interval, SV *reschedule_cb, SV *cb)
745 1499 ALIAS:
746void ev_periodic_start (struct ev_periodic *w) 1500 periodic_ns = 1
747 INIT:
748 CHECK_REPEAT (w->interval);
749
750void ev_periodic_stop (struct ev_periodic *w)
751
752void ev_periodic_again (struct ev_periodic *w)
753
754void DESTROY (struct ev_periodic *w)
755 CODE:
756 ev_periodic_stop (w);
757 e_destroy (w);
758
759void set (struct ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef)
760 INIT: 1501 INIT:
761 CHECK_REPEAT (interval); 1502 CHECK_REPEAT (interval);
762 CODE: 1503 CODE:
763{ 1504{
764 int active = ev_is_active (w); 1505 ev_periodic *w;
765 if (active) ev_periodic_stop (w); 1506 w = e_new (sizeof (ev_periodic), cb, ST (0));
766
767 SvREFCNT_dec (w->fh);
768 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 1507 e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
769 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); 1508 ev_periodic_set (w, at, interval, e_fh (w) ? e_periodic_cb : 0);
770 1509 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
771 if (active) ev_periodic_start (w); 1510 if (!ix) START (periodic, w);
772} 1511}
773
774MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
775
776void ev_idle_start (struct ev_idle *w)
777
778void ev_idle_stop (struct ev_idle *w)
779
780void DESTROY (struct ev_idle *w)
781 CODE:
782 ev_idle_stop (w);
783 e_destroy (w);
784
785MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_
786
787void ev_prepare_start (struct ev_prepare *w)
788
789void ev_prepare_stop (struct ev_prepare *w)
790
791void DESTROY (struct ev_prepare *w)
792 CODE:
793 ev_prepare_stop (w);
794 e_destroy (w);
795
796MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_
797
798void ev_check_start (struct ev_check *w)
799
800void ev_check_stop (struct ev_check *w)
801
802void DESTROY (struct ev_check *w)
803 CODE:
804 ev_check_stop (w);
805 e_destroy (w);
806
807MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
808
809void ev_child_start (struct ev_child *w)
810
811void ev_child_stop (struct ev_child *w)
812
813void DESTROY (struct ev_child *w)
814 CODE:
815 ev_child_stop (w);
816 e_destroy (w);
817
818void set (struct ev_child *w, int pid)
819 CODE:
820{
821 int active = ev_is_active (w);
822 if (active) ev_child_stop (w);
823
824 ev_child_set (w, pid);
825
826 if (active) ev_child_start (w);
827}
828
829int pid (struct ev_child *w, int new_pid = 0)
830 CODE:
831{
832 RETVAL = w->pid;
833
834 if (items > 1)
835 {
836 int active = ev_is_active (w);
837 if (active) ev_child_stop (w);
838
839 ev_child_set (w, new_pid);
840
841 if (active) ev_child_start (w);
842 }
843}
844 OUTPUT: 1512 OUTPUT:
845 RETVAL
846
847
848int rstatus (struct ev_child *w)
849 ALIAS:
850 rpid = 1
851 CODE:
852 RETVAL = ix ? w->rpid : w->rstatus;
853 OUTPUT:
854 RETVAL
855
856#ifndef _WIN32
857
858MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_
859
860BOOT:
861{
862 HV *stash = gv_stashpv ("EV::DNS", 1);
863
864 static const struct {
865 const char *name;
866 IV iv;
867 } *civ, const_iv[] = {
868# define const_iv(pfx, name) { # name, (IV) pfx ## name },
869 const_iv (DNS_, ERR_NONE)
870 const_iv (DNS_, ERR_FORMAT)
871 const_iv (DNS_, ERR_SERVERFAILED)
872 const_iv (DNS_, ERR_NOTEXIST)
873 const_iv (DNS_, ERR_NOTIMPL)
874 const_iv (DNS_, ERR_REFUSED)
875 const_iv (DNS_, ERR_TRUNCATED)
876 const_iv (DNS_, ERR_UNKNOWN)
877 const_iv (DNS_, ERR_TIMEOUT)
878 const_iv (DNS_, ERR_SHUTDOWN)
879 const_iv (DNS_, IPv4_A)
880 const_iv (DNS_, PTR)
881 const_iv (DNS_, IPv6_AAAA)
882 const_iv (DNS_, QUERY_NO_SEARCH)
883 const_iv (DNS_, OPTION_SEARCH)
884 const_iv (DNS_, OPTION_NAMESERVERS)
885 const_iv (DNS_, OPTION_MISC)
886 const_iv (DNS_, OPTIONS_ALL)
887 const_iv (DNS_, NO_SEARCH)
888 };
889
890 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
891 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
892}
893
894int evdns_init ()
895
896void evdns_shutdown (int fail_requests = 1)
897
898const char *evdns_err_to_string (int err)
899
900int evdns_nameserver_add (U32 address)
901
902int evdns_count_nameservers ()
903
904int evdns_clear_nameservers_and_suspend ()
905
906int evdns_resume ()
907
908int evdns_nameserver_ip_add (char *ip_as_string)
909
910int evdns_resolve_ipv4 (const char *name, int flags, SV *cb)
911 C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb)
912
913int evdns_resolve_ipv6 (const char *name, int flags, SV *cb)
914 C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb)
915
916int evdns_resolve_reverse (SV *addr, int flags, SV *cb)
917 ALIAS:
918 evdns_resolve_reverse_ipv6 = 1
919 CODE:
920{
921 STRLEN len;
922 char *data = SvPVbyte (addr, len);
923 if (len != (ix ? 16 : 4))
924 croak ("ipv4/ipv6 address to be resolved must be given as 4/16 byte octet string");
925
926 RETVAL = ix 1513 RETVAL
927 ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb))
928 : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb));
929}
930 OUTPUT:
931 RETVAL
932 1514
933int evdns_set_option (char *option, char *val, int flags) 1515ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb)
1516 ALIAS:
1517 signal_ns = 1
1518 CODE:
1519{
1520 Signal signum = s_signum (signal);
1521 CHECK_SIG (signal, signum);
934 1522
935int evdns_resolv_conf_parse (int flags, const char *filename) 1523 RETVAL = e_new (sizeof (ev_signal), cb, ST (0));
1524 ev_signal_set (RETVAL, signum);
1525 if (!ix) START_SIGNAL (RETVAL);
1526}
1527 OUTPUT:
1528 RETVAL
936 1529
937#ifdef _WIN32 1530ev_idle *idle (struct ev_loop *loop, SV *cb)
1531 ALIAS:
1532 idle_ns = 1
1533 CODE:
1534 RETVAL = e_new (sizeof (ev_idle), cb, ST (0));
1535 ev_idle_set (RETVAL);
1536 if (!ix) START (idle, RETVAL);
1537 OUTPUT:
1538 RETVAL
938 1539
939int evdns_config_windows_nameservers () 1540ev_prepare *prepare (struct ev_loop *loop, SV *cb)
1541 ALIAS:
1542 prepare_ns = 1
1543 CODE:
1544 RETVAL = e_new (sizeof (ev_prepare), cb, ST (0));
1545 ev_prepare_set (RETVAL);
1546 if (!ix) START (prepare, RETVAL);
1547 OUTPUT:
1548 RETVAL
1549
1550ev_check *check (struct ev_loop *loop, SV *cb)
1551 ALIAS:
1552 check_ns = 1
1553 CODE:
1554 RETVAL = e_new (sizeof (ev_check), cb, ST (0));
1555 ev_check_set (RETVAL);
1556 if (!ix) START (check, RETVAL);
1557 OUTPUT:
1558 RETVAL
1559
1560ev_fork *fork (struct ev_loop *loop, SV *cb)
1561 ALIAS:
1562 fork_ns = 1
1563 CODE:
1564 RETVAL = e_new (sizeof (ev_fork), cb, ST (0));
1565 ev_fork_set (RETVAL);
1566 if (!ix) START (fork, RETVAL);
1567 OUTPUT:
1568 RETVAL
1569
1570#if CLEANUP_ENABLED
1571
1572ev_cleanup *cleanup (struct ev_loop *loop, SV *cb)
1573 ALIAS:
1574 cleanup_ns = 1
1575 CODE:
1576 RETVAL = e_new (sizeof (ev_cleanup), cb, ST (0));
1577 SvREFCNT_dec (RETVAL->loop); /* must not keep loop object alive */
1578 ev_cleanup_set (RETVAL);
1579 if (!ix) START (cleanup, RETVAL);
1580 OUTPUT:
1581 RETVAL
940 1582
941#endif 1583#endif
942 1584
943void evdns_search_clear () 1585ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
944 1586 ALIAS:
945void evdns_search_add (char *domain) 1587 child_ns = 1
946 1588 CODE:
947void evdns_search_ndots_set (int ndots) 1589#if EV_CHILD_ENABLE
948 1590 RETVAL = e_new (sizeof (ev_child), cb, ST (0));
949#if 0 1591 ev_child_set (RETVAL, pid, trace);
950 1592 if (!ix) START (child, RETVAL);
951MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ 1593#else
952 1594 croak ("EV::child watchers not supported on this platform");
953BOOT:
954{
955 HV *stash = gv_stashpv ("EV::HTTP", 1);
956
957 static const struct {
958 const char *name;
959 IV iv;
960 } *civ, const_iv[] = {
961# define const_iv(pfx, name) { # name, (IV) pfx ## name },
962 const_iv (HTTP_, OK)
963 const_iv (HTTP_, NOCONTENT)
964 const_iv (HTTP_, MOVEPERM)
965 const_iv (HTTP_, MOVETEMP)
966 const_iv (HTTP_, NOTMODIFIED)
967 const_iv (HTTP_, BADREQUEST)
968 const_iv (HTTP_, NOTFOUND)
969 const_iv (HTTP_, SERVUNAVAIL)
970 const_iv (EVHTTP_, REQ_OWN_CONNECTION)
971 const_iv (EVHTTP_, PROXY_REQUEST)
972 const_iv (EVHTTP_, REQ_GET)
973 const_iv (EVHTTP_, REQ_POST)
974 const_iv (EVHTTP_, REQ_HEAD)
975 const_iv (EVHTTP_, REQUEST)
976 const_iv (EVHTTP_, RESPONSE)
977 };
978
979 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
980 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
981}
982
983MODULE = EV PACKAGE = EV::HTTP::Request PREFIX = evhttp_request_
984
985#HttpRequest new (SV *klass, SV *cb)
986
987#void DESTROY (struct evhttp_request *req);
988
989#endif 1595#endif
1596 OUTPUT:
1597 RETVAL
1598
1599ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb)
1600 ALIAS:
1601 stat_ns = 1
1602 CODE:
1603 RETVAL = e_new (sizeof (ev_stat), cb, ST (0));
1604 e_fh (RETVAL) = newSVsv (path);
1605 ev_stat_set (RETVAL, SvPVbyte_nolen (e_fh (RETVAL)), interval);
1606 if (!ix) START (stat, RETVAL);
1607 OUTPUT:
1608 RETVAL
1609
1610ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = 0)
1611 ALIAS:
1612 embed_ns = 1
1613 CODE:
1614{
1615 if (!(ev_backend (other) & ev_embeddable_backends ()))
1616 croak ("passed loop is not embeddable via EV::embed,");
1617
1618 RETVAL = e_new (sizeof (ev_embed), cb, ST (0));
1619 e_fh (RETVAL) = newSVsv (ST (1));
1620 ev_embed_set (RETVAL, other);
1621 if (!ix) START (embed, RETVAL);
1622}
1623 OUTPUT:
1624 RETVAL
1625
1626ev_async *async (struct ev_loop *loop, SV *cb)
1627 ALIAS:
1628 async_ns = 1
1629 CODE:
1630 RETVAL = e_new (sizeof (ev_async), cb, ST (0));
1631 ev_async_set (RETVAL);
1632 if (!ix) START (async, RETVAL);
1633 OUTPUT:
1634 RETVAL
1635
1636void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb)
1637 CODE:
1638 ev_once (
1639 loop,
1640 s_fileno (fh, events & EV_WRITE), events,
1641 SvOK (timeout) ? SvNV (timeout) : -1.,
1642 e_once_cb,
1643 newSVsv (cb)
1644 );
990 1645
991#endif 1646#endif
992 1647
993
994
995
996
997
998

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines