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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines