--- AnyEvent/lib/AnyEvent/Handle.pm 2008/10/23 19:03:30 1.101 +++ AnyEvent/lib/AnyEvent/Handle.pm 2009/02/10 13:58:49 1.115 @@ -16,7 +16,7 @@ =cut -our $VERSION = 4.3; +our $VERSION = 4.331; =head1 SYNOPSIS @@ -29,7 +29,7 @@ AnyEvent::Handle->new ( fh => \*STDIN, on_eof => sub { - $cv->broadcast; + $cv->send; }, ); @@ -257,6 +257,11 @@ or C on it before you pass it to AnyEvent::Handle. +B since Net::SSLeay "objects" are really only integers, +passing in the wrong integer will lead to certain crash. This most often +happens when one uses a stylish C<< tls => 1 >> and is surprised about the +segmentation fault. + See the C<< ->starttls >> method for when need to start TLS negotiation later. =item tls_ctx => $ssl_ctx @@ -376,10 +381,14 @@ =item $handle->autocork ($boolean) Enables or disables the current autocork behaviour (see C -constructor argument). +constructor argument). Changes will only take effect on the next write. =cut +sub autocork { + $_[0]{autocork} = $_[1]; +} + =item $handle->no_delay ($boolean) Enables or disables the C setting (see constructor argument of @@ -760,6 +769,8 @@ } while () { + $self->{rbuf} .= delete $self->{tls_rbuf} if exists $self->{tls_rbuf};#d# + my $len = length $self->{rbuf}; if (my $cb = shift @{ $self->{_queue} }) { @@ -1137,7 +1148,8 @@ =item json => $cb->($handle, $hash_or_arrayref) -Reads a JSON object or array, decodes it and passes it to the callback. +Reads a JSON object or array, decodes it and passes it to the +callback. When a parse error occurs, an C error will be raised. If a C object was passed to the constructor, then that will be used for the final decode, otherwise it will create a JSON coder expecting UTF-8. @@ -1164,7 +1176,7 @@ my $json = $self->{json} ||= JSON->new->utf8; sub { - my $ref = $json->incr_parse ($self->{rbuf}); + my $ref = eval { $json->incr_parse ($self->{rbuf}) }; if ($ref) { $self->{rbuf} = $json->incr_text; @@ -1172,8 +1184,19 @@ $cb->($self, $ref); 1 + } elsif ($@) { + # error case + $json->incr_skip; + + $self->{rbuf} = $json->incr_text; + $json->incr_text = ""; + + $self->_error (&Errno::EBADMSG); + + () } else { $self->{rbuf} = ""; + () } } @@ -1324,7 +1347,7 @@ &_freetls; } - $self->{rbuf} .= $tmp; + $self->{tls_rbuf} .= $tmp;#d# $self->_drain_rbuf unless $self->{_in_drain}; $self->{tls} or return; # tls session might have gone away in callback } @@ -1373,7 +1396,7 @@ require Net::SSLeay; - Carp::croak "it is an error to call starttls more than once on an Anyevent::Handle object" + Carp::croak "it is an error to call starttls more than once on an AnyEvent::Handle object" if $self->{tls}; if ($ssl eq "accept") {