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.227 by root, Mon Jul 6 23:42:24 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.8; 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}
2121L<Glib>, L<Tk>, L<Event::Lib>, L<Qt>, L<POE>. 2116L<Glib>, L<Tk>, L<Event::Lib>, L<Qt>, L<POE>.
2122 2117
2123Implementations: L<AnyEvent::Impl::EV>, L<AnyEvent::Impl::Event>, 2118Implementations: L<AnyEvent::Impl::EV>, L<AnyEvent::Impl::Event>,
2124L<AnyEvent::Impl::Glib>, L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>, 2119L<AnyEvent::Impl::Glib>, L<AnyEvent::Impl::Tk>, L<AnyEvent::Impl::Perl>,
2125L<AnyEvent::Impl::EventLib>, L<AnyEvent::Impl::Qt>, 2120L<AnyEvent::Impl::EventLib>, L<AnyEvent::Impl::Qt>,
2126L<AnyEvent::Impl::POE>. 2121L<AnyEvent::Impl::POE>, L<AnyEvent::Impl::IOAsync>.
2127 2122
2128Non-blocking file handles, sockets, TCP clients and 2123Non-blocking file handles, sockets, TCP clients and
2129servers: L<AnyEvent::Handle>, L<AnyEvent::Socket>. 2124servers: L<AnyEvent::Handle>, L<AnyEvent::Socket>, L<AnyEvent::TLS>.
2130 2125
2131Asynchronous DNS: L<AnyEvent::DNS>. 2126Asynchronous DNS: L<AnyEvent::DNS>.
2132 2127
2133Coroutine 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>,
2134 2130
2135Nontrivial usage examples: L<Net::FCP>, L<Net::XMPP2>, L<AnyEvent::DNS>. 2131Nontrivial usage examples: L<AnyEvent::GPSD>, L<AnyEvent::XMPP>,
2132L<AnyEvent::HTTP>.
2136 2133
2137 2134
2138=head1 AUTHOR 2135=head1 AUTHOR
2139 2136
2140 Marc Lehmann <schmorp@schmorp.de> 2137 Marc Lehmann <schmorp@schmorp.de>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines