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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines