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

Comparing EV/README (file contents):
Revision 1.28 by root, Tue Jul 8 18:56:48 2008 UTC vs.
Revision 1.31 by root, Wed Nov 19 10:33:32 2008 UTC

54 54
55DESCRIPTION 55DESCRIPTION
56 This module provides an interface to libev 56 This module provides an interface to libev
57 (<http://software.schmorp.de/pkg/libev.html>). While the documentation 57 (<http://software.schmorp.de/pkg/libev.html>). While the documentation
58 below is comprehensive, one might also consult the documentation of 58 below is comprehensive, one might also consult the documentation of
59 libev itself (<http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod>) 59 libev itself (<http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod> or
60 for more subtle details on watcher semantics or some discussion on the 60 perldoc EV::libev) for more subtle details on watcher semantics or some
61 available backends, or how to force a specific backend with 61 discussion on the available backends, or how to force a specific backend
62 "LIBEV_FLAGS", or just about in any case because it has much more 62 with "LIBEV_FLAGS", or just about in any case because it has much more
63 detailed information. 63 detailed information.
64 64
65 This module is very fast and scalable. It is actually so fast that you 65 This module is very fast and scalable. It is actually so fast that you
66 can use it through the AnyEvent module, stay portable to other event 66 can use it through the AnyEvent module, stay portable to other event
67 loops (if you don't rely on any watcher types not available through it) 67 loops (if you don't rely on any watcher types not available through it)
68 and still be faster than with any other event loop currently supported 68 and still be faster than with any other event loop currently supported
69 in Perl. 69 in Perl.
70
71 MODULE EXPORTS
72 This module does not export any symbols.
70 73
71EVENT LOOPS 74EVENT LOOPS
72 EV supports multiple event loops: There is a single "default event loop" 75 EV supports multiple event loops: There is a single "default event loop"
73 that can handle everything including signals and child watchers, and any 76 that can handle everything including signals and child watchers, and any
74 number of "dynamic event loops" that can use different backends (with 77 number of "dynamic event loops" that can use different backends (with
81 default loop as this is fastest (perl-wise), best supported by other 84 default loop as this is fastest (perl-wise), best supported by other
82 modules (e.g. AnyEvent or Coro) and most portable event loop. 85 modules (e.g. AnyEvent or Coro) and most portable event loop.
83 86
84 For specific programs you can create additional event loops dynamically. 87 For specific programs you can create additional event loops dynamically.
85 88
86 If you want to take avdantage of kqueue (which often works properly for 89 If you want to take advantage of kqueue (which often works properly for
87 sockets only) even though the default loop doesn't enable it, you can 90 sockets only) even though the default loop doesn't enable it, you can
88 *embed* a kqueue loop into the default loop: running the default loop 91 *embed* a kqueue loop into the default loop: running the default loop
89 will then also service the kqueue loop to some extent. See the example 92 will then also service the kqueue loop to some extent. See the example
90 in the section about embed watchers for an example on how to achieve 93 in the section about embed watchers for an example on how to achieve
91 that. 94 that.
92 95
93 $loop = new EV::loop [$flags] 96 $loop = new EV::loop [$flags]
94 Create a new event loop as per the specified flags. Please refer to 97 Create a new event loop as per the specified flags. Please refer to
95 the "ev_loop_new ()" function description in the libev documentation 98 the "ev_loop_new ()" function description in the libev documentation
96 (<http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#GLOBAL_FUNCTI 99 (<http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#GLOBAL_FUNCTI
97 ONS>) for more info. 100 ONS>, or locally-installed as EV::libev manpage) for more info.
98 101
99 The loop will automatically be destroyed when it is no longer 102 The loop will automatically be destroyed when it is no longer
100 referenced by any watcher and the loop object goes out of scope. 103 referenced by any watcher and the loop object goes out of scope.
101 104
102 Using "EV::FLAG_FORKCHECK" is recommended, as only the default event 105 If you are not embedding the loop, then Using "EV::FLAG_FORKCHECK"
103 loop is protected by this module. 106 is recommended, as only the default event loop is protected by this
107 module. If you *are* embedding this loop in the default loop, this
108 is not necessary, as "EV::embed" automatically does the right thing
109 on fork.
104 110
105 $loop->loop_fork 111 $loop->loop_fork
106 Must be called after a fork in the child, before entering or 112 Must be called after a fork in the child, before entering or
107 continuing the event loop. An alternative is to use 113 continuing the event loop. An alternative is to use
108 "EV::FLAG_FORKCHECK" which calls this function automatically, at 114 "EV::FLAG_FORKCHECK" which calls this function automatically, at
143 Returns the current time in (fractional) seconds since the epoch. 149 Returns the current time in (fractional) seconds since the epoch.
144 150
145 $time = EV::now 151 $time = EV::now
146 $time = $loop->now 152 $time = $loop->now
147 Returns the time the last event loop iteration has been started. 153 Returns the time the last event loop iteration has been started.
148 This is the time that (relative) timers are based on, and refering 154 This is the time that (relative) timers are based on, and referring
149 to it is usually faster then calling EV::time. 155 to it is usually faster then calling EV::time.
150 156
151 $backend = EV::backend 157 $backend = EV::backend
152 $backend = $loop->backend 158 $backend = $loop->backend
153 Returns an integer describing the backend used by libev 159 Returns an integer describing the backend used by libev
154 (EV::METHOD_SELECT or EV::METHOD_EPOLL). 160 (EV::BACKEND_SELECT or EV::BACKEND_EPOLL).
155 161
156 EV::loop [$flags] 162 EV::loop [$flags]
157 $loop->loop ([$flags]) 163 $loop->loop ([$flags])
158 Begin checking for events and calling callbacks. It returns when a 164 Begin checking for events and calling callbacks. It returns when a
159 callback calls EV::unloop. 165 callback calls EV::unloop.
173 EV::loop will return as fast as possible. 179 EV::loop will return as fast as possible.
174 180
175 $count = EV::loop_count 181 $count = EV::loop_count
176 $count = $loop->loop_count 182 $count = $loop->loop_count
177 Return the number of times the event loop has polled for new events. 183 Return the number of times the event loop has polled for new events.
178 Sometiems useful as a generation counter. 184 Sometimes useful as a generation counter.
179 185
180 EV::once $fh_or_undef, $events, $timeout, $cb->($revents) 186 EV::once $fh_or_undef, $events, $timeout, $cb->($revents)
181 $loop->once ($fh_or_undef, $events, $timeout, $cb->($revents)) 187 $loop->once ($fh_or_undef, $events, $timeout, $cb->($revents))
182 This function rolls together an I/O and a timer watcher for a single 188 This function rolls together an I/O and a timer watcher for a single
183 one-shot event without the need for managing a watcher object. 189 one-shot event without the need for managing a watcher object.
217 $loop->set_timeout_collect_interval ($time) 223 $loop->set_timeout_collect_interval ($time)
218 These advanced functions set the minimum block interval when polling 224 These advanced functions set the minimum block interval when polling
219 for I/O events and the minimum wait interval for timer events. See 225 for I/O events and the minimum wait interval for timer events. See
220 the libev documentation at 226 the libev documentation at
221 <http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#FUNCTIONS_CONT 227 <http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#FUNCTIONS_CONT
222 ROLLING_THE_EVENT_LOOP> for a more detailed discussion. 228 ROLLING_THE_EVENT_LOOP> (locally installed as EV::libev) for a more
229 detailed discussion.
223 230
224WATCHER OBJECTS 231WATCHER OBJECTS
225 A watcher is an object that gets created to record your interest in some 232 A watcher is an object that gets created to record your interest in some
226 event. For instance, if you want to wait for STDIN to become readable, 233 event. For instance, if you want to wait for STDIN to become readable,
227 you would create an EV::io watcher for that: 234 you would create an EV::io watcher for that:
236 will be called with at least two arguments: the watcher and a bitmask of 243 will be called with at least two arguments: the watcher and a bitmask of
237 received events. 244 received events.
238 245
239 Each watcher type has its associated bit in revents, so you can use the 246 Each watcher type has its associated bit in revents, so you can use the
240 same callback for multiple watchers. The event mask is named after the 247 same callback for multiple watchers. The event mask is named after the
241 type, i..e. EV::child sets EV::CHILD, EV::prepare sets EV::PREPARE, 248 type, i.e. EV::child sets EV::CHILD, EV::prepare sets EV::PREPARE,
242 EV::periodic sets EV::PERIODIC and so on, with the exception of I/O 249 EV::periodic sets EV::PERIODIC and so on, with the exception of I/O
243 events (which can set both EV::READ and EV::WRITE bits), and EV::timer 250 events (which can set both EV::READ and EV::WRITE bits), and EV::timer
244 (which uses EV::TIMEOUT). 251 (which uses EV::TIMEOUT).
245 252
246 In the rare case where one wants to create a watcher but not start it at 253 In the rare case where one wants to create a watcher but not start it at
331 338
332 In this case you can clear the keepalive status, which means that 339 In this case you can clear the keepalive status, which means that
333 even though your watcher is active, it won't keep "EV::loop" from 340 even though your watcher is active, it won't keep "EV::loop" from
334 returning. 341 returning.
335 342
336 The initial value for keepalive is true (enabled), and you cna 343 The initial value for keepalive is true (enabled), and you can
337 change it any time. 344 change it any time.
338 345
339 Example: Register an I/O watcher for some UDP socket but do not keep 346 Example: Register an I/O watcher for some UDP socket but do not keep
340 the event loop from running just because of that watcher. 347 the event loop from running just because of that watcher.
341 348
741 # make the dispatcher handle any new stuff 748 # make the dispatcher handle any new stuff
742 ... not shown 749 ... not shown
743 }; 750 };
744 751
745 The callbacks of the created watchers will not be called as the 752 The callbacks of the created watchers will not be called as the
746 watchers are destroyed before this cna happen (remember EV::check 753 watchers are destroyed before this can happen (remember EV::check
747 gets called first). 754 gets called first).
748 755
749 The "check_ns" variant doesn't start (activate) the newly created 756 The "check_ns" variant doesn't start (activate) the newly created
750 watcher. 757 watcher.
751 758
770 embedded loop, other types of watchers might be handled in a delayed or 777 embedded loop, other types of watchers might be handled in a delayed or
771 incorrect fashion and must not be used). 778 incorrect fashion and must not be used).
772 779
773 See the libev documentation at 780 See the libev documentation at
774 <http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#code_ev_embed_code 781 <http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#code_ev_embed_code
775 _when_one_backend_> for more details. 782 _when_one_backend_> (locally installed as EV::libev) for more details.
776 783
777 In short, this watcher is most useful on BSD systems without working 784 In short, this watcher is most useful on BSD systems without working
778 kqueue to still be able to handle a large number of sockets: 785 kqueue to still be able to handle a large number of sockets:
779 786
780 my $socket_loop; 787 my $socket_loop;
789 } 796 }
790 797
791 # use the default loop otherwise 798 # use the default loop otherwise
792 $socket_loop ||= EV::default_loop; 799 $socket_loop ||= EV::default_loop;
793 800
794 $w = EV::embed $otherloop, $callback 801 $w = EV::embed $otherloop[, $callback]
795 $w = EV::embed_ns $otherloop, $callback 802 $w = EV::embed_ns $otherloop[, $callback]
796 $w = $loop->embed ($otherloop, $callback) 803 $w = $loop->embed ($otherloop[, $callback])
797 $w = $loop->embed_ns ($otherloop, $callback) 804 $w = $loop->embed_ns ($otherloop[, $callback])
798 Call the callback when the embedded event loop ($otherloop) has any 805 Call the callback when the embedded event loop ($otherloop) has any
799 I/O activity. The $callback should alwas be specified as "undef" in 806 I/O activity. The $callback is optional: if it is missing, then the
800 this version of EV, which means the embedded event loop will be 807 embedded event loop will be managed automatically (which is
801 managed automatically. 808 recommended), otherwise you have to invoke "sweep" yourself.
802 809
803 The "embed_ns" variant doesn't start (activate) the newly created 810 The "embed_ns" variant doesn't start (activate) the newly created
804 watcher. 811 watcher.
805 812
806 ASYNC WATCHERS - how to wake up another event loop 813 ASYNC WATCHERS - how to wake up another event loop

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines