--- AnyEvent/lib/AnyEvent/Handle.pm 2009/07/03 00:09:04 1.134 +++ AnyEvent/lib/AnyEvent/Handle.pm 2009/07/04 23:58:52 1.137 @@ -16,7 +16,7 @@ =cut -our $VERSION = 4.45; +our $VERSION = 4.452; =head1 SYNOPSIS @@ -1218,13 +1218,13 @@ register_read_type json => sub { my ($self, $cb) = @_; - require JSON; + my $json = $self->{json} ||= + eval { require JSON::XS; JSON::XS->new->utf8 } + || do { require JSON; JSON->new->utf8 }; my $data; my $rbuf = \$self->{rbuf}; - my $json = $self->{json} ||= JSON->new->utf8; - sub { my $ref = eval { $json->incr_parse ($self->{rbuf}) }; @@ -1383,13 +1383,16 @@ sub _tls_error { my ($self, $err) = @_; - warn "$err,$!\n";#d# return $self->_error ($!, 1) if $err == Net::SSLeay::ERROR_SYSCALL (); - $self->_error (&Errno::EPROTO, 1, - Net::SSLeay::ERR_error_string (Net::SSLeay::ERR_get_error ())); + my $err =Net::SSLeay::ERR_error_string (Net::SSLeay::ERR_get_error ()); + + # reduce error string to look less scary + $err =~ s/^error:[0-9a-fA-F]{8}:[^:]+:([^:]+):/\L$1: /; + + $self->_error (&Errno::EPROTO, 1, $err); } # poll the write BIO and send the data if applicable @@ -1463,6 +1466,8 @@ =cut +our %TLS_CACHE; #TODO not yet documented, should we? + sub starttls { my ($self, $ssl, $ctx) = @_; @@ -1481,7 +1486,13 @@ require AnyEvent::TLS; local $Carp::CarpLevel = 1; # skip ourselves when creating a new context - $ctx = new AnyEvent::TLS %$ctx; + + if ($ctx->{cache}) { + my $key = $ctx+0; + $ctx = $TLS_CACHE{$key} ||= new AnyEvent::TLS %$ctx; + } else { + $ctx = new AnyEvent::TLS %$ctx; + } } $self->{tls_ctx} = $ctx || TLS_CTX ();