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

Comparing EV/EV.xs (file contents):
Revision 1.19 by root, Wed Oct 31 11:59:54 2007 UTC vs.
Revision 1.22 by root, Wed Oct 31 18:28:00 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
8#define HAVE_EPOLL 1
9 9
10#define EV_COMMON \ 10#define EV_PROTOTYPES 1
11 SV *self; /* contains this struct */ \
12 SV *cb_sv, *fh;
13
14#include "EV/EVAPI.h" 11#include "EV/EVAPI.h"
15 12
16#include "libev/ev.c" 13#include "libev/ev.c"
17 14
18typedef int Signal; 15typedef int Signal;
25 *stash_time, 22 *stash_time,
26 *stash_timer, 23 *stash_timer,
27 *stash_periodic, 24 *stash_periodic,
28 *stash_signal, 25 *stash_signal,
29 *stash_idle, 26 *stash_idle,
27 *stash_prepare,
30 *stash_check; 28 *stash_check;
31 29
32static int 30static int
33sv_signum (SV *sig) 31sv_signum (SV *sig)
34{ 32{
40 for (signum = 1; signum < SIG_SIZE; ++signum) 38 for (signum = 1; signum < SIG_SIZE; ++signum)
41 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) 39 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum]))
42 return signum; 40 return signum;
43 41
44 return -1; 42 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} 43}
61 44
62///////////////////////////////////////////////////////////////////////////// 45/////////////////////////////////////////////////////////////////////////////
63// Event 46// Event
64 47
219///////////////////////////////////////////////////////////////////////////// 202/////////////////////////////////////////////////////////////////////////////
220// XS interface functions 203// XS interface functions
221 204
222MODULE = EV PACKAGE = EV PREFIX = ev_ 205MODULE = EV PACKAGE = EV PREFIX = ev_
223 206
207PROTOTYPES: ENABLE
208
224BOOT: 209BOOT:
225{ 210{
226 int i; 211 int i;
227 HV *stash = gv_stashpv ("EV", 1); 212 HV *stash = gv_stashpv ("EV", 1);
228 213
229 static const struct { 214 static const struct {
230 const char *name; 215 const char *name;
231 IV iv; 216 IV iv;
232 } *civ, const_iv[] = { 217 } *civ, const_iv[] = {
233# define const_iv(pfx, name) { # name, (IV) pfx ## name }, 218# define const_iv(pfx, name) { # name, (IV) pfx ## name },
219 const_iv (EV_, UNDEF)
234 const_iv (EV_, NONE) 220 const_iv (EV_, NONE)
235 const_iv (EV_, TIMEOUT) 221 const_iv (EV_, TIMEOUT)
236 const_iv (EV_, READ) 222 const_iv (EV_, READ)
237 const_iv (EV_, WRITE) 223 const_iv (EV_, WRITE)
238 const_iv (EV_, SIGNAL) 224 const_iv (EV_, SIGNAL)
239 const_iv (EV_, IDLE) 225 const_iv (EV_, IDLE)
240 const_iv (EV_, CHECK) 226 const_iv (EV_, CHECK)
227 const_iv (EV_, ERROR)
241 228
242 const_iv (EV, LOOP_ONESHOT) 229 const_iv (EV, LOOP_ONESHOT)
243 const_iv (EV, LOOP_NONBLOCK) 230 const_iv (EV, LOOP_NONBLOCK)
244 231
245 const_iv (EV, METHOD_NONE) 232 const_iv (EV, METHOD_NONE)
255 stash_time = gv_stashpv ("EV::Time" , 1); 242 stash_time = gv_stashpv ("EV::Time" , 1);
256 stash_timer = gv_stashpv ("EV::Timer" , 1); 243 stash_timer = gv_stashpv ("EV::Timer" , 1);
257 stash_periodic = gv_stashpv ("EV::Periodic", 1); 244 stash_periodic = gv_stashpv ("EV::Periodic", 1);
258 stash_signal = gv_stashpv ("EV::Signal" , 1); 245 stash_signal = gv_stashpv ("EV::Signal" , 1);
259 stash_idle = gv_stashpv ("EV::Idle" , 1); 246 stash_idle = gv_stashpv ("EV::Idle" , 1);
247 stash_prepare = gv_stashpv ("EV::Prepare" , 1);
260 stash_check = gv_stashpv ("EV::Check" , 1); 248 stash_check = gv_stashpv ("EV::Check" , 1);
261 249
262 { 250 {
263 SV *sv = perl_get_sv ("EV::API", TRUE); 251 SV *sv = perl_get_sv ("EV::API", TRUE);
264 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 252 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
265 253
266 /* the poor man's shared library emulator */ 254 /* the poor man's shared library emulator */
267 evapi.ver = EV_API_VERSION; 255 evapi.ver = EV_API_VERSION;
268 evapi.rev = EV_API_REVISION; 256 evapi.rev = EV_API_REVISION;
269 evapi.once = api_once;
270 evapi.sv_fileno = sv_fileno; 257 evapi.sv_fileno = sv_fileno;
271 evapi.sv_signum = sv_signum; 258 evapi.sv_signum = sv_signum;
272 evapi.now = &ev_now; 259 evapi.now = &ev_now;
273 evapi.method = &ev_method; 260 evapi.method = &ev_method;
274 evapi.loop_done = &ev_loop_done; 261 evapi.loop_done = &ev_loop_done;
275 evapi.time = ev_time; 262 evapi.time = ev_time;
276 evapi.loop = ev_loop; 263 evapi.loop = ev_loop;
264 evapi.once = ev_once;
277 evapi.io_start = evio_start; 265 evapi.io_start = evio_start;
278 evapi.io_stop = evio_stop; 266 evapi.io_stop = evio_stop;
279 evapi.timer_start = evtimer_start; 267 evapi.timer_start = evtimer_start;
280 evapi.timer_stop = evtimer_stop; 268 evapi.timer_stop = evtimer_stop;
281 evapi.timer_again = evtimer_again; 269 evapi.timer_again = evtimer_again;
283 evapi.periodic_stop = evperiodic_stop; 271 evapi.periodic_stop = evperiodic_stop;
284 evapi.signal_start = evsignal_start; 272 evapi.signal_start = evsignal_start;
285 evapi.signal_stop = evsignal_stop; 273 evapi.signal_stop = evsignal_stop;
286 evapi.idle_start = evidle_start; 274 evapi.idle_start = evidle_start;
287 evapi.idle_stop = evidle_stop; 275 evapi.idle_stop = evidle_stop;
276 evapi.prepare_start = evprepare_start;
277 evapi.prepare_stop = evprepare_stop;
288 evapi.check_start = evcheck_start; 278 evapi.check_start = evcheck_start;
289 evapi.check_stop = evcheck_stop; 279 evapi.check_stop = evcheck_stop;
290 280
291 sv_setiv (sv, (IV)&evapi); 281 sv_setiv (sv, (IV)&evapi);
292 SvREADONLY_on (sv); 282 SvREADONLY_on (sv);
314void ev_loop_done (int value = 1) 304void ev_loop_done (int value = 1)
315 CODE: 305 CODE:
316 ev_loop_done = value; 306 ev_loop_done = value;
317 307
318struct ev_io *io (SV *fh, int events, SV *cb) 308struct ev_io *io (SV *fh, int events, SV *cb)
319 PROTOTYPE: $$&
320 ALIAS: 309 ALIAS:
321 io_ns = 1 310 io_ns = 1
322 CODE: 311 CODE:
323 RETVAL = e_new (sizeof (struct ev_io), cb); 312 RETVAL = e_new (sizeof (struct ev_io), cb);
324 RETVAL->fh = newSVsv (fh); 313 RETVAL->fh = newSVsv (fh);
326 if (!ix) evio_start (RETVAL); 315 if (!ix) evio_start (RETVAL);
327 OUTPUT: 316 OUTPUT:
328 RETVAL 317 RETVAL
329 318
330struct ev_timer *timer (NV after, NV repeat, SV *cb) 319struct ev_timer *timer (NV after, NV repeat, SV *cb)
331 PROTOTYPE: $$&
332 ALIAS: 320 ALIAS:
333 timer_ns = 1 321 timer_ns = 1
334 INIT: 322 INIT:
335 CHECK_REPEAT (repeat); 323 CHECK_REPEAT (repeat);
336 CODE: 324 CODE:
339 if (!ix) evtimer_start (RETVAL); 327 if (!ix) evtimer_start (RETVAL);
340 OUTPUT: 328 OUTPUT:
341 RETVAL 329 RETVAL
342 330
343struct ev_periodic *periodic (NV at, NV interval, SV *cb) 331struct ev_periodic *periodic (NV at, NV interval, SV *cb)
344 PROTOTYPE: $$&
345 ALIAS: 332 ALIAS:
346 periodic_ns = 1 333 periodic_ns = 1
347 INIT: 334 INIT:
348 CHECK_REPEAT (interval); 335 CHECK_REPEAT (interval);
349 CODE: 336 CODE:
352 if (!ix) evperiodic_start (RETVAL); 339 if (!ix) evperiodic_start (RETVAL);
353 OUTPUT: 340 OUTPUT:
354 RETVAL 341 RETVAL
355 342
356struct ev_signal *signal (Signal signum, SV *cb) 343struct ev_signal *signal (Signal signum, SV *cb)
357 PROTOTYPE: $&
358 ALIAS: 344 ALIAS:
359 signal_ns = 1 345 signal_ns = 1
360 CODE: 346 CODE:
361 RETVAL = e_new (sizeof (struct ev_signal), cb); 347 RETVAL = e_new (sizeof (struct ev_signal), cb);
362 evsignal_set (RETVAL, signum); 348 evsignal_set (RETVAL, signum);
363 if (!ix) evsignal_start (RETVAL); 349 if (!ix) evsignal_start (RETVAL);
364 OUTPUT: 350 OUTPUT:
365 RETVAL 351 RETVAL
366 352
367struct ev_idle *idle (SV *cb) 353struct ev_idle *idle (SV *cb)
368 PROTOTYPE: &
369 ALIAS: 354 ALIAS:
370 idle_ns = 1 355 idle_ns = 1
371 CODE: 356 CODE:
372 RETVAL = e_new (sizeof (struct ev_idle), cb); 357 RETVAL = e_new (sizeof (struct ev_idle), cb);
373 evidle_set (RETVAL); 358 evidle_set (RETVAL);
374 if (!ix) evidle_start (RETVAL); 359 if (!ix) evidle_start (RETVAL);
375 OUTPUT: 360 OUTPUT:
376 RETVAL 361 RETVAL
377 362
363struct ev_prepare *prepare (SV *cb)
364 ALIAS:
365 prepare_ns = 1
366 CODE:
367 RETVAL = e_new (sizeof (struct ev_prepare), cb);
368 evprepare_set (RETVAL);
369 if (!ix) evprepare_start (RETVAL);
370 OUTPUT:
371 RETVAL
372
378struct ev_check *check (SV *cb) 373struct ev_check *check (SV *cb)
379 PROTOTYPE: &
380 ALIAS: 374 ALIAS:
381 check_ns = 1 375 check_ns = 1
382 CODE: 376 CODE:
383 RETVAL = e_new (sizeof (struct ev_check), cb); 377 RETVAL = e_new (sizeof (struct ev_check), cb);
384 evcheck_set (RETVAL); 378 evcheck_set (RETVAL);
523MODULE = EV PACKAGE = EV::Idle PREFIX = evidle_ 517MODULE = EV PACKAGE = EV::Idle PREFIX = evidle_
524 518
525void evidle_start (struct ev_idle *w) 519void evidle_start (struct ev_idle *w)
526 520
527void evidle_stop (struct ev_idle *w) 521void evidle_stop (struct ev_idle *w)
522
523MODULE = EV PACKAGE = EV::Prepare PREFIX = evcheck_
524
525void evprepare_start (struct ev_prepare *w)
526
527void evprepare_stop (struct ev_prepare *w)
528 528
529MODULE = EV PACKAGE = EV::Check PREFIX = evcheck_ 529MODULE = EV PACKAGE = EV::Check PREFIX = evcheck_
530 530
531void evcheck_start (struct ev_check *w) 531void evcheck_start (struct ev_check *w)
532 532

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines