ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/README
Revision: 1.3
Committed: Sun Oct 28 06:40:46 2007 UTC (16 years, 6 months ago) by root
Branch: MAIN
CVS Tags: rel-0_02
Changes since 1.2: +8 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 NAME
2 EV - perl interface to libevent, monkey.org/~provos/libevent/
3
4 SYNOPSIS
5 use EV;
6
7 # TIMER
8
9 my $w = EV::timer 2, 0, sub {
10 warn "is called after 2s";
11 };
12
13 my $w = EV::timer 2, 1, sub {
14 warn "is called roughly every 2s (repeat = 1)";
15 };
16
17 undef $w; # destroy event watcher again
18
19 # IO
20
21 my $w = EV::timer_abs 0, 60, sub {
22 warn "is called every minute, on the minute, exactly";
23 };
24
25 my $w = EV::io \*STDIN, EV::READ | EV::PERSIST, sub {
26 my ($w, $events) = @_; # all callbacks get the watcher object and event mask
27 if ($events & EV::TIMEOUT) {
28 warn "nothign received on stdin for 10 seconds, retrying";
29 } else {
30 warn "stdin is readable, you entered: ", <STDIN>;
31 }
32 };
33 $w->timeout (10);
34
35 # MAINLOOP
36 EV::dispatch; # loop as long as watchers are active
37 EV::loop; # the same thing
38 EV::loop EV::LOOP_ONCE;
39 EV::loop EV::LOOP_ONSHOT;
40
41 DESCRIPTION
42 This module provides an interface to libevent
43 (<http://monkey.org/~provos/libevent/>). You probably should acquaint
44 yourself with its documentation and source code to be able to use this
45 module fully.
46
47 Please note thta this module disables the libevent EPOLL method by
48 default, see BUGS, below, if you need to enable it.
49
50 BASIC INTERFACE
51 $EV::NPRI
52 How many priority levels are available.
53
54 $EV::DIED
55 Must contain a reference to a function that is called when a
56 callback throws an exception (with $@ containing thr error). The
57 default prints an informative message and continues.
58
59 If this callback throws an exception it will be silently ignored.
60
61 $time = EV::now
62 Returns the time in (fractional) seconds since the epoch.
63
64 $version = EV::version
65 $method = EV::method
66 Return version string and event polling method used.
67
68 EV::loop $flags # EV::LOOP_ONCE, EV::LOOP_ONESHOT
69 EV::loopexit $after
70 Exit any active loop or dispatch after $after seconds or immediately
71 if $after is missing or zero.
72
73 EV::dispatch
74 Same as "EV::loop 0".
75
76 EV::event $callback
77 Creates a new event watcher waiting for nothing, calling the given
78 callback.
79
80 my $w = EV::io $fileno_or_fh, $eventmask, $callback
81 my $w = EV::io_ns $fileno_or_fh, $eventmask, $callback
82 As long as the returned watcher object is alive, call the $callback
83 when the events specified in $eventmask happen. Initially, the
84 timeout is disabled.
85
86 Youc an additionall set a timeout to occur on the watcher, but note
87 that this timeout will not be reset when you get an I/O event in the
88 EV::PERSIST case, and reaching a timeout will always stop the
89 watcher even in the EV::PERSIST case.
90
91 If you want a timeout to occur only after a specific time of
92 inactivity, set a repeating timeout and do NOT use EV::PERSIST.
93
94 Eventmask can be one or more of these constants ORed together:
95
96 EV::READ wait until read() wouldn't block anymore
97 EV::WRITE wait until write() wouldn't block anymore
98 EV::PERSIST stay active after a (non-timeout) event occured
99
100 The "io_ns" variant doesn't add/start the newly created watcher.
101
102 my $w = EV::timer $after, $repeat, $callback
103 my $w = EV::timer_ns $after, $repeat, $callback
104 Calls the callback after $after seconds. If $repeat is true, the
105 timer will be restarted after the callback returns. This means that
106 the callback would be called roughly every $after seconds, prolonged
107 by the time the callback takes.
108
109 The "timer_ns" variant doesn't add/start the newly created watcher.
110
111 my $w = EV::timer_abs $at, $interval, $callback
112 my $w = EV::timer_abs_ns $at, $interval, $callback
113 Similar to EV::timer, but the time is given as an absolute point in
114 time ($at), plus an optional $interval.
115
116 If the $interval is zero, then the callback will be called at the
117 time $at if that is in the future, or as soon as possible if its in
118 the past. It will not automatically repeat.
119
120 If the $interval is nonzero, then the watcher will always be
121 scheduled to time out at the next "$at + integer * $interval" time.
122
123 This can be used to schedule a callback to run at very regular
124 intervals, as long as the processing time is less then the interval
125 (otherwise obviously events will be skipped).
126
127 Another way to think about it (for the mathematically inclined) is
128 that "timer_abs" will try to tun the callback at the next possible
129 time where "$time = $at (mod $interval)", regardless of any time
130 jumps.
131
132 The "timer_abs_ns" variant doesn't add/start the newly created
133 watcher.
134
135 my $w = EV::signal $signum, $callback
136 my $w = EV::signal_ns $signum, $callback
137 Call the callback when signal $signum is received.
138
139 The "signal_ns" variant doesn't add/start the newly created watcher.
140
141 THE EV::Event CLASS
142 All EV functions creating an event watcher (designated by "my $w ="
143 above) support the following methods on the returned watcher object:
144
145 $w->add ($timeout)
146 Stops and (re-)starts the event watcher, setting the optional
147 timeout to the given value, or clearing the timeout if none is
148 given.
149
150 $w->start
151 Stops and (re-)starts the event watcher without touching the
152 timeout.
153
154 $w->del
155 $w->stop
156 Stop the event watcher if it was started.
157
158 $current_callback = $w->cb
159 $old_callback = $w->cb ($new_callback)
160 Return the previously set callback and optionally set a new one.
161
162 $current_fh = $w->fh
163 $old_fh = $w->fh ($new_fh)
164 Returns the previously set filehandle and optionally set a new one.
165
166 $current_eventmask = $w->events
167 $old_eventmask = $w->events ($new_eventmask)
168 Returns the previously set event mask and optionally set a new one.
169
170 $w->timeout ($after, $repeat)
171 Resets the timeout (see "EV::timer" for details).
172
173 $w->timeout_abs ($at, $interval)
174 Resets the timeout (see "EV::timer_abs" for details).
175
176 $w->priority_set ($priority)
177 Set the priority of the watcher to $priority (0 <= $priority <
178 $EV::NPRI).
179
180 BUGS
181 Lots. Libevent itself isn't well tested and rather buggy, and this
182 module is quite new at the moment.
183
184 Please note that the epoll method is not, in general, reliable in
185 programs that use fork (even if no libveent calls are being made in the
186 forked process). If your program behaves erratically, try setting the
187 environment variable "EVENT_NOEPOLL" first when running the program.
188
189 In general, if you fork, then you can only use the EV module in one of
190 the children.
191
192 SEE ALSO
193 L<EV::DNS>, L<event(3)>, L<event.h>, L<evdns.h>.
194 L<EV::AnyEvent>.
195
196 AUTHOR
197 Marc Lehmann <schmorp@schmorp.de>
198 http://home.schmorp.de/
199