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

Comparing EV/EV.pm (file contents):
Revision 1.15 by root, Wed Oct 31 18:28:00 2007 UTC vs.
Revision 1.18 by root, Thu Nov 1 08:10:03 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
81 our $VERSION = '0.03'; 84 our $VERSION = '0.03';
82 use XSLoader; 85 use XSLoader;
83 XSLoader::load "EV", $VERSION; 86 XSLoader::load "EV", $VERSION;
84} 87}
85 88
86@EV::Io::ISA = "EV::Watcher"; 89@EV::Io::ISA =
87@EV::Time::ISA = "EV::Watcher";
88@EV::Timer::ISA = "EV::Time"; 90@EV::Timer::ISA =
89@EV::Periodic::ISA = "EV::Time"; 91@EV::Periodic::ISA =
90@EV::Signal::ISA = "EV::Watcher"; 92@EV::Signal::ISA =
91@EV::Idle::ISA = "EV::Watcher"; 93@EV::Idle::ISA =
92@EV::Prepare::ISA = "EV::Watcher"; 94@EV::Prepare::ISA =
95@EV::Check::ISA =
93@EV::Check::ISA = "EV::Watcher"; 96@EV::Child::ISA = "EV::Watcher";
94 97
95=head1 BASIC INTERFACE 98=head1 BASIC INTERFACE
96 99
97=over 4 100=over 4
98 101
295=head1 THREADS 298=head1 THREADS
296 299
297Threads 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
298and must die. 301and must die.
299 302
300=head1 BUGS
301
302Lots. Libevent itself isn't well tested and rather buggy, and this module
303is quite new at the moment.
304
305Please note that the epoll method is not, in general, reliable in programs
306that use fork (even if no libveent calls are being made in the forked
307process). If your program behaves erratically, try setting the environment
308variable C<EVENT_NOEPOLL> first when running the program.
309
310In general, if you fork, then you can only use the EV module in one of the
311children.
312
313=cut 303=cut
314 304
315our $DIED = sub { 305our $DIED = sub {
316 warn "EV: error in callback (ignoring): $@"; 306 warn "EV: error in callback (ignoring): $@";
317}; 307};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines