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

Comparing EV/EV.xs (file contents):
Revision 1.18 by root, Wed Oct 31 11:55:42 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
229 static const struct { 210 static const struct {
230 const char *name; 211 const char *name;
231 IV iv; 212 IV iv;
232 } *civ, const_iv[] = { 213 } *civ, const_iv[] = {
233# define const_iv(pfx, name) { # name, (IV) pfx ## name }, 214# define const_iv(pfx, name) { # name, (IV) pfx ## name },
215 const_iv (EV_, UNDEF)
234 const_iv (EV_, NONE) 216 const_iv (EV_, NONE)
235 const_iv (EV_, TIMEOUT) 217 const_iv (EV_, TIMEOUT)
236 const_iv (EV_, READ) 218 const_iv (EV_, READ)
237 const_iv (EV_, WRITE) 219 const_iv (EV_, WRITE)
238 const_iv (EV_, SIGNAL) 220 const_iv (EV_, SIGNAL)
239 const_iv (EV_, IDLE) 221 const_iv (EV_, IDLE)
240 const_iv (EV_, CHECK) 222 const_iv (EV_, CHECK)
223 const_iv (EV_, ERROR)
241 224
242 const_iv (EV, LOOP_ONESHOT) 225 const_iv (EV, LOOP_ONESHOT)
243 const_iv (EV, LOOP_NONBLOCK) 226 const_iv (EV, LOOP_NONBLOCK)
244 227
245 const_iv (EV, METHOD_NONE) 228 const_iv (EV, METHOD_NONE)
264 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 247 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
265 248
266 /* the poor man's shared library emulator */ 249 /* the poor man's shared library emulator */
267 evapi.ver = EV_API_VERSION; 250 evapi.ver = EV_API_VERSION;
268 evapi.rev = EV_API_REVISION; 251 evapi.rev = EV_API_REVISION;
269 evapi.once = api_once;
270 evapi.sv_fileno = sv_fileno; 252 evapi.sv_fileno = sv_fileno;
271 evapi.sv_signum = sv_signum; 253 evapi.sv_signum = sv_signum;
272 evapi.now = &ev_now; 254 evapi.now = &ev_now;
273 evapi.method = &ev_method; 255 evapi.method = &ev_method;
274 evapi.loop_done = &ev_loop_done; 256 evapi.loop_done = &ev_loop_done;
275 evapi.time = ev_time; 257 evapi.time = ev_time;
276 evapi.loop = ev_loop; 258 evapi.loop = ev_loop;
259 evapi.once = ev_once;
277 evapi.io_start = evio_start; 260 evapi.io_start = evio_start;
278 evapi.io_stop = evio_stop; 261 evapi.io_stop = evio_stop;
279 evapi.timer_start = evtimer_start; 262 evapi.timer_start = evtimer_start;
280 evapi.timer_stop = evtimer_stop; 263 evapi.timer_stop = evtimer_stop;
281 evapi.timer_again = evtimer_again; 264 evapi.timer_again = evtimer_again;
314void ev_loop_done (int value = 1) 297void ev_loop_done (int value = 1)
315 CODE: 298 CODE:
316 ev_loop_done = value; 299 ev_loop_done = value;
317 300
318struct ev_io *io (SV *fh, int events, SV *cb) 301struct ev_io *io (SV *fh, int events, SV *cb)
302 PROTOTYPE: $$&
319 ALIAS: 303 ALIAS:
320 io_ns = 1 304 io_ns = 1
321 CODE: 305 CODE:
322 RETVAL = e_new (sizeof (struct ev_io), cb); 306 RETVAL = e_new (sizeof (struct ev_io), cb);
323 RETVAL->fh = newSVsv (fh); 307 RETVAL->fh = newSVsv (fh);
325 if (!ix) evio_start (RETVAL); 309 if (!ix) evio_start (RETVAL);
326 OUTPUT: 310 OUTPUT:
327 RETVAL 311 RETVAL
328 312
329struct ev_timer *timer (NV after, NV repeat, SV *cb) 313struct ev_timer *timer (NV after, NV repeat, SV *cb)
314 PROTOTYPE: $$&
330 ALIAS: 315 ALIAS:
331 timer_ns = 1 316 timer_ns = 1
332 INIT: 317 INIT:
333 CHECK_REPEAT (repeat); 318 CHECK_REPEAT (repeat);
334 CODE: 319 CODE:
337 if (!ix) evtimer_start (RETVAL); 322 if (!ix) evtimer_start (RETVAL);
338 OUTPUT: 323 OUTPUT:
339 RETVAL 324 RETVAL
340 325
341struct ev_periodic *periodic (NV at, NV interval, SV *cb) 326struct ev_periodic *periodic (NV at, NV interval, SV *cb)
327 PROTOTYPE: $$&
342 ALIAS: 328 ALIAS:
343 periodic_ns = 1 329 periodic_ns = 1
344 INIT: 330 INIT:
345 CHECK_REPEAT (interval); 331 CHECK_REPEAT (interval);
346 CODE: 332 CODE:
349 if (!ix) evperiodic_start (RETVAL); 335 if (!ix) evperiodic_start (RETVAL);
350 OUTPUT: 336 OUTPUT:
351 RETVAL 337 RETVAL
352 338
353struct ev_signal *signal (Signal signum, SV *cb) 339struct ev_signal *signal (Signal signum, SV *cb)
340 PROTOTYPE: $&
354 ALIAS: 341 ALIAS:
355 signal_ns = 1 342 signal_ns = 1
356 CODE: 343 CODE:
357 RETVAL = e_new (sizeof (struct ev_signal), cb); 344 RETVAL = e_new (sizeof (struct ev_signal), cb);
358 evsignal_set (RETVAL, signum); 345 evsignal_set (RETVAL, signum);
359 if (!ix) evsignal_start (RETVAL); 346 if (!ix) evsignal_start (RETVAL);
360 OUTPUT: 347 OUTPUT:
361 RETVAL 348 RETVAL
362 349
363struct ev_idle *idle (SV *cb) 350struct ev_idle *idle (SV *cb)
351 PROTOTYPE: &
364 ALIAS: 352 ALIAS:
365 idle_ns = 1 353 idle_ns = 1
366 CODE: 354 CODE:
367 RETVAL = e_new (sizeof (struct ev_idle), cb); 355 RETVAL = e_new (sizeof (struct ev_idle), cb);
368 evidle_set (RETVAL); 356 evidle_set (RETVAL);
369 if (!ix) evidle_start (RETVAL); 357 if (!ix) evidle_start (RETVAL);
370 OUTPUT: 358 OUTPUT:
371 RETVAL 359 RETVAL
372 360
373struct ev_check *check (SV *cb) 361struct ev_check *check (SV *cb)
362 PROTOTYPE: &
374 ALIAS: 363 ALIAS:
375 check_ns = 1 364 check_ns = 1
376 CODE: 365 CODE:
377 RETVAL = e_new (sizeof (struct ev_check), cb); 366 RETVAL = e_new (sizeof (struct ev_check), cb);
378 evcheck_set (RETVAL); 367 evcheck_set (RETVAL);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines