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.191 by root, Sun Jan 31 22:33:45 2010 UTC vs.
Revision 1.192 by root, Fri Mar 12 23:22:14 2010 UTC

1714} 1714}
1715 1715
1716sub start_read { 1716sub start_read {
1717 my ($self) = @_; 1717 my ($self) = @_;
1718 1718
1719 unless ($self->{_rw} || $self->{_eof}) { 1719 unless ($self->{_rw} || $self->{_eof} || !$self->{fh}) {
1720 Scalar::Util::weaken $self; 1720 Scalar::Util::weaken $self;
1721 1721
1722 $self->{_rw} = AE::io $self->{fh}, 0, sub { 1722 $self->{_rw} = AE::io $self->{fh}, 0, sub {
1723 my $rbuf = \($self->{tls} ? my $buf : $self->{rbuf}); 1723 my $rbuf = \($self->{tls} ? my $buf : $self->{rbuf});
1724 my $len = sysread $self->{fh}, $$rbuf, $self->{read_size} || 8192, length $$rbuf; 1724 my $len = sysread $self->{fh}, $$rbuf, $self->{read_size} || 8192, length $$rbuf;
1817 && ($tmp != $ERROR_SYSCALL || $!); 1817 && ($tmp != $ERROR_SYSCALL || $!);
1818 1818
1819 while (length ($tmp = Net::SSLeay::BIO_read ($self->{_wbio}))) { 1819 while (length ($tmp = Net::SSLeay::BIO_read ($self->{_wbio}))) {
1820 $self->{wbuf} .= $tmp; 1820 $self->{wbuf} .= $tmp;
1821 $self->_drain_wbuf; 1821 $self->_drain_wbuf;
1822 $self->{tls} or return; # tls session might have gone away in callback
1822 } 1823 }
1823 1824
1824 $self->{_on_starttls} 1825 $self->{_on_starttls}
1825 and Net::SSLeay::state ($self->{tls}) == Net::SSLeay::ST_OK () 1826 and Net::SSLeay::state ($self->{tls}) == Net::SSLeay::ST_OK ()
1826 and (delete $self->{_on_starttls})->($self, 1, "TLS/SSL connection established"); 1827 and (delete $self->{_on_starttls})->($self, 1, "TLS/SSL connection established");
1925 1926
1926=item $handle->stoptls 1927=item $handle->stoptls
1927 1928
1928Shuts down the SSL connection - this makes a proper EOF handshake by 1929Shuts down the SSL connection - this makes a proper EOF handshake by
1929sending a close notify to the other side, but since OpenSSL doesn't 1930sending a close notify to the other side, but since OpenSSL doesn't
1930support non-blocking shut downs, it is not guarenteed that you can re-use 1931support non-blocking shut downs, it is not guaranteed that you can re-use
1931the stream afterwards. 1932the stream afterwards.
1932 1933
1933=cut 1934=cut
1934 1935
1935sub stoptls { 1936sub stoptls {
1936 my ($self) = @_; 1937 my ($self) = @_;
1937 1938
1938 if ($self->{tls}) { 1939 if ($self->{tls} && $self->{fh}) {
1939 Net::SSLeay::shutdown ($self->{tls}); 1940 Net::SSLeay::shutdown ($self->{tls});
1940 1941
1941 &_dotls; 1942 &_dotls;
1942 1943
1943# # we don't give a shit. no, we do, but we can't. no...#d# 1944# # we don't give a shit. no, we do, but we can't. no...#d#
2020 2021
2021sub AnyEvent::Handle::destroyed::AUTOLOAD { 2022sub AnyEvent::Handle::destroyed::AUTOLOAD {
2022 #nop 2023 #nop
2023} 2024}
2024 2025
2026=item $handle->destroyed
2027
2028Returns false as long as the handle hasn't been destroyed by a call to C<<
2029->destroy >>, true otherwise.
2030
2031Can be useful to decide whether the handle is still valid after some
2032callback possibly destroyed the handle. For example, C<< ->push_write >>,
2033C<< ->starttls >> and other methods can call user callbacks, which in turn
2034can destroy the handle, so work can be avoided by checking sometimes:
2035
2036 $hdl->starttls ("accept");
2037 return if $hdl->destroyed;
2038 $hdl->push_write (...
2039
2040Note that the call to C<push_write> will silently be ignored if the handle
2041has been destroyed, so often you can just ignore the possibility of the
2042handle being destroyed.
2043
2044=cut
2045
2046sub destroyed { 0 }
2047sub AnyEvent::Handle::destroyed::destroyed { 1 }
2048
2025=item AnyEvent::Handle::TLS_CTX 2049=item AnyEvent::Handle::TLS_CTX
2026 2050
2027This function creates and returns the AnyEvent::TLS object used by default 2051This function creates and returns the AnyEvent::TLS object used by default
2028for TLS mode. 2052for TLS mode.
2029 2053

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines