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

Comparing AnyEvent/lib/AnyEvent/Handle.pm (file contents):
Revision 1.192 by root, Fri Mar 12 23:22:14 2010 UTC vs.
Revision 1.196 by root, Tue Jun 8 10:04:17 2010 UTC

1=head1 NAME 1=head1 NAME
2 2
3AnyEvent::Handle - non-blocking I/O on file handles via AnyEvent 3AnyEvent::Handle - non-blocking I/O on streaming handles via AnyEvent
4 4
5=head1 SYNOPSIS 5=head1 SYNOPSIS
6 6
7 use AnyEvent; 7 use AnyEvent;
8 use AnyEvent::Handle; 8 use AnyEvent::Handle;
31 $cv->recv; 31 $cv->recv;
32 32
33=head1 DESCRIPTION 33=head1 DESCRIPTION
34 34
35This module is a helper module to make it easier to do event-based I/O on 35This module is a helper module to make it easier to do event-based I/O on
36filehandles. 36stream-based filehandles (sockets, pipes or other stream things).
37 37
38The L<AnyEvent::Intro> tutorial contains some well-documented 38The L<AnyEvent::Intro> tutorial contains some well-documented
39AnyEvent::Handle examples. 39AnyEvent::Handle examples.
40 40
41In the following, when the documentation refers to of "bytes" then this 41In the following, when the documentation refers to of "bytes" then this
532} 532}
533 533
534sub _start { 534sub _start {
535 my ($self) = @_; 535 my ($self) = @_;
536 536
537 # too many clueless people try to use udp and similar sockets
538 # with AnyEvent::Handle, do them a favour.
539 my $type = getsockopt $self->{fh}, Socket::SOL_SOCKET (), Socket::SO_TYPE ();
540 Carp::croak "AnyEvent::Handle: only stream sockets supported, anything else will NOT work!"
541 if Socket::SOCK_STREAM () != (unpack "I", $type) && defined $type;
542
537 AnyEvent::Util::fh_nonblocking $self->{fh}, 1; 543 AnyEvent::Util::fh_nonblocking $self->{fh}, 1;
538 544
539 $self->{_activity} = 545 $self->{_activity} =
540 $self->{_ractivity} = 546 $self->{_ractivity} =
541 $self->{_wactivity} = AE::now; 547 $self->{_wactivity} = AE::now;
832=item $handle->on_drain ($cb) 838=item $handle->on_drain ($cb)
833 839
834Sets the C<on_drain> callback or clears it (see the description of 840Sets the C<on_drain> callback or clears it (see the description of
835C<on_drain> in the constructor). 841C<on_drain> in the constructor).
836 842
843This method may invoke callbacks (and therefore the handle might be
844destroyed after it returns).
845
837=cut 846=cut
838 847
839sub on_drain { 848sub on_drain {
840 my ($self, $cb) = @_; 849 my ($self, $cb) = @_;
841 850
848=item $handle->push_write ($data) 857=item $handle->push_write ($data)
849 858
850Queues the given scalar to be written. You can push as much data as you 859Queues the given scalar to be written. You can push as much data as you
851want (only limited by the available memory), as C<AnyEvent::Handle> 860want (only limited by the available memory), as C<AnyEvent::Handle>
852buffers it independently of the kernel. 861buffers it independently of the kernel.
862
863This method may invoke callbacks (and therefore the handle might be
864destroyed after it returns).
853 865
854=cut 866=cut
855 867
856sub _drain_wbuf { 868sub _drain_wbuf {
857 my ($self) = @_; 869 my ($self) = @_;
1033This simply shuts down the write side and signals an EOF condition to the 1045This simply shuts down the write side and signals an EOF condition to the
1034the peer. 1046the peer.
1035 1047
1036You can rely on the normal read queue and C<on_eof> handling 1048You can rely on the normal read queue and C<on_eof> handling
1037afterwards. This is the cleanest way to close a connection. 1049afterwards. This is the cleanest way to close a connection.
1050
1051This method may invoke callbacks (and therefore the handle might be
1052destroyed after it returns).
1038 1053
1039=cut 1054=cut
1040 1055
1041sub push_shutdown { 1056sub push_shutdown {
1042 my ($self) = @_; 1057 my ($self) = @_;
1239 1254
1240This replaces the currently set C<on_read> callback, or clears it (when 1255This replaces the currently set C<on_read> callback, or clears it (when
1241the new callback is C<undef>). See the description of C<on_read> in the 1256the new callback is C<undef>). See the description of C<on_read> in the
1242constructor. 1257constructor.
1243 1258
1259This method may invoke callbacks (and therefore the handle might be
1260destroyed after it returns).
1261
1244=cut 1262=cut
1245 1263
1246sub on_read { 1264sub on_read {
1247 my ($self, $cb) = @_; 1265 my ($self, $cb) = @_;
1248 1266
1286available (or an error condition is detected). 1304available (or an error condition is detected).
1287 1305
1288If enough data was available, then the callback must remove all data it is 1306If enough data was available, then the callback must remove all data it is
1289interested in (which can be none at all) and return a true value. After returning 1307interested in (which can be none at all) and return a true value. After returning
1290true, it will be removed from the queue. 1308true, it will be removed from the queue.
1309
1310These methods may invoke callbacks (and therefore the handle might be
1311destroyed after it returns).
1291 1312
1292=cut 1313=cut
1293 1314
1294our %RH; 1315our %RH;
1295 1316
1851when this function returns. 1872when this function returns.
1852 1873
1853Due to bugs in OpenSSL, it might or might not be possible to do multiple 1874Due to bugs in OpenSSL, it might or might not be possible to do multiple
1854handshakes on the same stream. Best do not attempt to use the stream after 1875handshakes on the same stream. Best do not attempt to use the stream after
1855stopping TLS. 1876stopping TLS.
1877
1878This method may invoke callbacks (and therefore the handle might be
1879destroyed after it returns).
1856 1880
1857=cut 1881=cut
1858 1882
1859our %TLS_CACHE; #TODO not yet documented, should we? 1883our %TLS_CACHE; #TODO not yet documented, should we?
1860 1884
1929Shuts down the SSL connection - this makes a proper EOF handshake by 1953Shuts down the SSL connection - this makes a proper EOF handshake by
1930sending a close notify to the other side, but since OpenSSL doesn't 1954sending a close notify to the other side, but since OpenSSL doesn't
1931support non-blocking shut downs, it is not guaranteed that you can re-use 1955support non-blocking shut downs, it is not guaranteed that you can re-use
1932the stream afterwards. 1956the stream afterwards.
1933 1957
1958This method may invoke callbacks (and therefore the handle might be
1959destroyed after it returns).
1960
1934=cut 1961=cut
1935 1962
1936sub stoptls { 1963sub stoptls {
1937 my ($self) = @_; 1964 my ($self) = @_;
1938 1965

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines