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

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.223 by root, Mon Jun 29 21:00:32 2009 UTC vs.
Revision 1.231 by root, Wed Jul 8 13:46:46 2009 UTC

176=head2 I/O WATCHERS 176=head2 I/O WATCHERS
177 177
178You can create an I/O watcher by calling the C<< AnyEvent->io >> method 178You can create an I/O watcher by calling the C<< AnyEvent->io >> method
179with the following mandatory key-value pairs as arguments: 179with the following mandatory key-value pairs as arguments:
180 180
181C<fh> is the Perl I<file handle> (I<not> file descriptor) to watch 181C<fh> is the Perl I<file handle> (or a naked file descriptor) to watch
182for events (AnyEvent might or might not keep a reference to this file 182for events (AnyEvent might or might not keep a reference to this file
183handle). Note that only file handles pointing to things for which 183handle). Note that only file handles pointing to things for which
184non-blocking operation makes sense are allowed. This includes sockets, 184non-blocking operation makes sense are allowed. This includes sockets,
185most character devices, pipes, fifos and so on, but not for example files 185most character devices, pipes, fifos and so on, but not for example files
186or block devices. 186or block devices.
868 868
869 869
870=head1 OTHER MODULES 870=head1 OTHER MODULES
871 871
872The following is a non-exhaustive list of additional modules that use 872The following is a non-exhaustive list of additional modules that use
873AnyEvent and can therefore be mixed easily with other AnyEvent modules 873AnyEvent as a client and can therefore be mixed easily with other AnyEvent
874in the same program. Some of the modules come with AnyEvent, some are 874modules and other event loops in the same program. Some of the modules
875available via CPAN. 875come with AnyEvent, most are available via CPAN.
876 876
877=over 4 877=over 4
878 878
879=item L<AnyEvent::Util> 879=item L<AnyEvent::Util>
880 880
889 889
890=item L<AnyEvent::Handle> 890=item L<AnyEvent::Handle>
891 891
892Provide read and write buffers, manages watchers for reads and writes, 892Provide read and write buffers, manages watchers for reads and writes,
893supports raw and formatted I/O, I/O queued and fully transparent and 893supports raw and formatted I/O, I/O queued and fully transparent and
894non-blocking SSL/TLS. 894non-blocking SSL/TLS (via L<AnyEvent::TLS>.
895 895
896=item L<AnyEvent::DNS> 896=item L<AnyEvent::DNS>
897 897
898Provides rich asynchronous DNS resolver capabilities. 898Provides rich asynchronous DNS resolver capabilities.
899 899
927 927
928=item L<AnyEvent::GPSD> 928=item L<AnyEvent::GPSD>
929 929
930A non-blocking interface to gpsd, a daemon delivering GPS information. 930A non-blocking interface to gpsd, a daemon delivering GPS information.
931 931
932=item L<AnyEvent::IRC>
933
934AnyEvent based IRC client module family (replacing the older Net::IRC3).
935
936=item L<AnyEvent::XMPP>
937
938AnyEvent based XMPP (Jabber protocol) module family (replacing the older
939Net::XMPP2>.
940
932=item L<AnyEvent::IGS> 941=item L<AnyEvent::IGS>
933 942
934A non-blocking interface to the Internet Go Server protocol (used by 943A non-blocking interface to the Internet Go Server protocol (used by
935L<App::IGS>). 944L<App::IGS>).
936 945
937=item L<AnyEvent::IRC>
938
939AnyEvent based IRC client module family (replacing the older Net::IRC3).
940
941=item L<Net::XMPP2>
942
943AnyEvent based XMPP (Jabber protocol) module family.
944
945=item L<Net::FCP> 946=item L<Net::FCP>
946 947
947AnyEvent-based implementation of the Freenet Client Protocol, birthplace 948AnyEvent-based implementation of the Freenet Client Protocol, birthplace
948of AnyEvent. 949of AnyEvent.
949 950
953 954
954=item L<Coro> 955=item L<Coro>
955 956
956Has special support for AnyEvent via L<Coro::AnyEvent>. 957Has special support for AnyEvent via L<Coro::AnyEvent>.
957 958
958=item L<IO::Lambda>
959
960The lambda approach to I/O - don't ask, look there. Can use AnyEvent.
961
962=back 959=back
963 960
964=cut 961=cut
965 962
966package AnyEvent; 963package AnyEvent;
968no warnings; 965no warnings;
969use strict qw(vars subs); 966use strict qw(vars subs);
970 967
971use Carp; 968use Carp;
972 969
973our $VERSION = 4.45; 970our $VERSION = 4.801;
974our $MODEL; 971our $MODEL;
975 972
976our $AUTOLOAD; 973our $AUTOLOAD;
977our @ISA; 974our @ISA;
978 975
1123# allow only one watcher per fd, so we dup it to get a different one). 1120# allow only one watcher per fd, so we dup it to get a different one).
1124sub _dupfh($$;$$) { 1121sub _dupfh($$;$$) {
1125 my ($poll, $fh, $r, $w) = @_; 1122 my ($poll, $fh, $r, $w) = @_;
1126 1123
1127 # cygwin requires the fh mode to be matching, unix doesn't 1124 # cygwin requires the fh mode to be matching, unix doesn't
1128 my ($rw, $mode) = $poll eq "r" ? ($r, "<") 1125 my ($rw, $mode) = $poll eq "r" ? ($r, "<") : ($w, ">");
1129 : $poll eq "w" ? ($w, ">")
1130 : Carp::croak "AnyEvent->io requires poll set to either 'r' or 'w'";
1131 1126
1132 open my $fh2, "$mode&" . fileno $fh 1127 open my $fh2, "$mode&", $fh
1133 or die "cannot dup() filehandle: $!,"; 1128 or die "AnyEvent->io: cannot dup() filehandle in mode '$poll': $!,";
1134 1129
1135 # we assume CLOEXEC is already set by perl in all important cases 1130 # we assume CLOEXEC is already set by perl in all important cases
1136 1131
1137 ($fh2, $rw) 1132 ($fh2, $rw)
1138} 1133}
1470 1465
1471=item C<PERL_ANYEVENT_MAX_FORKS> 1466=item C<PERL_ANYEVENT_MAX_FORKS>
1472 1467
1473The maximum number of child processes that C<AnyEvent::Util::fork_call> 1468The maximum number of child processes that C<AnyEvent::Util::fork_call>
1474will create in parallel. 1469will create in parallel.
1470
1471=item C<PERL_ANYEVENT_MAX_OUTSTANDING_DNS>
1472
1473The default value for the C<max_outstanding> parameter for the default DNS
1474resolver - this is the maximum number of parallel DNS requests that are
1475sent to the DNS server.
1476
1477=item C<PERL_ANYEVENT_RESOLV_CONF>
1478
1479The file to use instead of F</etc/resolv.conf> (or OS-specific
1480configuration) in the default resolver. When set to the empty string, no
1481default config will be used.
1482
1483=item C<PERL_ANYEVENT_CA_FILE>, C<PERL_ANYEVENT_CA_PATH>.
1484
1485When neither C<ca_file> nor C<ca_path> was specified during
1486L<AnyEvent::TLS> context creation, and either of these environment
1487variables exist, they will be used to specify CA certificate locations
1488instead of a system-dependent default.
1475 1489
1476=back 1490=back
1477 1491
1478=head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE 1492=head1 SUPPLYING YOUR OWN EVENT MODEL INTERFACE
1479 1493
2102L<Glib>, L<Tk>, L<Event::Lib>, L<Qt>, L<POE>. 2116L<Glib>, L<Tk>, L<Event::Lib>, L<Qt>, L<POE>.
2103 2117
2104Implementations: L<AnyEvent::Impl::EV>, L<AnyEvent::Impl::Event>, 2118Implementations: L<AnyEvent::Impl::EV>, L<AnyEvent::Impl::Event>,
2105L<AnyEvent::Impl::Glib>, L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>, 2119L<AnyEvent::Impl::Glib>, L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>,
2106L<AnyEvent::Impl::EventLib>, L<AnyEvent::Impl::Qt>, 2120L<AnyEvent::Impl::EventLib>, L<AnyEvent::Impl::Qt>,
2107L<AnyEvent::Impl::POE>. 2121L<AnyEvent::Impl::POE>, L<AnyEvent::Impl::IOAsync>.
2108 2122
2109Non-blocking file handles, sockets, TCP clients and 2123Non-blocking file handles, sockets, TCP clients and
2110servers: L<AnyEvent::Handle>, L<AnyEvent::Socket>. 2124servers: L<AnyEvent::Handle>, L<AnyEvent::Socket>, L<AnyEvent::TLS>.
2111 2125
2112Asynchronous DNS: L<AnyEvent::DNS>. 2126Asynchronous DNS: L<AnyEvent::DNS>.
2113 2127
2114Coroutine support: L<Coro>, L<Coro::AnyEvent>, L<Coro::EV>, L<Coro::Event>, 2128Coroutine support: L<Coro>, L<Coro::AnyEvent>, L<Coro::EV>,
2129L<Coro::Event>,
2115 2130
2116Nontrivial usage examples: L<Net::FCP>, L<Net::XMPP2>, L<AnyEvent::DNS>. 2131Nontrivial usage examples: L<AnyEvent::GPSD>, L<AnyEvent::XMPP>,
2132L<AnyEvent::HTTP>.
2117 2133
2118 2134
2119=head1 AUTHOR 2135=head1 AUTHOR
2120 2136
2121 Marc Lehmann <schmorp@schmorp.de> 2137 Marc Lehmann <schmorp@schmorp.de>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines