ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Handle.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/Handle.pm (file contents):
Revision 1.233 by root, Thu Apr 5 06:14:10 2012 UTC vs.
Revision 1.234 by root, Wed Apr 18 09:44:10 2012 UTC

429appropriate error message. 429appropriate error message.
430 430
431TLS mode requires Net::SSLeay to be installed (it will be loaded 431TLS mode requires Net::SSLeay to be installed (it will be loaded
432automatically when you try to create a TLS handle): this module doesn't 432automatically when you try to create a TLS handle): this module doesn't
433have a dependency on that module, so if your module requires it, you have 433have a dependency on that module, so if your module requires it, you have
434to add the dependency yourself. 434to add the dependency yourself. If Net::SSLeay cannot be loaded or is too
435old, you get an C<EPROTO> error.
435 436
436Unlike TCP, TLS has a server and client side: for the TLS server side, use 437Unlike TCP, TLS has a server and client side: for the TLS server side, use
437C<accept>, and for the TLS client side of a connection, use C<connect> 438C<accept>, and for the TLS client side of a connection, use C<connect>
438mode. 439mode.
439 440
1937 1938
1938=item $handle->starttls ($tls[, $tls_ctx]) 1939=item $handle->starttls ($tls[, $tls_ctx])
1939 1940
1940Instead of starting TLS negotiation immediately when the AnyEvent::Handle 1941Instead of starting TLS negotiation immediately when the AnyEvent::Handle
1941object is created, you can also do that at a later time by calling 1942object is created, you can also do that at a later time by calling
1942C<starttls>. 1943C<starttls>. See the C<tls> constructor argument for general info.
1943 1944
1944Starting TLS is currently an asynchronous operation - when you push some 1945Starting TLS is currently an asynchronous operation - when you push some
1945write data and then call C<< ->starttls >> then TLS negotiation will start 1946write data and then call C<< ->starttls >> then TLS negotiation will start
1946immediately, after which the queued write data is then sent. 1947immediately, after which the queued write data is then sent. This might
1948change in future versions, so best make sure you have no outstanding write
1949data when calling this method.
1947 1950
1948The first argument is the same as the C<tls> constructor argument (either 1951The first argument is the same as the C<tls> constructor argument (either
1949C<"connect">, C<"accept"> or an existing Net::SSLeay object). 1952C<"connect">, C<"accept"> or an existing Net::SSLeay object).
1950 1953
1951The second argument is the optional C<AnyEvent::TLS> object that is used 1954The second argument is the optional C<AnyEvent::TLS> object that is used
1973 my ($self, $tls, $ctx) = @_; 1976 my ($self, $tls, $ctx) = @_;
1974 1977
1975 Carp::croak "It is an error to call starttls on an AnyEvent::Handle object while TLS is already active, caught" 1978 Carp::croak "It is an error to call starttls on an AnyEvent::Handle object while TLS is already active, caught"
1976 if $self->{tls}; 1979 if $self->{tls};
1977 1980
1981 unless (defined $AnyEvent::TLS::VERSION) {
1982 eval {
1983 require Net::SSLeay;
1984 require AnyEvent::TLS;
1985 1
1986 } or return $self->_error (Errno::EPROTO, 1, "TLS support not available on this system");
1987 }
1988
1978 $self->{tls} = $tls; 1989 $self->{tls} = $tls;
1979 $self->{tls_ctx} = $ctx if @_ > 2; 1990 $self->{tls_ctx} = $ctx if @_ > 2;
1980 1991
1981 return unless $self->{fh}; 1992 return unless $self->{fh};
1982 1993
1983 require Net::SSLeay;
1984
1985 $ERROR_SYSCALL = Net::SSLeay::ERROR_SYSCALL (); 1994 $ERROR_SYSCALL = Net::SSLeay::ERROR_SYSCALL ();
1986 $ERROR_WANT_READ = Net::SSLeay::ERROR_WANT_READ (); 1995 $ERROR_WANT_READ = Net::SSLeay::ERROR_WANT_READ ();
1987 1996
1988 $tls = delete $self->{tls}; 1997 $tls = delete $self->{tls};
1989 $ctx = $self->{tls_ctx}; 1998 $ctx = $self->{tls_ctx};
1990 1999
1991 local $Carp::CarpLevel = 1; # skip ourselves when creating a new context or session 2000 local $Carp::CarpLevel = 1; # skip ourselves when creating a new context or session
1992 2001
1993 if ("HASH" eq ref $ctx) { 2002 if ("HASH" eq ref $ctx) {
1994 require AnyEvent::TLS;
1995
1996 if ($ctx->{cache}) { 2003 if ($ctx->{cache}) {
1997 my $key = $ctx+0; 2004 my $key = $ctx+0;
1998 $ctx = $TLS_CACHE{$key} ||= new AnyEvent::TLS %$ctx; 2005 $ctx = $TLS_CACHE{$key} ||= new AnyEvent::TLS %$ctx;
1999 } else { 2006 } else {
2000 $ctx = new AnyEvent::TLS %$ctx; 2007 $ctx = new AnyEvent::TLS %$ctx;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines