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.33 by root, Thu Nov 1 11:55:54 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);
288 evapi.child_stop = ev_child_stop; 291 evapi.child_stop = ev_child_stop;
289 292
290 sv_setiv (sv, (IV)&evapi); 293 sv_setiv (sv, (IV)&evapi);
291 SvREADONLY_on (sv); 294 SvREADONLY_on (sv);
292 } 295 }
296
297 pthread_atfork (ev_fork_prepare, ev_fork_parent, ev_fork_child);
293} 298}
294 299
295NV ev_now () 300NV ev_now ()
296 CODE: 301 CODE:
297 RETVAL = ev_now; 302 RETVAL = ev_now;
316 321
317struct ev_io *io (SV *fh, int events, SV *cb) 322struct ev_io *io (SV *fh, int events, SV *cb)
318 ALIAS: 323 ALIAS:
319 io_ns = 1 324 io_ns = 1
320 CODE: 325 CODE:
326{
327 int fd = sv_fileno (fh);
328 CHECK_FD (fh, fd);
329
321 RETVAL = e_new (sizeof (struct ev_io), cb); 330 RETVAL = e_new (sizeof (struct ev_io), cb);
322 RETVAL->fh = newSVsv (fh); 331 RETVAL->fh = newSVsv (fh);
323 ev_io_set (RETVAL, sv_fileno (RETVAL->fh), events); 332 ev_io_set (RETVAL, fd, events);
324 if (!ix) ev_io_start (RETVAL); 333 if (!ix) ev_io_start (RETVAL);
334}
325 OUTPUT: 335 OUTPUT:
326 RETVAL 336 RETVAL
327 337
328struct ev_timer *timer (NV after, NV repeat, SV *cb) 338struct ev_timer *timer (NV after, NV repeat, SV *cb)
329 ALIAS: 339 ALIAS:
433 443
434void set (struct ev_io *w, SV *fh, int events) 444void set (struct ev_io *w, SV *fh, int events)
435 CODE: 445 CODE:
436{ 446{
437 int active = w->active; 447 int active = w->active;
448 int fd = sv_fileno (fh);
449 CHECK_FD (fh, fd);
450
438 if (active) ev_io_stop (w); 451 if (active) ev_io_stop (w);
439 452
440 sv_setsv (w->fh, fh); 453 sv_setsv (w->fh, fh);
441 ev_io_set (w, sv_fileno (w->fh), events); 454 ev_io_set (w, fd, events);
442 455
443 if (active) ev_io_start (w); 456 if (active) ev_io_start (w);
444} 457}
445 458
446SV *fh (struct ev_io *w, SV *new_fh = 0) 459SV *fh (struct ev_io *w, SV *new_fh = 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines