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

Comparing EV/EV.xs (file contents):
Revision 1.29 by root, Thu Nov 1 06:48:49 2007 UTC vs.
Revision 1.32 by root, Thu Nov 1 11:11:39 2007 UTC

3#include "XSUB.h" 3#include "XSUB.h"
4 4
5/*#include <netinet/in.h>*/ 5/*#include <netinet/in.h>*/
6 6
7#define TIMEOUT_NONE HUGE_VAL 7#define TIMEOUT_NONE HUGE_VAL
8#define HAVE_EPOLL 1 8#define EV_USE_EPOLL 1
9 9
10#define EV_PROTOTYPES 1 10#define EV_PROTOTYPES 1
11#include "EV/EVAPI.h" 11#include "EV/EVAPI.h"
12 12
13#include "libev/ev.c" 13#include "libev/ev.c"
17static struct EVAPI evapi; 17static struct EVAPI evapi;
18 18
19static HV 19static HV
20 *stash_watcher, 20 *stash_watcher,
21 *stash_io, 21 *stash_io,
22 *stash_time,
23 *stash_timer, 22 *stash_timer,
24 *stash_periodic, 23 *stash_periodic,
25 *stash_signal, 24 *stash_signal,
26 *stash_idle, 25 *stash_idle,
27 *stash_prepare, 26 *stash_prepare,
31static int 30static int
32sv_signum (SV *sig) 31sv_signum (SV *sig)
33{ 32{
34 int signum; 33 int signum;
35 34
36 if (SvIV (sig) > 0) 35 SvGETMAGIC (sig);
37 return SvIV (sig);
38 36
39 for (signum = 1; signum < SIG_SIZE; ++signum) 37 for (signum = 1; signum < SIG_SIZE; ++signum)
40 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) 38 if (strEQ (SvPV_nolen (sig), PL_sig_name [signum]))
41 return signum; 39 return signum;
42 40
41 if (SvIV (sig) > 0)
42 return SvIV (sig);
43
43 return -1; 44 return -1;
44} 45}
45 46
46///////////////////////////////////////////////////////////////////////////// 47/////////////////////////////////////////////////////////////////////////////
47// Event 48// Event
57 fh = SvRV (fh); 58 fh = SvRV (fh);
58 59
59 if (SvTYPE (fh) == SVt_PVGV) 60 if (SvTYPE (fh) == SVt_PVGV)
60 return PerlIO_fileno (IoIFP (sv_2io (fh))); 61 return PerlIO_fileno (IoIFP (sv_2io (fh)));
61 62
62 if (SvIOK (fh)) 63 if ((SvIV (fh) >= 0) && (SvIV (fh) < 0x7ffffff))
63 return SvIV (fh); 64 return SvIV (fh);
64 65
65 return -1; 66 return -1;
66} 67}
67 68
203#endif 204#endif
204 205
205#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 206#define CHECK_REPEAT(repeat) if (repeat < 0.) \
206 croak (# repeat " value must be >= 0"); 207 croak (# repeat " value must be >= 0");
207 208
209#define CHECK_FD(fh,fd) if ((fd) < 0) \
210 croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh));
211
208///////////////////////////////////////////////////////////////////////////// 212/////////////////////////////////////////////////////////////////////////////
209// XS interface functions 213// XS interface functions
210 214
211MODULE = EV PACKAGE = EV PREFIX = ev_ 215MODULE = EV PACKAGE = EV PREFIX = ev_
212 216
243 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 247 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
244 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 248 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
245 249
246 stash_watcher = gv_stashpv ("EV::Watcher" , 1); 250 stash_watcher = gv_stashpv ("EV::Watcher" , 1);
247 stash_io = gv_stashpv ("EV::Io" , 1); 251 stash_io = gv_stashpv ("EV::Io" , 1);
248 stash_time = gv_stashpv ("EV::Time" , 1);
249 stash_timer = gv_stashpv ("EV::Timer" , 1); 252 stash_timer = gv_stashpv ("EV::Timer" , 1);
250 stash_periodic = gv_stashpv ("EV::Periodic", 1); 253 stash_periodic = gv_stashpv ("EV::Periodic", 1);
251 stash_signal = gv_stashpv ("EV::Signal" , 1); 254 stash_signal = gv_stashpv ("EV::Signal" , 1);
252 stash_idle = gv_stashpv ("EV::Idle" , 1); 255 stash_idle = gv_stashpv ("EV::Idle" , 1);
253 stash_prepare = gv_stashpv ("EV::Prepare" , 1); 256 stash_prepare = gv_stashpv ("EV::Prepare" , 1);
316 319
317struct ev_io *io (SV *fh, int events, SV *cb) 320struct ev_io *io (SV *fh, int events, SV *cb)
318 ALIAS: 321 ALIAS:
319 io_ns = 1 322 io_ns = 1
320 CODE: 323 CODE:
324{
325 int fd = sv_fileno (fh);
326 CHECK_FD (fh, fd);
327
321 RETVAL = e_new (sizeof (struct ev_io), cb); 328 RETVAL = e_new (sizeof (struct ev_io), cb);
322 RETVAL->fh = newSVsv (fh); 329 RETVAL->fh = newSVsv (fh);
323 ev_io_set (RETVAL, sv_fileno (RETVAL->fh), events); 330 ev_io_set (RETVAL, fd, events);
324 if (!ix) ev_io_start (RETVAL); 331 if (!ix) ev_io_start (RETVAL);
332}
325 OUTPUT: 333 OUTPUT:
326 RETVAL 334 RETVAL
327 335
328struct ev_timer *timer (NV after, NV repeat, SV *cb) 336struct ev_timer *timer (NV after, NV repeat, SV *cb)
329 ALIAS: 337 ALIAS:
433 441
434void set (struct ev_io *w, SV *fh, int events) 442void set (struct ev_io *w, SV *fh, int events)
435 CODE: 443 CODE:
436{ 444{
437 int active = w->active; 445 int active = w->active;
446 int fd = sv_fileno (fh);
447 CHECK_FD (fh, fd);
448
438 if (active) ev_io_stop (w); 449 if (active) ev_io_stop (w);
439 450
440 sv_setsv (w->fh, fh); 451 sv_setsv (w->fh, fh);
441 ev_io_set (w, sv_fileno (w->fh), events); 452 ev_io_set (w, fd, events);
442 453
443 if (active) ev_io_start (w); 454 if (active) ev_io_start (w);
444} 455}
445 456
446SV *fh (struct ev_io *w, SV *new_fh = 0) 457SV *fh (struct ev_io *w, SV *new_fh = 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines