… | |
… | |
176 | =head2 I/O WATCHERS |
176 | =head2 I/O WATCHERS |
177 | |
177 | |
178 | You can create an I/O watcher by calling the C<< AnyEvent->io >> method |
178 | You can create an I/O watcher by calling the C<< AnyEvent->io >> method |
179 | with the following mandatory key-value pairs as arguments: |
179 | with the following mandatory key-value pairs as arguments: |
180 | |
180 | |
181 | C<fh> is the Perl I<file handle> (I<not> file descriptor) to watch |
181 | C<fh> is the Perl I<file handle> (I<not> file descriptor, see below) to |
182 | for events (AnyEvent might or might not keep a reference to this file |
182 | watch for events (AnyEvent might or might not keep a reference to this |
183 | handle). Note that only file handles pointing to things for which |
183 | file handle). Note that only file handles pointing to things for which |
184 | non-blocking operation makes sense are allowed. This includes sockets, |
184 | non-blocking operation makes sense are allowed. This includes sockets, |
185 | most character devices, pipes, fifos and so on, but not for example files |
185 | most character devices, pipes, fifos and so on, but not for example files |
186 | or block devices. |
186 | or block devices. |
187 | |
187 | |
188 | C<poll> must be a string that is either C<r> or C<w>, which creates a |
188 | C<poll> must be a string that is either C<r> or C<w>, which creates a |
… | |
… | |
208 | my $w; $w = AnyEvent->io (fh => \*STDIN, poll => 'r', cb => sub { |
208 | my $w; $w = AnyEvent->io (fh => \*STDIN, poll => 'r', cb => sub { |
209 | chomp (my $input = <STDIN>); |
209 | chomp (my $input = <STDIN>); |
210 | warn "read: $input\n"; |
210 | warn "read: $input\n"; |
211 | undef $w; |
211 | undef $w; |
212 | }); |
212 | }); |
|
|
213 | |
|
|
214 | =head3 GETTING A FILE HANDLE FROM A FILE DESCRIPTOR |
|
|
215 | |
|
|
216 | It is not uncommon to only have a file descriptor, while AnyEvent requires |
|
|
217 | a Perl file handle. |
|
|
218 | |
|
|
219 | There are basically two methods to convert a file descriptor into a file handle. If you own |
|
|
220 | the file descriptor, you can open it with C<&=>, as in: |
|
|
221 | |
|
|
222 | open my $fh, "<&=$fileno" or die "xxx: ยง!"; |
|
|
223 | |
|
|
224 | This will "own" the file descriptor, meaning that when C<$fh> is |
|
|
225 | destroyed, it will automatically close the C<$fileno>. Also, note that |
|
|
226 | the open mode (read, write, read/write) must correspond with how the |
|
|
227 | underlying file descriptor was opened. |
|
|
228 | |
|
|
229 | In many cases, taking over the file descriptor is now what you want, in |
|
|
230 | which case the only alternative is to dup the file descriptor: |
|
|
231 | |
|
|
232 | open my $fh, "<&$fileno" or die "xxx: $!"; |
|
|
233 | |
|
|
234 | This has the advantage of not closing the file descriptor and the |
|
|
235 | disadvantage of making a slow copy. |
213 | |
236 | |
214 | =head2 TIME WATCHERS |
237 | =head2 TIME WATCHERS |
215 | |
238 | |
216 | You can create a time watcher by calling the C<< AnyEvent->timer >> |
239 | You can create a time watcher by calling the C<< AnyEvent->timer >> |
217 | method with the following mandatory arguments: |
240 | method with the following mandatory arguments: |
… | |
… | |
1471 | =item C<PERL_ANYEVENT_MAX_FORKS> |
1494 | =item C<PERL_ANYEVENT_MAX_FORKS> |
1472 | |
1495 | |
1473 | The maximum number of child processes that C<AnyEvent::Util::fork_call> |
1496 | The maximum number of child processes that C<AnyEvent::Util::fork_call> |
1474 | will create in parallel. |
1497 | will create in parallel. |
1475 | |
1498 | |
|
|
1499 | =item C<PERL_ANYEVENT_MAX_OUTSTANDING_DNS> |
|
|
1500 | |
|
|
1501 | The default value for the C<max_outstanding> parameter for the default DNS |
|
|
1502 | resolver - this is the maximum number of parallel DNS requests that are |
|
|
1503 | sent to the DNS server. |
|
|
1504 | |
|
|
1505 | =item C<PERL_ANYEVENT_RESOLV_CONF> |
|
|
1506 | |
|
|
1507 | The file to use instead of F</etc/resolv.conf> (or OS-specific |
|
|
1508 | configuration) in the default resolver. When set to the empty string, no |
|
|
1509 | default config will be used. |
|
|
1510 | |
|
|
1511 | =item C<PERL_ANYEVENT_CA_FILE>, C<PERL_ANYEVENT_CA_PATH>. |
|
|
1512 | |
|
|
1513 | When neither C<ca_file> nor C<ca_path> was specified during |
|
|
1514 | L<AnyEvent::TLS> context creation, and either of these environment |
|
|
1515 | variables exist, they will be used to specify CA certificate locations |
|
|
1516 | instead of a system-dependent default. |
|
|
1517 | |
1476 | =back |
1518 | =back |
1477 | |
1519 | |
1478 | =head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE |
1520 | =head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE |
1479 | |
1521 | |
1480 | This is an advanced topic that you do not normally need to use AnyEvent in |
1522 | This is an advanced topic that you do not normally need to use AnyEvent in |