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

Comparing EV/EV.xs (file contents):
Revision 1.3 by root, Fri Oct 26 17:24:18 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
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
471 static const struct { 495 static const struct {
472 const char *name; 496 const char *name;
473 IV iv; 497 IV iv;
474 } *civ, const_iv[] = { 498 } *civ, const_iv[] = {
475# define const_iv(pfx, name) { # name, (IV) pfx ## name }, 499# define const_iv(pfx, name) { # name, (IV) pfx ## name },
476
477 const_iv (DNS_, ERR_NONE) 500 const_iv (DNS_, ERR_NONE)
478 const_iv (DNS_, ERR_FORMAT) 501 const_iv (DNS_, ERR_FORMAT)
479 const_iv (DNS_, ERR_SERVERFAILED) 502 const_iv (DNS_, ERR_SERVERFAILED)
480 const_iv (DNS_, ERR_NOTEXIST) 503 const_iv (DNS_, ERR_NOTEXIST)
481 const_iv (DNS_, ERR_NOTIMPL) 504 const_iv (DNS_, ERR_NOTIMPL)
527 CODE: 550 CODE:
528{ 551{
529 STRLEN len; 552 STRLEN len;
530 char *data = SvPVbyte (addr, len); 553 char *data = SvPVbyte (addr, len);
531 if (len != (ix ? 16 : 4)) 554 if (len != (ix ? 16 : 4))
532 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");
533 556
534 RETVAL = ix 557 RETVAL = ix
535 ? 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))
536 : 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));
537} 560}
552 575
553void evdns_search_add (char *domain) 576void evdns_search_add (char *domain)
554 577
555void evdns_search_ndots_set (int ndots) 578void evdns_search_ndots_set (int ndots)
556 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