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

Comparing EV/EV.pm (file contents):
Revision 1.5 by root, Fri Oct 26 19:25:00 2007 UTC vs.
Revision 1.9 by root, Sun Oct 28 06:40:46 2007 UTC

41 EV::loop EV::LOOP_ONSHOT; 41 EV::loop EV::LOOP_ONSHOT;
42 42
43=head1 DESCRIPTION 43=head1 DESCRIPTION
44 44
45This module provides an interface to libevent 45This module provides an interface to libevent
46(L<http://monkey.org/~provos/libevent/>). 46(L<http://monkey.org/~provos/libevent/>). You probably should acquaint
47yourself with its documentation and source code to be able to use this
48module fully.
49
50Please note thta this module disables the libevent EPOLL method by
51default, see BUGS, below, if you need to enable it.
47 52
48=cut 53=cut
49 54
50package EV; 55package EV;
51 56
52use strict; 57use strict;
53 58
54BEGIN { 59BEGIN {
55 our $VERSION = '0.01'; 60 our $VERSION = '0.02';
56 use XSLoader; 61 use XSLoader;
57 XSLoader::load "EV", $VERSION; 62 XSLoader::load "EV", $VERSION;
58} 63}
59 64
60=head1 FUNCTIONAL INTERFACE 65=head1 BASIC INTERFACE
61 66
62=over 4 67=over 4
63 68
64=item $EV::NPRI 69=item $EV::NPRI
65 70
66How many priority levels are available. 71How many priority levels are available.
72
73=item $EV::DIED
74
75Must contain a reference to a function that is called when a callback
76throws an exception (with $@ containing thr error). The default prints an
77informative message and continues.
78
79If this callback throws an exception it will be silently ignored.
67 80
68=item $time = EV::now 81=item $time = EV::now
69 82
70Returns the time in (fractional) seconds since the epoch. 83Returns the time in (fractional) seconds since the epoch.
71 84
96 109
97As long as the returned watcher object is alive, call the C<$callback> 110As long as the returned watcher object is alive, call the C<$callback>
98when the events specified in C<$eventmask> happen. Initially, the timeout 111when the events specified in C<$eventmask> happen. Initially, the timeout
99is disabled. 112is disabled.
100 113
101The C<io_ns> variant doesn't add/start the newly created watcher. 114Youc an additionall set a timeout to occur on the watcher, but note that
115this timeout will not be reset when you get an I/O event in the EV::PERSIST
116case, and reaching a timeout will always stop the watcher even in the
117EV::PERSIST case.
118
119If you want a timeout to occur only after a specific time of inactivity, set
120a repeating timeout and do NOT use EV::PERSIST.
102 121
103Eventmask can be one or more of these constants ORed together: 122Eventmask can be one or more of these constants ORed together:
104 123
105 EV::READ wait until read() wouldn't block anymore 124 EV::READ wait until read() wouldn't block anymore
106 EV::WRITE wait until write() wouldn't block anymore 125 EV::WRITE wait until write() wouldn't block anymore
107 EV::PERSIST stay active after an event occured 126 EV::PERSIST stay active after a (non-timeout) event occured
127
128The C<io_ns> variant doesn't add/start the newly created watcher.
108 129
109=item my $w = EV::timer $after, $repeat, $callback 130=item my $w = EV::timer $after, $repeat, $callback
110 131
111=item my $w = EV::timer_ns $after, $repeat, $callback 132=item my $w = EV::timer_ns $after, $repeat, $callback
112 133
133 154
134This can be used to schedule a callback to run at very regular intervals, 155This can be used to schedule a callback to run at very regular intervals,
135as long as the processing time is less then the interval (otherwise 156as long as the processing time is less then the interval (otherwise
136obviously events will be skipped). 157obviously events will be skipped).
137 158
159Another way to think about it (for the mathematically inclined) is that
160C<timer_abs> will try to tun the callback at the next possible time where
161C<$time = $at (mod $interval)>, regardless of any time jumps.
162
138The C<timer_abs_ns> variant doesn't add/start the newly created watcher. 163The C<timer_abs_ns> variant doesn't add/start the newly created watcher.
139 164
140=item my $w = EV::signal $signum, $callback 165=item my $w = EV::signal $signum, $callback
141 166
142=item my $w = EV::signal_ns $signum, $callback 167=item my $w = EV::signal_ns $signum, $callback
204=head1 BUGS 229=head1 BUGS
205 230
206Lots. Libevent itself isn't well tested and rather buggy, and this module 231Lots. Libevent itself isn't well tested and rather buggy, and this module
207is quite new at the moment. 232is quite new at the moment.
208 233
234Please note that the epoll method is not, in general, reliable in programs
235that use fork (even if no libveent calls are being made in the forked
236process). If your program behaves erratically, try setting the environment
237variable C<EVENT_NOEPOLL> first when running the program.
238
239In general, if you fork, then you can only use the EV module in one of the
240children.
241
209=cut 242=cut
243
244our $DIED = sub {
245 warn "EV: error in callback (ignoring): $@";
246};
210 247
211our $NPRI = 4; 248our $NPRI = 4;
212our $BASE = init; 249our $BASE = init;
213priority_init $NPRI; 250priority_init $NPRI;
214 251

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines