… | |
… | |
132 | These watchers are normal Perl objects with normal Perl lifetime. After |
132 | These watchers are normal Perl objects with normal Perl lifetime. After |
133 | creating a watcher it will immediately "watch" for events and invoke the |
133 | creating a watcher it will immediately "watch" for events and invoke the |
134 | callback when the event occurs (of course, only when the event model is |
134 | callback when the event occurs (of course, only when the event model is |
135 | in control). |
135 | in control). |
136 | |
136 | |
|
|
137 | Note that callbacks must not permanently change global variables |
|
|
138 | potentially in use by the event loop (such as $_ or $[) and that |
|
|
139 | callbacks must not "die". The former is good programming practise in |
|
|
140 | Perl and the latter stems from the fact that exception handling differs |
|
|
141 | widely between event loops. |
|
|
142 | |
137 | To disable the watcher you have to destroy it (e.g. by setting the |
143 | To disable the watcher you have to destroy it (e.g. by setting the |
138 | variable you store it in to "undef" or otherwise deleting all references |
144 | variable you store it in to "undef" or otherwise deleting all references |
139 | to it). |
145 | to it). |
140 | |
146 | |
141 | All watchers are created by calling a method on the "AnyEvent" class. |
147 | All watchers are created by calling a method on the "AnyEvent" class. |
… | |
… | |
156 | |
162 | |
157 | I/O WATCHERS |
163 | I/O WATCHERS |
158 | You can create an I/O watcher by calling the "AnyEvent->io" method with |
164 | You can create an I/O watcher by calling the "AnyEvent->io" method with |
159 | the following mandatory key-value pairs as arguments: |
165 | the following mandatory key-value pairs as arguments: |
160 | |
166 | |
161 | "fh" the Perl *file handle* (*not* file descriptor) to watch for events |
167 | "fh" is the Perl *file handle* (*not* file descriptor) to watch for |
162 | (AnyEvent might or might not keep a reference to this file handle). |
168 | events (AnyEvent might or might not keep a reference to this file |
|
|
169 | handle). Note that only file handles pointing to things for which |
|
|
170 | non-blocking operation makes sense are allowed. This includes sockets, |
|
|
171 | most character devices, pipes, fifos and so on, but not for example |
|
|
172 | files or block devices. |
|
|
173 | |
163 | "poll" must be a string that is either "r" or "w", which creates a |
174 | "poll" must be a string that is either "r" or "w", which creates a |
164 | watcher waiting for "r"eadable or "w"ritable events, respectively. "cb" |
175 | watcher waiting for "r"eadable or "w"ritable events, respectively. |
|
|
176 | |
165 | is the callback to invoke each time the file handle becomes ready. |
177 | "cb" is the callback to invoke each time the file handle becomes ready. |
166 | |
178 | |
167 | Although the callback might get passed parameters, their value and |
179 | Although the callback might get passed parameters, their value and |
168 | presence is undefined and you cannot rely on them. Portable AnyEvent |
180 | presence is undefined and you cannot rely on them. Portable AnyEvent |
169 | callbacks cannot use arguments passed to I/O watcher callbacks. |
181 | callbacks cannot use arguments passed to I/O watcher callbacks. |
170 | |
182 | |
… | |
… | |
870 | mentioned will be used, and preference will be given to protocols |
882 | mentioned will be used, and preference will be given to protocols |
871 | mentioned earlier in the list. |
883 | mentioned earlier in the list. |
872 | |
884 | |
873 | This variable can effectively be used for denial-of-service attacks |
885 | This variable can effectively be used for denial-of-service attacks |
874 | against local programs (e.g. when setuid), although the impact is |
886 | against local programs (e.g. when setuid), although the impact is |
875 | likely small, as the program has to handle connection errors |
887 | likely small, as the program has to handle conenction and other |
876 | already- |
888 | failures anyways. |
877 | |
889 | |
878 | Examples: "PERL_ANYEVENT_PROTOCOLS=ipv4,ipv6" - prefer IPv4 over |
890 | Examples: "PERL_ANYEVENT_PROTOCOLS=ipv4,ipv6" - prefer IPv4 over |
879 | IPv6, but support both and try to use both. |
891 | IPv6, but support both and try to use both. |
880 | "PERL_ANYEVENT_PROTOCOLS=ipv4" - only support IPv4, never try to |
892 | "PERL_ANYEVENT_PROTOCOLS=ipv4" - only support IPv4, never try to |
881 | resolve or contact IPv6 addresses. |
893 | resolve or contact IPv6 addresses. |
… | |
… | |
1387 | |
1399 | |
1388 | BUGS |
1400 | BUGS |
1389 | Perl 5.8 has numerous memleaks that sometimes hit this module and are |
1401 | Perl 5.8 has numerous memleaks that sometimes hit this module and are |
1390 | hard to work around. If you suffer from memleaks, first upgrade to Perl |
1402 | hard to work around. If you suffer from memleaks, first upgrade to Perl |
1391 | 5.10 and check wether the leaks still show up. (Perl 5.10.0 has other |
1403 | 5.10 and check wether the leaks still show up. (Perl 5.10.0 has other |
1392 | annoying mamleaks, such as leaking on "map" and "grep" but it is usually |
1404 | annoying memleaks, such as leaking on "map" and "grep" but it is usually |
1393 | not as pronounced). |
1405 | not as pronounced). |
1394 | |
1406 | |
1395 | SEE ALSO |
1407 | SEE ALSO |
1396 | Utility functions: AnyEvent::Util. |
1408 | Utility functions: AnyEvent::Util. |
1397 | |
1409 | |