--- AnyEvent/lib/AnyEvent/Handle.pm 2009/01/21 06:06:22 1.114 +++ AnyEvent/lib/AnyEvent/Handle.pm 2009/06/29 21:00:32 1.130 @@ -16,7 +16,7 @@ =cut -our $VERSION = 4.331; +our $VERSION = 4.45; =head1 SYNOPSIS @@ -129,7 +129,9 @@ read buffer). To access (and remove data from) the read buffer, use the C<< ->rbuf >> -method or access the C<$handle->{rbuf}> member directly. +method or access the C<$handle->{rbuf}> member directly. Note that you +must not enlarge or modify the read buffer, you can only remove data at +the beginning from it. When an EOF condition is detected then AnyEvent::Handle will first try to feed all the remaining data to the queued callbacks and C before @@ -312,15 +314,9 @@ sub _shutdown { my ($self) = @_; - delete $self->{_tw}; - delete $self->{_rw}; - delete $self->{_ww}; - delete $self->{fh}; + delete @$self{qw(_tw _rw _ww fh rbuf wbuf on_read _queue)}; &_freetls; - - delete $self->{on_read}; - delete $self->{_queue}; } sub _error { @@ -769,6 +765,10 @@ } while () { + # we need to use a separate tls read buffer, as we must not receive data while + # we are draining the buffer, and this can only happen with TLS. + $self->{rbuf} .= delete $self->{_tls_rbuf} if exists $self->{_tls_rbuf}; + my $len = length $self->{rbuf}; if (my $cb = shift @{ $self->{_queue} }) { @@ -839,8 +839,11 @@ Returns the read buffer (as a modifiable lvalue). -You can access the read buffer directly as the C<< ->{rbuf} >> member, if -you want. +You can access the read buffer directly as the C<< ->{rbuf} >> +member, if you want. However, the only operation allowed on the +read buffer (apart from looking at it) is removing data from its +beginning. Otherwise modifying or appending to it is not allowed and will +lead to hard-to-track-down bugs. NOTE: The read buffer should only be used or modified if the C, C or C methods are used. The other read methods @@ -1345,7 +1348,7 @@ &_freetls; } - $self->{rbuf} .= $tmp; + $self->{_tls_rbuf} .= $tmp; $self->_drain_rbuf unless $self->{_in_drain}; $self->{tls} or return; # tls session might have gone away in callback } @@ -1355,7 +1358,7 @@ if ($tmp != Net::SSLeay::ERROR_WANT_READ ()) { if ($tmp == Net::SSLeay::ERROR_SYSCALL ()) { return $self->_error ($!, 1); - } elsif ($tmp == Net::SSLeay::ERROR_SSL ()) { + } elsif ($tmp == Net::SSLeay::ERROR_SSL ()) { return $self->_error (&Errno::EIO, 1); } @@ -1466,7 +1469,7 @@ } sub DESTROY { - my $self = shift; + my ($self) = @_; &_freetls;