--- AnyEvent/lib/AnyEvent/Handle.pm 2009/01/21 06:01:35 1.112 +++ AnyEvent/lib/AnyEvent/Handle.pm 2009/02/12 17:33:38 1.118 @@ -16,7 +16,7 @@ =cut -our $VERSION = 4.331; +our $VERSION = 4.34; =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 @@ -769,6 +771,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 +845,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 @@ -1174,22 +1183,15 @@ my $json = $self->{json} ||= JSON->new->utf8; sub { - eval { - my $ref = $json->incr_parse ($self->{rbuf}); - - if ($ref) { - $self->{rbuf} = $json->incr_text; - $json->incr_text = ""; - $cb->($self, $ref); + my $ref = eval { $json->incr_parse ($self->{rbuf}) }; - 1 - } else { - $self->{rbuf} = ""; - () - } + if ($ref) { + $self->{rbuf} = $json->incr_text; + $json->incr_text = ""; + $cb->($self, $ref); 1 - } or do { + } elsif ($@) { # error case $json->incr_skip; @@ -1197,7 +1199,13 @@ $json->incr_text = ""; $self->_error (&Errno::EBADMSG); - }; + + () + } else { + $self->{rbuf} = ""; + + () + } } }; @@ -1346,7 +1354,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 } @@ -1356,7 +1364,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); }