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

Comparing EV/EV.xs (file contents):
Revision 1.2 by root, Fri Oct 26 16:51:27 2007 UTC vs.
Revision 1.8 by root, Sat Oct 27 19:11:27 2007 UTC

7 7
8#include <sys/time.h> 8#include <sys/time.h>
9#include <time.h> 9#include <time.h>
10#include <event.h> 10#include <event.h>
11#include <evdns.h> 11#include <evdns.h>
12/*include <evhttp.h>*/ /* does not compile */ 12
13/* workaround for evhttp.h requiring obscure bsd headers */
14#ifndef TAILQ_ENTRY
15#define TAILQ_ENTRY(type) \
16struct { \
17 struct type *tqe_next; /* next element */ \
18 struct type **tqe_prev; /* address of previous next element */ \
19}
20#endif /* !TAILQ_ENTRY */
21#include <evhttp.h>
13 22
14#define EV_NONE 0 23#define EV_NONE 0
15#define EV_UNDEF -1 24#define EV_UNDEF -1
16 25
17#define TIMEOUT_NONE HUGE_VAL 26#define TIMEOUT_NONE HUGE_VAL
56 65
57static void e_cb (int fd, short events, void *arg); 66static void e_cb (int fd, short events, void *arg);
58 67
59static int sv_fileno (SV *fh) 68static int sv_fileno (SV *fh)
60{ 69{
61 if (fh)
62 {
63 SvGETMAGIC (fh); 70 SvGETMAGIC (fh);
64 71
65 if (SvROK (fh)) 72 if (SvROK (fh))
66 fh = SvRV (fh); 73 fh = SvRV (fh);
67 74
68 if (SvTYPE (fh) == SVt_PVGV) 75 if (SvTYPE (fh) == SVt_PVGV)
69 return PerlIO_fileno (IoIFP (sv_2io (fh))); 76 return PerlIO_fileno (IoIFP (sv_2io (fh)));
70 77
71 if (SvIOK (fh)) 78 if (SvIOK (fh))
72 return SvIV (fh); 79 return SvIV (fh);
73 }
74 80
75 return -1; 81 return -1;
76} 82}
77 83
78static Event 84static Event
110 116
111 if (ev->abstime) 117 if (ev->abstime)
112 { 118 {
113 double now = e_now (); 119 double now = e_now ();
114 120
115 if (now > to && ev->interval) 121 if (ev->interval)
116 ev->timeout = (to += ceil ((now - to) / ev->interval) * ev->interval); 122 ev->timeout = (to += ceil ((now - to) / ev->interval) * ev->interval);
117 123
118 to -= now; 124 to -= now;
119 } 125 }
120 else if (to < 0.) 126 else if (to < 0.)
163 dSP; 169 dSP;
164 170
165 ENTER; 171 ENTER;
166 SAVETMPS; 172 SAVETMPS;
167 173
168 if (!(ev->ev.ev_events & EV_PERSIST)) 174 if (!(ev->ev.ev_events & EV_PERSIST) || (events & EV_TIMEOUT))
169 ev->active = 0; 175 ev->active = 0;
170 176
171 PUSHMARK (SP); 177 PUSHMARK (SP);
172 EXTEND (SP, 2); 178 EXTEND (SP, 2);
173 PUSHs (sv_2mortal (e_self (ev))); 179 PUSHs (sv_2mortal (e_self (ev)));
174 PUSHs (sv_2mortal (newSViv (events))); 180 PUSHs (sv_2mortal (newSViv (events)));
175 PUTBACK; 181 PUTBACK;
176 call_sv (ev->cb, G_DISCARD | G_VOID | G_EVAL); 182 call_sv (ev->cb, G_DISCARD | G_VOID | G_EVAL);
177 /*TODO: if err, call some logging function */
178 183
179 if (ev->interval && !ev->active) 184 if (ev->interval && !ev->active)
180 e_start (ev); 185 e_start (ev);
181 186
182 FREETMPS; 187 FREETMPS;
188
189 if (SvTRUE (ERRSV))
190 {
191 PUSHMARK (SP);
192 PUTBACK;
193 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
194 }
195
183 LEAVE; 196 LEAVE;
184} 197}
185 198
186///////////////////////////////////////////////////////////////////////////// 199/////////////////////////////////////////////////////////////////////////////
187// DNS 200// DNS
222 235
223 PUTBACK; 236 PUTBACK;
224 call_sv (sv_2mortal (cb), G_DISCARD | G_VOID | G_EVAL); 237 call_sv (sv_2mortal (cb), G_DISCARD | G_VOID | G_EVAL);
225 238
226 FREETMPS; 239 FREETMPS;
240
241 if (SvTRUE (ERRSV))
242 {
243 PUSHMARK (SP);
244 PUTBACK;
245 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
246 }
247
227 LEAVE; 248 LEAVE;
228} 249}
229 250
230///////////////////////////////////////////////////////////////////////////// 251/////////////////////////////////////////////////////////////////////////////
231// XS interface functions 252// XS interface functions
283 304
284int event_dispatch () 305int event_dispatch ()
285 306
286int event_loop (int flags = 0) 307int event_loop (int flags = 0)
287 308
288int event_loopexit (double after) 309int event_loopexit (double after = 0)
289 CODE: 310 CODE:
290{ 311{
291 struct timeval tv; 312 struct timeval tv;
292 tv_set (&tv, after); 313 tv_set (&tv, after);
293 event_loopexit (&tv); 314 event_loopexit (&tv);
294} 315}
295 316
296Event event (SV *cb) 317Event event (SV *cb)
297 CODE: 318 CODE:
298 RETVAL = e_new (0, 0, cb); 319 RETVAL = e_new (NEWSV (0, 0), 0, cb);
299 OUTPUT: 320 OUTPUT:
300 RETVAL 321 RETVAL
301 322
302Event io (SV *fh, short events, SV *cb) 323Event io (SV *fh, short events, SV *cb)
303 ALIAS: 324 ALIAS:
310 331
311Event timer (double after, int repeat, SV *cb) 332Event timer (double after, int repeat, SV *cb)
312 ALIAS: 333 ALIAS:
313 timer_ns = 1 334 timer_ns = 1
314 CODE: 335 CODE:
315 RETVAL = e_new (0, 0, cb); 336 RETVAL = e_new (NEWSV (0, 0), 0, cb);
316 RETVAL->timeout = after; 337 RETVAL->timeout = after;
317 RETVAL->interval = repeat; 338 RETVAL->interval = repeat;
318 if (!ix) e_start (RETVAL); 339 if (!ix) e_start (RETVAL);
319 OUTPUT: 340 OUTPUT:
320 RETVAL 341 RETVAL
321 342
322Event timer_abs (double at, double interval, SV *cb) 343Event timer_abs (double at, double interval, SV *cb)
323 ALIAS: 344 ALIAS:
324 timer_abs_ns = 1 345 timer_abs_ns = 1
325 CODE: 346 CODE:
326 RETVAL = e_new (0, 0, cb); 347 RETVAL = e_new (NEWSV (0, 0), 0, cb);
327 RETVAL->timeout = at; 348 RETVAL->timeout = at;
328 RETVAL->interval = interval; 349 RETVAL->interval = interval;
329 RETVAL->abstime = 1; 350 RETVAL->abstime = 1;
330 if (!ix) e_start (RETVAL); 351 if (!ix) e_start (RETVAL);
331 OUTPUT: 352 OUTPUT:
405 CODE: 426 CODE:
406 e_stop (ev); 427 e_stop (ev);
407 SvREFCNT_dec (ev->cb); 428 SvREFCNT_dec (ev->cb);
408 SvREFCNT_dec (ev->fh); 429 SvREFCNT_dec (ev->fh);
409 430
410void cb (Event ev, SV *new_cb) 431SV *cb (Event ev, SV *new_cb = 0)
411 CODE: 432 CODE:
433 RETVAL = newSVsv (ev->cb);
434 if (items > 1)
412 sv_setsv (ev->cb, new_cb); 435 sv_setsv (ev->cb, new_cb);
436 OUTPUT:
437 RETVAL
413 438
414SV *fh (Event ev, SV *new_fh = 0) 439SV *fh (Event ev, SV *new_fh = 0)
415 ALIAS: 440 ALIAS:
416 signal = 0 441 signal = 0
417 CODE: 442 CODE:
470 static const struct { 495 static const struct {
471 const char *name; 496 const char *name;
472 IV iv; 497 IV iv;
473 } *civ, const_iv[] = { 498 } *civ, const_iv[] = {
474# define const_iv(pfx, name) { # name, (IV) pfx ## name }, 499# define const_iv(pfx, name) { # name, (IV) pfx ## name },
475
476 const_iv (DNS_, ERR_NONE) 500 const_iv (DNS_, ERR_NONE)
477 const_iv (DNS_, ERR_FORMAT) 501 const_iv (DNS_, ERR_FORMAT)
478 const_iv (DNS_, ERR_SERVERFAILED) 502 const_iv (DNS_, ERR_SERVERFAILED)
479 const_iv (DNS_, ERR_NOTEXIST) 503 const_iv (DNS_, ERR_NOTEXIST)
480 const_iv (DNS_, ERR_NOTIMPL) 504 const_iv (DNS_, ERR_NOTIMPL)
526 CODE: 550 CODE:
527{ 551{
528 STRLEN len; 552 STRLEN len;
529 char *data = SvPVbyte (addr, len); 553 char *data = SvPVbyte (addr, len);
530 if (len != (ix ? 16 : 4)) 554 if (len != (ix ? 16 : 4))
531 croak ("ipv4/ipv6 address to resolve must be given as 4/16 byte octet string"); 555 croak ("ipv4/ipv6 address to be resolved must be given as 4/16 byte octet string");
532 556
533 RETVAL = ix 557 RETVAL = ix
534 ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)) 558 ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb))
535 : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)); 559 : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb));
536} 560}
551 575
552void evdns_search_add (char *domain) 576void evdns_search_add (char *domain)
553 577
554void evdns_search_ndots_set (int ndots) 578void evdns_search_ndots_set (int ndots)
555 579
580
581MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
582
583BOOT:
584{
585 HV *stash = gv_stashpv ("EV::HTTP", 1);
586
587 static const struct {
588 const char *name;
589 IV iv;
590 } *civ, const_iv[] = {
591# define const_iv(pfx, name) { # name, (IV) pfx ## name },
592 const_iv (HTTP_, OK)
593 const_iv (HTTP_, NOCONTENT)
594 const_iv (HTTP_, MOVEPERM)
595 const_iv (HTTP_, MOVETEMP)
596 const_iv (HTTP_, NOTMODIFIED)
597 const_iv (HTTP_, BADREQUEST)
598 const_iv (HTTP_, NOTFOUND)
599 const_iv (HTTP_, SERVUNAVAIL)
600 const_iv (EVHTTP_, REQ_OWN_CONNECTION)
601 const_iv (EVHTTP_, PROXY_REQUEST)
602 const_iv (EVHTTP_, REQ_GET)
603 const_iv (EVHTTP_, REQ_POST)
604 const_iv (EVHTTP_, REQ_HEAD)
605 const_iv (EVHTTP_, REQUEST)
606 const_iv (EVHTTP_, RESPONSE)
607 };
608
609 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
610 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
611}
612
613MODULE = EV PACKAGE = EV::HTTP::Request PREFIX = evhttp_request_
614
615#HttpRequest new (SV *klass, SV *cb)
616
617#void DESTROY (struct evhttp_request *req);
618
619
620
621
622
623
624
625

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines