… | |
… | |
1714 | } |
1714 | } |
1715 | |
1715 | |
1716 | sub start_read { |
1716 | sub 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 | |
1928 | Shuts down the SSL connection - this makes a proper EOF handshake by |
1929 | Shuts down the SSL connection - this makes a proper EOF handshake by |
1929 | sending a close notify to the other side, but since OpenSSL doesn't |
1930 | sending a close notify to the other side, but since OpenSSL doesn't |
1930 | support non-blocking shut downs, it is not guarenteed that you can re-use |
1931 | support non-blocking shut downs, it is not guaranteed that you can re-use |
1931 | the stream afterwards. |
1932 | the stream afterwards. |
1932 | |
1933 | |
1933 | =cut |
1934 | =cut |
1934 | |
1935 | |
1935 | sub stoptls { |
1936 | sub 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 | |
2021 | sub AnyEvent::Handle::destroyed::AUTOLOAD { |
2022 | sub AnyEvent::Handle::destroyed::AUTOLOAD { |
2022 | #nop |
2023 | #nop |
2023 | } |
2024 | } |
2024 | |
2025 | |
|
|
2026 | =item $handle->destroyed |
|
|
2027 | |
|
|
2028 | Returns false as long as the handle hasn't been destroyed by a call to C<< |
|
|
2029 | ->destroy >>, true otherwise. |
|
|
2030 | |
|
|
2031 | Can be useful to decide whether the handle is still valid after some |
|
|
2032 | callback possibly destroyed the handle. For example, C<< ->push_write >>, |
|
|
2033 | C<< ->starttls >> and other methods can call user callbacks, which in turn |
|
|
2034 | can 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 | |
|
|
2040 | Note that the call to C<push_write> will silently be ignored if the handle |
|
|
2041 | has been destroyed, so often you can just ignore the possibility of the |
|
|
2042 | handle being destroyed. |
|
|
2043 | |
|
|
2044 | =cut |
|
|
2045 | |
|
|
2046 | sub destroyed { 0 } |
|
|
2047 | sub AnyEvent::Handle::destroyed::destroyed { 1 } |
|
|
2048 | |
2025 | =item AnyEvent::Handle::TLS_CTX |
2049 | =item AnyEvent::Handle::TLS_CTX |
2026 | |
2050 | |
2027 | This function creates and returns the AnyEvent::TLS object used by default |
2051 | This function creates and returns the AnyEvent::TLS object used by default |
2028 | for TLS mode. |
2052 | for TLS mode. |
2029 | |
2053 | |