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

Comparing EV/EV.pm (file contents):
Revision 1.13 by root, Tue Oct 30 12:48:29 2007 UTC vs.
Revision 1.19 by root, Thu Nov 1 11:43:10 2007 UTC

23 }; 23 };
24 24
25 # IO 25 # IO
26 26
27 my $w = EV::io \*STDIN, EV::READ | EV::PERSIST, sub { 27 my $w = EV::io \*STDIN, EV::READ | EV::PERSIST, sub {
28 my ($w, $events) = @_; # all callbacks get the watcher object and event mask 28 my ($w, $revents) = @_; # all callbacks get the watcher object and event mask
29 if ($events & EV::TIMEOUT) { 29 if ($revents & EV::TIMEOUT) {
30 warn "nothing received on stdin for 10 seconds, retrying"; 30 warn "nothing received on stdin for 10 seconds, retrying";
31 } else { 31 } else {
32 warn "stdin is readable, you entered: ", <STDIN>; 32 warn "stdin is readable, you entered: ", <STDIN>;
33 } 33 }
34 }; 34 };
35 $w->timeout (10); 35 $w->timeout (10);
36 36
37 my $w = EV::timed_io \*STDIN, EV::READ, 30, sub { 37 my $w = EV::timed_io \*STDIN, EV::READ, 30, sub {
38 my ($w, $events) = @_; 38 my ($w, $revents) = @_;
39 if ($_[1] & EV::TIMEOUT) { 39 if ($revents & EV::TIMEOUT) {
40 warn "nothing entered within 30 seconds, bye bye.\n"; 40 warn "nothing entered within 30 seconds, bye bye.\n";
41 $w->stop; 41 $w->stop;
42 } else { 42 } else {
43 my $line = <STDIN>; 43 my $line = <STDIN>;
44 warn "you entered something, you again have 30 seconds.\n"; 44 warn "you entered something, you again have 30 seconds.\n";
52 }; 52 };
53 53
54 my $w = EV::signal 3, sub { 54 my $w = EV::signal 3, sub {
55 warn "sigquit received (this is GNU/Linux, right?)\n"; 55 warn "sigquit received (this is GNU/Linux, right?)\n";
56 }; 56 };
57
58 # CHILD/PID STATUS CHANGES
59
60 my $w = EV::child 666, sub {
61 my ($w, $revents, $status) = @_;
62 };
57 63
58 # MAINLOOP 64 # MAINLOOP
59 EV::dispatch; # loop as long as watchers are active 65 EV::dispatch; # loop as long as watchers are active
60 EV::loop; # the same thing 66 EV::loop; # the same thing
61 EV::loop EV::LOOP_ONCE; # block until some events could be handles 67 EV::loop EV::LOOP_ONESHOT; # block until some events could be handles
62 EV::loop EV::LOOP_NONBLOCK; # check and handle some events, but do not wait 68 EV::loop EV::LOOP_NONBLOCK; # check and handle some events, but do not wait
63 69
64=head1 DESCRIPTION 70=head1 DESCRIPTION
65 71
66This module provides an interface to libevent 72This module provides an interface to libev
67(L<http://monkey.org/~provos/libevent/>). You probably should acquaint 73(L<http://software.schmorp.de/pkg/libev.html>). You probably should
68yourself with its documentation and source code to be able to use this 74acquaint yourself with its documentation and source code to be able to use
69module fully. 75this module fully.
70
71Please note thta this module disables the libevent EPOLL method by
72default, see BUGS, below, if you need to enable it.
73 76
74=cut 77=cut
75 78
76package EV; 79package EV;
77 80
78use strict; 81use strict;
79 82
80BEGIN { 83BEGIN {
81 our $VERSION = '0.03'; 84 our $VERSION = '0.1';
82 use XSLoader; 85 use XSLoader;
83 XSLoader::load "EV", $VERSION; 86 XSLoader::load "EV", $VERSION;
84} 87}
88
89@EV::Io::ISA =
90@EV::Timer::ISA =
91@EV::Periodic::ISA =
92@EV::Signal::ISA =
93@EV::Idle::ISA =
94@EV::Prepare::ISA =
95@EV::Check::ISA =
96@EV::Child::ISA = "EV::Watcher";
85 97
86=head1 BASIC INTERFACE 98=head1 BASIC INTERFACE
87 99
88=over 4 100=over 4
89 101
286=head1 THREADS 298=head1 THREADS
287 299
288Threads are not supported by this in any way. Perl pseudo-threads is evil 300Threads are not supported by this in any way. Perl pseudo-threads is evil
289and must die. 301and must die.
290 302
291=head1 BUGS
292
293Lots. Libevent itself isn't well tested and rather buggy, and this module
294is quite new at the moment.
295
296Please note that the epoll method is not, in general, reliable in programs
297that use fork (even if no libveent calls are being made in the forked
298process). If your program behaves erratically, try setting the environment
299variable C<EVENT_NOEPOLL> first when running the program.
300
301In general, if you fork, then you can only use the EV module in one of the
302children.
303
304=cut 303=cut
305 304
306our $DIED = sub { 305our $DIED = sub {
307 warn "EV: error in callback (ignoring): $@"; 306 warn "EV: error in callback (ignoring): $@";
308}; 307};
309 308
310our $NPRI = 4; 309init;
311our $BASE = init;
312priority_init $NPRI;
313 310
314push @AnyEvent::REGISTRY, [EV => "EV::AnyEvent"]; 311push @AnyEvent::REGISTRY, [EV => "EV::AnyEvent"];
315 312
3161; 3131;
317 314

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines