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

Comparing EV/EV.xs (file contents):
Revision 1.15 by root, Wed Oct 31 10:50:05 2007 UTC vs.
Revision 1.20 by root, Wed Oct 31 13:57:34 2007 UTC

1#include "EXTERN.h" 1#include "EXTERN.h"
2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4 4
5#include <math.h>
6#include <netinet/in.h> 5/*#include <netinet/in.h>*/
7 6
8#define TIMEOUT_NONE HUGE_VAL 7#define TIMEOUT_NONE HUGE_VAL
9 8
10#define EV_COMMON \ 9#define EV_PROTOTYPES 1
11 SV *self; /* contains this struct */ \
12 SV *cb_sv, *fh;
13
14#include "EV/EVAPI.h" 10#include "EV/EVAPI.h"
11
12#include "libev/ev.c"
15 13
16typedef int Signal; 14typedef int Signal;
17 15
18static struct EVAPI evapi; 16static struct EVAPI evapi;
19 17
38 for (signum = 1; signum < SIG_SIZE; ++signum) 36 for (signum = 1; signum < SIG_SIZE; ++signum)
39 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) 37 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum]))
40 return signum; 38 return signum;
41 39
42 return -1; 40 return -1;
43}
44
45static void
46api_once (int fd, short events, double timeout, void (*cb)(int, short, void *), void *arg)
47{
48#if 0
49 if (timeout >= 0.)
50 {
51 struct timeval tv;
52 tv_set (&tv, timeout);
53 event_once (fd, events, cb, arg, &tv);
54 }
55 else
56 event_once (fd, events, cb, arg, 0);
57#endif
58} 41}
59 42
60///////////////////////////////////////////////////////////////////////////// 43/////////////////////////////////////////////////////////////////////////////
61// Event 44// Event
62 45
209 192
210 LEAVE; 193 LEAVE;
211} 194}
212#endif 195#endif
213 196
197#define CHECK_REPEAT(repeat) if (repeat < 0.) \
198 croak (# repeat " value must be >= 0");
199
214///////////////////////////////////////////////////////////////////////////// 200/////////////////////////////////////////////////////////////////////////////
215// XS interface functions 201// XS interface functions
216 202
217MODULE = EV PACKAGE = EV PREFIX = ev_ 203MODULE = EV PACKAGE = EV PREFIX = ev_
218 204
224 static const struct { 210 static const struct {
225 const char *name; 211 const char *name;
226 IV iv; 212 IV iv;
227 } *civ, const_iv[] = { 213 } *civ, const_iv[] = {
228# define const_iv(pfx, name) { # name, (IV) pfx ## name }, 214# define const_iv(pfx, name) { # name, (IV) pfx ## name },
215 const_iv (EV_, UNDEF)
229 const_iv (EV_, NONE) 216 const_iv (EV_, NONE)
230 const_iv (EV_, TIMEOUT) 217 const_iv (EV_, TIMEOUT)
231 const_iv (EV_, READ) 218 const_iv (EV_, READ)
232 const_iv (EV_, WRITE) 219 const_iv (EV_, WRITE)
233 const_iv (EV_, SIGNAL) 220 const_iv (EV_, SIGNAL)
234 const_iv (EV_, IDLE) 221 const_iv (EV_, IDLE)
235 const_iv (EV_, CHECK) 222 const_iv (EV_, CHECK)
223 const_iv (EV_, ERROR)
236 224
237 const_iv (EV, LOOP_ONESHOT) 225 const_iv (EV, LOOP_ONESHOT)
238 const_iv (EV, LOOP_NONBLOCK) 226 const_iv (EV, LOOP_NONBLOCK)
239 227
240 const_iv (EV, METHOD_NONE) 228 const_iv (EV, METHOD_NONE)
259 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 247 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
260 248
261 /* the poor man's shared library emulator */ 249 /* the poor man's shared library emulator */
262 evapi.ver = EV_API_VERSION; 250 evapi.ver = EV_API_VERSION;
263 evapi.rev = EV_API_REVISION; 251 evapi.rev = EV_API_REVISION;
264 evapi.once = api_once;
265 evapi.sv_fileno = sv_fileno; 252 evapi.sv_fileno = sv_fileno;
266 evapi.sv_signum = sv_signum; 253 evapi.sv_signum = sv_signum;
267 evapi.now = &ev_now; 254 evapi.now = &ev_now;
268 evapi.method = &ev_method; 255 evapi.method = &ev_method;
269 evapi.loop_done = &ev_loop_done; 256 evapi.loop_done = &ev_loop_done;
270 evapi.time = ev_time; 257 evapi.time = ev_time;
271 evapi.loop = ev_loop; 258 evapi.loop = ev_loop;
259 evapi.once = ev_once;
272 evapi.io_start = evio_start; 260 evapi.io_start = evio_start;
273 evapi.io_stop = evio_stop; 261 evapi.io_stop = evio_stop;
274 evapi.timer_start = evtimer_start; 262 evapi.timer_start = evtimer_start;
275 evapi.timer_stop = evtimer_stop; 263 evapi.timer_stop = evtimer_stop;
264 evapi.timer_again = evtimer_again;
276 evapi.periodic_start = evperiodic_start; 265 evapi.periodic_start = evperiodic_start;
277 evapi.periodic_stop = evperiodic_stop; 266 evapi.periodic_stop = evperiodic_stop;
278 evapi.signal_start = evsignal_start; 267 evapi.signal_start = evsignal_start;
279 evapi.signal_stop = evsignal_stop; 268 evapi.signal_stop = evsignal_stop;
280 evapi.idle_start = evidle_start; 269 evapi.idle_start = evidle_start;
308void ev_loop_done (int value = 1) 297void ev_loop_done (int value = 1)
309 CODE: 298 CODE:
310 ev_loop_done = value; 299 ev_loop_done = value;
311 300
312struct ev_io *io (SV *fh, int events, SV *cb) 301struct ev_io *io (SV *fh, int events, SV *cb)
302 PROTOTYPE: $$&
313 ALIAS: 303 ALIAS:
314 io_ns = 1 304 io_ns = 1
315 CODE: 305 CODE:
316 RETVAL = e_new (sizeof (struct ev_io), cb); 306 RETVAL = e_new (sizeof (struct ev_io), cb);
317 RETVAL->fh = newSVsv (fh); 307 RETVAL->fh = newSVsv (fh);
319 if (!ix) evio_start (RETVAL); 309 if (!ix) evio_start (RETVAL);
320 OUTPUT: 310 OUTPUT:
321 RETVAL 311 RETVAL
322 312
323struct ev_timer *timer (NV after, NV repeat, SV *cb) 313struct ev_timer *timer (NV after, NV repeat, SV *cb)
314 PROTOTYPE: $$&
324 ALIAS: 315 ALIAS:
325 timer_ns = 1 316 timer_ns = 1
317 INIT:
318 CHECK_REPEAT (repeat);
326 CODE: 319 CODE:
327 RETVAL = e_new (sizeof (struct ev_timer), cb); 320 RETVAL = e_new (sizeof (struct ev_timer), cb);
328 evtimer_set (RETVAL, after, repeat); 321 evtimer_set (RETVAL, after, repeat);
329 if (!ix) evtimer_start (RETVAL); 322 if (!ix) evtimer_start (RETVAL);
330 OUTPUT: 323 OUTPUT:
331 RETVAL 324 RETVAL
332 325
333struct ev_periodic *periodic (NV at, NV interval, SV *cb) 326struct ev_periodic *periodic (NV at, NV interval, SV *cb)
327 PROTOTYPE: $$&
334 ALIAS: 328 ALIAS:
335 periodic_ns = 1 329 periodic_ns = 1
330 INIT:
331 CHECK_REPEAT (interval);
336 CODE: 332 CODE:
337 RETVAL = e_new (sizeof (struct ev_periodic), cb); 333 RETVAL = e_new (sizeof (struct ev_periodic), cb);
338 evperiodic_set (RETVAL, at, interval); 334 evperiodic_set (RETVAL, at, interval);
339 if (!ix) evperiodic_start (RETVAL); 335 if (!ix) evperiodic_start (RETVAL);
340 OUTPUT: 336 OUTPUT:
341 RETVAL 337 RETVAL
342 338
343struct ev_signal *signal (Signal signum, SV *cb) 339struct ev_signal *signal (Signal signum, SV *cb)
340 PROTOTYPE: $&
344 ALIAS: 341 ALIAS:
345 signal_ns = 1 342 signal_ns = 1
346 CODE: 343 CODE:
347 RETVAL = e_new (sizeof (struct ev_signal), cb); 344 RETVAL = e_new (sizeof (struct ev_signal), cb);
348 evsignal_set (RETVAL, signum); 345 evsignal_set (RETVAL, signum);
349 if (!ix) evsignal_start (RETVAL); 346 if (!ix) evsignal_start (RETVAL);
350 OUTPUT: 347 OUTPUT:
351 RETVAL 348 RETVAL
352 349
353struct ev_idle *idle (SV *cb) 350struct ev_idle *idle (SV *cb)
351 PROTOTYPE: &
354 ALIAS: 352 ALIAS:
355 idle_ns = 1 353 idle_ns = 1
356 CODE: 354 CODE:
357 RETVAL = e_new (sizeof (struct ev_idle), cb); 355 RETVAL = e_new (sizeof (struct ev_idle), cb);
358 evidle_set (RETVAL); 356 evidle_set (RETVAL);
359 if (!ix) evidle_start (RETVAL); 357 if (!ix) evidle_start (RETVAL);
360 OUTPUT: 358 OUTPUT:
361 RETVAL 359 RETVAL
362 360
363struct ev_check *check (SV *cb) 361struct ev_check *check (SV *cb)
362 PROTOTYPE: &
364 ALIAS: 363 ALIAS:
365 check_ns = 1 364 check_ns = 1
366 CODE: 365 CODE:
367 RETVAL = e_new (sizeof (struct ev_check), cb); 366 RETVAL = e_new (sizeof (struct ev_check), cb);
368 evcheck_set (RETVAL); 367 evcheck_set (RETVAL);
463MODULE = EV PACKAGE = EV::Time 462MODULE = EV PACKAGE = EV::Time
464 463
465MODULE = EV PACKAGE = EV::Timer PREFIX = evtimer_ 464MODULE = EV PACKAGE = EV::Timer PREFIX = evtimer_
466 465
467void evtimer_start (struct ev_timer *w) 466void evtimer_start (struct ev_timer *w)
467 INIT:
468 CHECK_REPEAT (w->repeat);
468 469
469void evtimer_stop (struct ev_timer *w) 470void evtimer_stop (struct ev_timer *w)
470 471
472void evtimer_again (struct ev_timer *w)
473 INIT:
474 CHECK_REPEAT (w->repeat);
475
471void set (struct ev_timer *w, NV after, NV repeat = 0.) 476void set (struct ev_timer *w, NV after, NV repeat = 0.)
477 INIT:
478 CHECK_REPEAT (repeat);
472 CODE: 479 CODE:
473{ 480{
474 int active = w->active; 481 int active = w->active;
475 if (active) evtimer_stop (w); 482 if (active) evtimer_stop (w);
476 evtimer_set (w, after, repeat); 483 evtimer_set (w, after, repeat);
478} 485}
479 486
480MODULE = EV PACKAGE = EV::Periodic PREFIX = evperiodic_ 487MODULE = EV PACKAGE = EV::Periodic PREFIX = evperiodic_
481 488
482void evperiodic_start (struct ev_periodic *w) 489void evperiodic_start (struct ev_periodic *w)
490 INIT:
491 CHECK_REPEAT (w->interval);
483 492
484void evperiodic_stop (struct ev_periodic *w) 493void evperiodic_stop (struct ev_periodic *w)
485 494
486void set (struct ev_periodic *w, NV at, NV interval = 0.) 495void set (struct ev_periodic *w, NV at, NV interval = 0.)
496 INIT:
497 CHECK_REPEAT (interval);
487 CODE: 498 CODE:
488{ 499{
489 int active = w->active; 500 int active = w->active;
490 if (active) evperiodic_stop (w); 501 if (active) evperiodic_stop (w);
491 evperiodic_set (w, at, interval); 502 evperiodic_set (w, at, interval);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines