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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines