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

Comparing EV/EV.xs (file contents):
Revision 1.4 by root, Fri Oct 26 18:21:32 2007 UTC vs.
Revision 1.10 by root, Mon Oct 29 07:56:03 2007 UTC

24#define EV_UNDEF -1 24#define EV_UNDEF -1
25 25
26#define TIMEOUT_NONE HUGE_VAL 26#define TIMEOUT_NONE HUGE_VAL
27 27
28typedef struct event_base *Base; 28typedef struct event_base *Base;
29typedef int Signal;
29 30
30static HV *stash_base, *stash_event; 31static HV *stash_base, *stash_event;
31 32
32static double tv_get (struct timeval *tv) 33static double tv_get (struct timeval *tv)
33{ 34{
37static void tv_set (struct timeval *tv, double val) 38static void tv_set (struct timeval *tv, double val)
38{ 39{
39 tv->tv_sec = (long)val; 40 tv->tv_sec = (long)val;
40 tv->tv_usec = (long)((val - (double)tv->tv_sec) * 1e6); 41 tv->tv_usec = (long)((val - (double)tv->tv_sec) * 1e6);
41 42
43}
44
45static int
46sv_signum (SV *sig)
47{
48 int signum;
49
50 if (SvIV (sig) > 0)
51 return SvIV (sig);
52
53 for (signum = 1; signum < SIG_SIZE; ++signum)
54 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum]))
55 return signum;
56
57 return -1;
42} 58}
43 59
44///////////////////////////////////////////////////////////////////////////// 60/////////////////////////////////////////////////////////////////////////////
45// Event 61// Event
46 62
116 132
117 if (ev->abstime) 133 if (ev->abstime)
118 { 134 {
119 double now = e_now (); 135 double now = e_now ();
120 136
121 if (now > to && ev->interval) 137 if (ev->interval)
122 ev->timeout = (to += ceil ((now - to) / ev->interval) * ev->interval); 138 ev->timeout = (to += ceil ((now - to) / ev->interval) * ev->interval);
123 139
124 to -= now; 140 to -= now;
125 } 141 }
126 else if (to < 0.) 142 else if (to < 0.)
169 dSP; 185 dSP;
170 186
171 ENTER; 187 ENTER;
172 SAVETMPS; 188 SAVETMPS;
173 189
174 if (!(ev->ev.ev_events & EV_PERSIST)) 190 if (!(ev->ev.ev_events & EV_PERSIST) || (events & EV_TIMEOUT))
175 ev->active = 0; 191 ev->active = 0;
176 192
177 PUSHMARK (SP); 193 PUSHMARK (SP);
178 EXTEND (SP, 2); 194 EXTEND (SP, 2);
179 PUSHs (sv_2mortal (e_self (ev))); 195 PUSHs (sv_2mortal (e_self (ev)));
180 PUSHs (sv_2mortal (newSViv (events))); 196 PUSHs (sv_2mortal (newSViv (events)));
181 PUTBACK; 197 PUTBACK;
182 call_sv (ev->cb, G_DISCARD | G_VOID | G_EVAL); 198 call_sv (ev->cb, G_DISCARD | G_VOID | G_EVAL);
183 /*TODO: if err, call some logging function */
184 199
185 if (ev->interval && !ev->active) 200 if (ev->interval && !ev->active)
186 e_start (ev); 201 e_start (ev);
187 202
188 FREETMPS; 203 FREETMPS;
204
205 if (SvTRUE (ERRSV))
206 {
207 PUSHMARK (SP);
208 PUTBACK;
209 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
210 }
211
189 LEAVE; 212 LEAVE;
190} 213}
191 214
192///////////////////////////////////////////////////////////////////////////// 215/////////////////////////////////////////////////////////////////////////////
193// DNS 216// DNS
228 251
229 PUTBACK; 252 PUTBACK;
230 call_sv (sv_2mortal (cb), G_DISCARD | G_VOID | G_EVAL); 253 call_sv (sv_2mortal (cb), G_DISCARD | G_VOID | G_EVAL);
231 254
232 FREETMPS; 255 FREETMPS;
256
257 if (SvTRUE (ERRSV))
258 {
259 PUSHMARK (SP);
260 PUTBACK;
261 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
262 }
263
233 LEAVE; 264 LEAVE;
234} 265}
235 266
236///////////////////////////////////////////////////////////////////////////// 267/////////////////////////////////////////////////////////////////////////////
237// XS interface functions 268// XS interface functions
238 269
239MODULE = EV PACKAGE = EV PREFIX = event_ 270MODULE = EV PACKAGE = EV PREFIX = event_
240 271
241BOOT: 272BOOT:
242{ 273{
274 int i;
243 HV *stash = gv_stashpv ("EV", 1); 275 HV *stash = gv_stashpv ("EV", 1);
244 276
245 static const struct { 277 static const struct {
246 const char *name; 278 const char *name;
247 IV iv; 279 IV iv;
312 RETVAL = e_new (fh, events, cb); 344 RETVAL = e_new (fh, events, cb);
313 if (!ix) e_start (RETVAL); 345 if (!ix) e_start (RETVAL);
314 OUTPUT: 346 OUTPUT:
315 RETVAL 347 RETVAL
316 348
349Event timed_io (SV *fh, short events, double timeout, SV *cb)
350 ALIAS:
351 timed_io_ns = 1
352 CODE:
353{
354 events = timeout ? events & ~EV_PERSIST : events | EV_PERSIST;
355
356 RETVAL = e_new (fh, events, cb);
357
358 if (timeout)
359 {
360 RETVAL->timeout = timeout;
361 RETVAL->interval = 1;
362 }
363
364 if (!ix) e_start (RETVAL);
365}
366 OUTPUT:
367 RETVAL
368
317Event timer (double after, int repeat, SV *cb) 369Event timer (double after, int repeat, SV *cb)
318 ALIAS: 370 ALIAS:
319 timer_ns = 1 371 timer_ns = 1
320 CODE: 372 CODE:
321 RETVAL = e_new (NEWSV (0, 0), 0, cb); 373 RETVAL = e_new (NEWSV (0, 0), 0, cb);
335 RETVAL->abstime = 1; 387 RETVAL->abstime = 1;
336 if (!ix) e_start (RETVAL); 388 if (!ix) e_start (RETVAL);
337 OUTPUT: 389 OUTPUT:
338 RETVAL 390 RETVAL
339 391
340Event signal (SV *signal, SV *cb) 392Event signal (Signal signum, SV *cb)
341 ALIAS: 393 ALIAS:
342 signal_ns = 1 394 signal_ns = 1
343 CODE: 395 CODE:
344 RETVAL = e_new (signal, EV_SIGNAL | EV_PERSIST, cb); 396 RETVAL = e_new (ST (0), EV_SIGNAL | EV_PERSIST, cb);
397 RETVAL->ev.ev_fd = signum;
345 if (!ix) e_start (RETVAL); 398 if (!ix) e_start (RETVAL);
346 OUTPUT: 399 OUTPUT:
347 RETVAL 400 RETVAL
348 401
349PROTOTYPES: DISABLE 402PROTOTYPES: DISABLE
420 sv_setsv (ev->cb, new_cb); 473 sv_setsv (ev->cb, new_cb);
421 OUTPUT: 474 OUTPUT:
422 RETVAL 475 RETVAL
423 476
424SV *fh (Event ev, SV *new_fh = 0) 477SV *fh (Event ev, SV *new_fh = 0)
425 ALIAS:
426 signal = 0
427 CODE: 478 CODE:
428 RETVAL = newSVsv (ev->fh); 479 RETVAL = newSVsv (ev->fh);
429 if (items > 1) 480 if (items > 1)
430 { 481 {
431 if (ev->active) event_del (&ev->ev); 482 if (ev->active) event_del (&ev->ev);
432 sv_setsv (ev->fh, new_fh); 483 sv_setsv (ev->fh, new_fh);
433 ev->ev.ev_fd = sv_fileno (ev->fh); 484 ev->ev.ev_fd = sv_fileno (ev->fh);
485 ev->ev.ev_events &= ev->ev.ev_events & ~EV_SIGNAL;
434 if (ev->active) event_add (&ev->ev, e_tv (ev)); 486 if (ev->active) event_add (&ev->ev, e_tv (ev));
435 } 487 }
488 OUTPUT:
489 RETVAL
490
491SV *signal (Event ev, SV *new_signal = 0)
492 CODE:
493{
494 Signal signum;
495
496 if (items > 1)
497 signum = sv_signum (new_signal); /* may croak here */
498
499 RETVAL = newSVsv (ev->fh);
500
501 if (items > 1)
502 {
503 if (ev->active) event_del (&ev->ev);
504 sv_setsv (ev->fh, new_signal);
505 ev->ev.ev_fd = signum;
506 ev->ev.ev_events |= EV_SIGNAL;
507 if (ev->active) event_add (&ev->ev, e_tv (ev));
508 }
509}
436 OUTPUT: 510 OUTPUT:
437 RETVAL 511 RETVAL
438 512
439short events (Event ev, short new_events = EV_UNDEF) 513short events (Event ev, short new_events = EV_UNDEF)
440 CODE: 514 CODE:
480 static const struct { 554 static const struct {
481 const char *name; 555 const char *name;
482 IV iv; 556 IV iv;
483 } *civ, const_iv[] = { 557 } *civ, const_iv[] = {
484# define const_iv(pfx, name) { # name, (IV) pfx ## name }, 558# define const_iv(pfx, name) { # name, (IV) pfx ## name },
485
486 const_iv (DNS_, ERR_NONE) 559 const_iv (DNS_, ERR_NONE)
487 const_iv (DNS_, ERR_FORMAT) 560 const_iv (DNS_, ERR_FORMAT)
488 const_iv (DNS_, ERR_SERVERFAILED) 561 const_iv (DNS_, ERR_SERVERFAILED)
489 const_iv (DNS_, ERR_NOTEXIST) 562 const_iv (DNS_, ERR_NOTEXIST)
490 const_iv (DNS_, ERR_NOTIMPL) 563 const_iv (DNS_, ERR_NOTIMPL)
536 CODE: 609 CODE:
537{ 610{
538 STRLEN len; 611 STRLEN len;
539 char *data = SvPVbyte (addr, len); 612 char *data = SvPVbyte (addr, len);
540 if (len != (ix ? 16 : 4)) 613 if (len != (ix ? 16 : 4))
541 croak ("ipv4/ipv6 address to resolve must be given as 4/16 byte octet string"); 614 croak ("ipv4/ipv6 address to be resolved must be given as 4/16 byte octet string");
542 615
543 RETVAL = ix 616 RETVAL = ix
544 ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)) 617 ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb))
545 : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)); 618 : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb));
546} 619}
561 634
562void evdns_search_add (char *domain) 635void evdns_search_add (char *domain)
563 636
564void evdns_search_ndots_set (int ndots) 637void evdns_search_ndots_set (int ndots)
565 638
639
640MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
641
642BOOT:
643{
644 HV *stash = gv_stashpv ("EV::HTTP", 1);
645
646 static const struct {
647 const char *name;
648 IV iv;
649 } *civ, const_iv[] = {
650# define const_iv(pfx, name) { # name, (IV) pfx ## name },
651 const_iv (HTTP_, OK)
652 const_iv (HTTP_, NOCONTENT)
653 const_iv (HTTP_, MOVEPERM)
654 const_iv (HTTP_, MOVETEMP)
655 const_iv (HTTP_, NOTMODIFIED)
656 const_iv (HTTP_, BADREQUEST)
657 const_iv (HTTP_, NOTFOUND)
658 const_iv (HTTP_, SERVUNAVAIL)
659 const_iv (EVHTTP_, REQ_OWN_CONNECTION)
660 const_iv (EVHTTP_, PROXY_REQUEST)
661 const_iv (EVHTTP_, REQ_GET)
662 const_iv (EVHTTP_, REQ_POST)
663 const_iv (EVHTTP_, REQ_HEAD)
664 const_iv (EVHTTP_, REQUEST)
665 const_iv (EVHTTP_, RESPONSE)
666 };
667
668 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
669 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
670}
671
672MODULE = EV PACKAGE = EV::HTTP::Request PREFIX = evhttp_request_
673
674#HttpRequest new (SV *klass, SV *cb)
675
676#void DESTROY (struct evhttp_request *req);
677
678
679
680
681
682
683
684

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines