… | |
… | |
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) \ |
|
|
16 | struct { \ |
|
|
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 |
… | |
… | |
107 | |
116 | |
108 | if (ev->abstime) |
117 | if (ev->abstime) |
109 | { |
118 | { |
110 | double now = e_now (); |
119 | double now = e_now (); |
111 | |
120 | |
112 | if (now > to && ev->interval) |
121 | if (ev->interval) |
113 | ev->timeout = (to += ceil ((now - to) / ev->interval) * ev->interval); |
122 | ev->timeout = (to += ceil ((now - to) / ev->interval) * ev->interval); |
114 | |
123 | |
115 | to -= now; |
124 | to -= now; |
116 | } |
125 | } |
117 | else if (to < 0.) |
126 | else if (to < 0.) |
… | |
… | |
160 | dSP; |
169 | dSP; |
161 | |
170 | |
162 | ENTER; |
171 | ENTER; |
163 | SAVETMPS; |
172 | SAVETMPS; |
164 | |
173 | |
165 | if (!(ev->ev.ev_events & EV_PERSIST)) |
174 | if (!(ev->ev.ev_events & EV_PERSIST) || (events & EV_TIMEOUT)) |
166 | ev->active = 0; |
175 | ev->active = 0; |
167 | |
176 | |
168 | PUSHMARK (SP); |
177 | PUSHMARK (SP); |
169 | EXTEND (SP, 2); |
178 | EXTEND (SP, 2); |
170 | PUSHs (sv_2mortal (e_self (ev))); |
179 | PUSHs (sv_2mortal (e_self (ev))); |
171 | PUSHs (sv_2mortal (newSViv (events))); |
180 | PUSHs (sv_2mortal (newSViv (events))); |
172 | PUTBACK; |
181 | PUTBACK; |
173 | call_sv (ev->cb, G_DISCARD | G_VOID | G_EVAL); |
182 | call_sv (ev->cb, G_DISCARD | G_VOID | G_EVAL); |
174 | /*TODO: if err, call some logging function */ |
|
|
175 | |
183 | |
176 | if (ev->interval && !ev->active) |
184 | if (ev->interval && !ev->active) |
177 | e_start (ev); |
185 | e_start (ev); |
178 | |
186 | |
179 | 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 | |
180 | LEAVE; |
196 | LEAVE; |
181 | } |
197 | } |
182 | |
198 | |
183 | ///////////////////////////////////////////////////////////////////////////// |
199 | ///////////////////////////////////////////////////////////////////////////// |
184 | // DNS |
200 | // DNS |
… | |
… | |
219 | |
235 | |
220 | PUTBACK; |
236 | PUTBACK; |
221 | call_sv (sv_2mortal (cb), G_DISCARD | G_VOID | G_EVAL); |
237 | call_sv (sv_2mortal (cb), G_DISCARD | G_VOID | G_EVAL); |
222 | |
238 | |
223 | 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 | |
224 | LEAVE; |
248 | LEAVE; |
225 | } |
249 | } |
226 | |
250 | |
227 | ///////////////////////////////////////////////////////////////////////////// |
251 | ///////////////////////////////////////////////////////////////////////////// |
228 | // XS interface functions |
252 | // XS interface functions |
… | |
… | |
303 | RETVAL = e_new (fh, events, cb); |
327 | RETVAL = e_new (fh, events, cb); |
304 | if (!ix) e_start (RETVAL); |
328 | if (!ix) e_start (RETVAL); |
305 | OUTPUT: |
329 | OUTPUT: |
306 | RETVAL |
330 | RETVAL |
307 | |
331 | |
|
|
332 | Event timed_io (SV *fh, short events, double timeout, SV *cb) |
|
|
333 | ALIAS: |
|
|
334 | timed_io_ns = 1 |
|
|
335 | CODE: |
|
|
336 | { |
|
|
337 | events = timeout ? events & ~EV_PERSIST : events | EV_PERSIST; |
|
|
338 | |
|
|
339 | RETVAL = e_new (fh, events, cb); |
|
|
340 | |
|
|
341 | if (timeout) |
|
|
342 | { |
|
|
343 | RETVAL->timeout = timeout; |
|
|
344 | RETVAL->interval = 1; |
|
|
345 | } |
|
|
346 | |
|
|
347 | if (!ix) e_start (RETVAL); |
|
|
348 | } |
|
|
349 | OUTPUT: |
|
|
350 | RETVAL |
|
|
351 | |
308 | Event timer (double after, int repeat, SV *cb) |
352 | Event timer (double after, int repeat, SV *cb) |
309 | ALIAS: |
353 | ALIAS: |
310 | timer_ns = 1 |
354 | timer_ns = 1 |
311 | CODE: |
355 | CODE: |
312 | RETVAL = e_new (NEWSV (0, 0), 0, cb); |
356 | RETVAL = e_new (NEWSV (0, 0), 0, cb); |
… | |
… | |
412 | OUTPUT: |
456 | OUTPUT: |
413 | RETVAL |
457 | RETVAL |
414 | |
458 | |
415 | SV *fh (Event ev, SV *new_fh = 0) |
459 | SV *fh (Event ev, SV *new_fh = 0) |
416 | ALIAS: |
460 | ALIAS: |
417 | signal = 0 |
461 | signal = 1 |
418 | CODE: |
462 | CODE: |
419 | RETVAL = newSVsv (ev->fh); |
463 | RETVAL = newSVsv (ev->fh); |
420 | if (items > 1) |
464 | if (items > 1) |
421 | { |
465 | { |
422 | if (ev->active) event_del (&ev->ev); |
466 | if (ev->active) event_del (&ev->ev); |
423 | sv_setsv (ev->fh, new_fh); |
467 | sv_setsv (ev->fh, new_fh); |
424 | ev->ev.ev_fd = sv_fileno (ev->fh); |
468 | ev->ev.ev_fd = sv_fileno (ev->fh); |
|
|
469 | ev->ev.ev_events = signal ? ev->ev.ev_events | EV_SIGNAL : ev->ev.ev_events & ~EV_SIGNAL; |
425 | if (ev->active) event_add (&ev->ev, e_tv (ev)); |
470 | if (ev->active) event_add (&ev->ev, e_tv (ev)); |
426 | } |
471 | } |
427 | OUTPUT: |
472 | OUTPUT: |
428 | RETVAL |
473 | RETVAL |
429 | |
474 | |
… | |
… | |
471 | static const struct { |
516 | static const struct { |
472 | const char *name; |
517 | const char *name; |
473 | IV iv; |
518 | IV iv; |
474 | } *civ, const_iv[] = { |
519 | } *civ, const_iv[] = { |
475 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
520 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
476 | |
|
|
477 | const_iv (DNS_, ERR_NONE) |
521 | const_iv (DNS_, ERR_NONE) |
478 | const_iv (DNS_, ERR_FORMAT) |
522 | const_iv (DNS_, ERR_FORMAT) |
479 | const_iv (DNS_, ERR_SERVERFAILED) |
523 | const_iv (DNS_, ERR_SERVERFAILED) |
480 | const_iv (DNS_, ERR_NOTEXIST) |
524 | const_iv (DNS_, ERR_NOTEXIST) |
481 | const_iv (DNS_, ERR_NOTIMPL) |
525 | const_iv (DNS_, ERR_NOTIMPL) |
… | |
… | |
527 | CODE: |
571 | CODE: |
528 | { |
572 | { |
529 | STRLEN len; |
573 | STRLEN len; |
530 | char *data = SvPVbyte (addr, len); |
574 | char *data = SvPVbyte (addr, len); |
531 | if (len != (ix ? 16 : 4)) |
575 | if (len != (ix ? 16 : 4)) |
532 | croak ("ipv4/ipv6 address to resolve must be given as 4/16 byte octet string"); |
576 | croak ("ipv4/ipv6 address to be resolved must be given as 4/16 byte octet string"); |
533 | |
577 | |
534 | RETVAL = ix |
578 | RETVAL = ix |
535 | ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)) |
579 | ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)) |
536 | : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)); |
580 | : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)); |
537 | } |
581 | } |
… | |
… | |
552 | |
596 | |
553 | void evdns_search_add (char *domain) |
597 | void evdns_search_add (char *domain) |
554 | |
598 | |
555 | void evdns_search_ndots_set (int ndots) |
599 | void evdns_search_ndots_set (int ndots) |
556 | |
600 | |
|
|
601 | |
|
|
602 | MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ |
|
|
603 | |
|
|
604 | BOOT: |
|
|
605 | { |
|
|
606 | HV *stash = gv_stashpv ("EV::HTTP", 1); |
|
|
607 | |
|
|
608 | static const struct { |
|
|
609 | const char *name; |
|
|
610 | IV iv; |
|
|
611 | } *civ, const_iv[] = { |
|
|
612 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
|
|
613 | const_iv (HTTP_, OK) |
|
|
614 | const_iv (HTTP_, NOCONTENT) |
|
|
615 | const_iv (HTTP_, MOVEPERM) |
|
|
616 | const_iv (HTTP_, MOVETEMP) |
|
|
617 | const_iv (HTTP_, NOTMODIFIED) |
|
|
618 | const_iv (HTTP_, BADREQUEST) |
|
|
619 | const_iv (HTTP_, NOTFOUND) |
|
|
620 | const_iv (HTTP_, SERVUNAVAIL) |
|
|
621 | const_iv (EVHTTP_, REQ_OWN_CONNECTION) |
|
|
622 | const_iv (EVHTTP_, PROXY_REQUEST) |
|
|
623 | const_iv (EVHTTP_, REQ_GET) |
|
|
624 | const_iv (EVHTTP_, REQ_POST) |
|
|
625 | const_iv (EVHTTP_, REQ_HEAD) |
|
|
626 | const_iv (EVHTTP_, REQUEST) |
|
|
627 | const_iv (EVHTTP_, RESPONSE) |
|
|
628 | }; |
|
|
629 | |
|
|
630 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
|
|
631 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
|
|
632 | } |
|
|
633 | |
|
|
634 | MODULE = EV PACKAGE = EV::HTTP::Request PREFIX = evhttp_request_ |
|
|
635 | |
|
|
636 | #HttpRequest new (SV *klass, SV *cb) |
|
|
637 | |
|
|
638 | #void DESTROY (struct evhttp_request *req); |
|
|
639 | |
|
|
640 | |
|
|
641 | |
|
|
642 | |
|
|
643 | |
|
|
644 | |
|
|
645 | |
|
|
646 | |