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

Comparing EV/EV.xs (file contents):
Revision 1.1 by root, Fri Oct 26 16:50:05 2007 UTC vs.
Revision 1.5 by root, Fri Oct 26 19:11:35 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
283 289
284int event_dispatch () 290int event_dispatch ()
285 291
286int event_loop (int flags = 0) 292int event_loop (int flags = 0)
287 293
288int event_loopexit (double after) 294int event_loopexit (double after = 0)
289 CODE: 295 CODE:
290{ 296{
291 struct timeval tv; 297 struct timeval tv;
292 tv_set (&tv, after); 298 tv_set (&tv, after);
293 event_loopexit (&tv); 299 event_loopexit (&tv);
294} 300}
295 301
296Event event (SV *cb) 302Event event (SV *cb)
297 CODE: 303 CODE:
298 RETVAL = e_new (0, 0, cb); 304 RETVAL = e_new (NEWSV (0, 0), 0, cb);
299 OUTPUT: 305 OUTPUT:
300 RETVAL 306 RETVAL
301 307
302Event io (SV *fh, short events, SV *cb) 308Event io (SV *fh, short events, SV *cb)
303 ALIAS: 309 ALIAS:
310 316
311Event timer (double after, int repeat, SV *cb) 317Event timer (double after, int repeat, SV *cb)
312 ALIAS: 318 ALIAS:
313 timer_ns = 1 319 timer_ns = 1
314 CODE: 320 CODE:
315 RETVAL = e_new (0, 0, cb); 321 RETVAL = e_new (NEWSV (0, 0), 0, cb);
316 RETVAL->timeout = after; 322 RETVAL->timeout = after;
317 RETVAL->interval = repeat; 323 RETVAL->interval = repeat;
318 if (!ix) e_start (RETVAL); 324 if (!ix) e_start (RETVAL);
319 OUTPUT: 325 OUTPUT:
320 RETVAL 326 RETVAL
321 327
322Event timer_abs (double at, double interval, SV *cb) 328Event timer_abs (double at, double interval, SV *cb)
323 ALIAS: 329 ALIAS:
324 timer_abs_ns = 1 330 timer_abs_ns = 1
325 CODE: 331 CODE:
326 RETVAL = e_new (0, 0, cb); 332 RETVAL = e_new (NEWSV (0, 0), 0, cb);
327 RETVAL->timeout = at; 333 RETVAL->timeout = at;
328 RETVAL->interval = interval; 334 RETVAL->interval = interval;
329 RETVAL->abstime = 1; 335 RETVAL->abstime = 1;
330 if (!ix) e_start (RETVAL); 336 if (!ix) e_start (RETVAL);
331 OUTPUT: 337 OUTPUT:
405 CODE: 411 CODE:
406 e_stop (ev); 412 e_stop (ev);
407 SvREFCNT_dec (ev->cb); 413 SvREFCNT_dec (ev->cb);
408 SvREFCNT_dec (ev->fh); 414 SvREFCNT_dec (ev->fh);
409 415
410void cb (Event ev, SV *new_cb) 416SV *cb (Event ev, SV *new_cb = 0)
411 CODE: 417 CODE:
418 RETVAL = newSVsv (ev->cb);
419 if (items > 1)
412 sv_setsv (ev->cb, new_cb); 420 sv_setsv (ev->cb, new_cb);
421 OUTPUT:
422 RETVAL
413 423
414SV *fh (Event ev, SV *new_fh = 0) 424SV *fh (Event ev, SV *new_fh = 0)
415 ALIAS: 425 ALIAS:
416 signal = 0 426 signal = 0
417 CODE: 427 CODE:
418 RETVAL = newSVsv (ev->fh); 428 RETVAL = newSVsv (ev->fh);
419 if (items > 1) 429 if (items > 1)
420 { 430 {
421 if (ev->active) event_del (&ev->ev); 431 if (ev->active) event_del (&ev->ev);
422 sv_setsv (ev->fh, new_fh); 432 sv_setsv (ev->fh, new_fh);
423 ev->ev.ev_fd = e_fd (ev); 433 ev->ev.ev_fd = sv_fileno (ev->fh);
424 if (ev->active) event_add (&ev->ev, e_tv (ev)); 434 if (ev->active) event_add (&ev->ev, e_tv (ev));
425 } 435 }
426 OUTPUT: 436 OUTPUT:
427 RETVAL 437 RETVAL
428 438
470 static const struct { 480 static const struct {
471 const char *name; 481 const char *name;
472 IV iv; 482 IV iv;
473 } *civ, const_iv[] = { 483 } *civ, const_iv[] = {
474# define const_iv(pfx, name) { # name, (IV) pfx ## name }, 484# define const_iv(pfx, name) { # name, (IV) pfx ## name },
475
476 const_iv (DNS_, ERR_NONE) 485 const_iv (DNS_, ERR_NONE)
477 const_iv (DNS_, ERR_FORMAT) 486 const_iv (DNS_, ERR_FORMAT)
478 const_iv (DNS_, ERR_SERVERFAILED) 487 const_iv (DNS_, ERR_SERVERFAILED)
479 const_iv (DNS_, ERR_NOTEXIST) 488 const_iv (DNS_, ERR_NOTEXIST)
480 const_iv (DNS_, ERR_NOTIMPL) 489 const_iv (DNS_, ERR_NOTIMPL)
551 560
552void evdns_search_add (char *domain) 561void evdns_search_add (char *domain)
553 562
554void evdns_search_ndots_set (int ndots) 563void evdns_search_ndots_set (int ndots)
555 564
565
566MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
567
568BOOT:
569{
570 HV *stash = gv_stashpv ("EV::HTTP", 1);
571
572 static const struct {
573 const char *name;
574 IV iv;
575 } *civ, const_iv[] = {
576# define const_iv(pfx, name) { # name, (IV) pfx ## name },
577 const_iv (HTTP_, OK)
578 const_iv (HTTP_, NOCONTENT)
579 const_iv (HTTP_, MOVEPERM)
580 const_iv (HTTP_, MOVETEMP)
581 const_iv (HTTP_, NOTMODIFIED)
582 const_iv (HTTP_, BADREQUEST)
583 const_iv (HTTP_, NOTFOUND)
584 const_iv (HTTP_, SERVUNAVAIL)
585 const_iv (EVHTTP_, REQ_OWN_CONNECTION)
586 const_iv (EVHTTP_, PROXY_REQUEST)
587 const_iv (EVHTTP_, REQ_GET)
588 const_iv (EVHTTP_, REQ_POST)
589 const_iv (EVHTTP_, REQ_HEAD)
590 const_iv (EVHTTP_, REQUEST)
591 const_iv (EVHTTP_, RESPONSE)
592 };
593
594 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
595 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
596}
597
598MODULE = EV PACKAGE = EV::HTTP::Request PREFIX = evhttp_request_
599
600#HttpRequest new (SV *klass, SV *cb)
601
602#void DESTROY (struct evhttp_request *req);
603
604
605
606
607
608
609
610

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines