Skip to content

Commit

Permalink
the handle is required anyway
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 13, 2017
1 parent 6a9a9fc commit ecb8c20
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/Mojo/IOLoop/Client.pm
Expand Up @@ -152,10 +152,10 @@ sub _try_tls {

# Start TLS handshake
weaken $self;
my $tls = Mojo::IOLoop::TLS->new(reactor => $reactor);
my $tls = Mojo::IOLoop::TLS->new($handle)->reactor($self->reactor);
$tls->on(upgrade => sub { $self->_cleanup->emit(connect => pop) });
$tls->on(error => sub { $self->emit(error => pop) });
$tls->negotiate(%$args, handle => $handle);
$tls->negotiate(%$args);
}

sub _wait {
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/IOLoop/Server.pm
Expand Up @@ -95,10 +95,10 @@ sub _accept {
$self->emit(accept => $handle) and next unless my $args = $self->{args};

# Start TLS handshake
my $tls = Mojo::IOLoop::TLS->new(reactor => $self->reactor);
my $tls = Mojo::IOLoop::TLS->new($handle)->reactor($self->reactor);
$tls->on(upgrade => sub { $self->emit(accept => pop) });
$tls->on(error => sub { });
$tls->negotiate(%$args, handle => $handle, server => 1);
$tls->negotiate(%$args, server => 1);
}
}

Expand Down
26 changes: 14 additions & 12 deletions lib/Mojo/IOLoop/TLS.pm
Expand Up @@ -59,13 +59,15 @@ sub negotiate {
$tls->{SSL_verifycn_name} = $args->{address};
}

my $handle = $args->{handle};
my $handle = $self->{handle};
return $self->emit(error => $IO::Socket::SSL::SSL_ERROR)
unless IO::Socket::SSL->start_SSL($handle, %$tls);
$self->reactor->io($self->{handle}
$self->reactor->io($handle
= $handle => sub { $self->_tls($handle, $args->{server}) });
}

sub new { shift->SUPER::new(handle => shift) }

sub _tls {
my ($self, $handle, $server) = @_;

Expand All @@ -91,7 +93,7 @@ Mojo::IOLoop::TLS - Non-blocking TLS handshake
use Mojo::IOLoop::TLS;
# Negotiate TLS
my $tls = Mojo::IOLoop::TLS->new;
my $tls = Mojo::IOLoop::TLS->new($old_handle);
$tls->on(upgrade => sub {
my ($tls, $new_handle) = @_;
...
Expand All @@ -100,7 +102,7 @@ Mojo::IOLoop::TLS - Non-blocking TLS handshake
my ($tls, $err) = @_;
...
});
$tls->negotiate(handle => $old_handle, server => 1);
$tls->negotiate(server => 1, tls_version => 'TLSv1_2');
# Start reactor if necessary
$tls->reactor->start unless $tls->reactor->is_running;
Expand Down Expand Up @@ -151,21 +153,15 @@ implements the following new ones.
=head2 negotiate
$tls->negotiate(handle => $handle, server => 1);
$tls->negotiate({handle => $handle, server => 1});
$tls->negotiate(server => 1, tls_version => 'TLSv1_2');
$tls->negotiate({server => 1, tls_version => 'TLSv1_2'});
Negotiate TLS.
These options are currently available:
=over 2
=item handle
handle => $handle
L<IO::Socket::IP> object to negotiate TLS with.
=item server
server => 1
Expand Down Expand Up @@ -216,6 +212,12 @@ TLS protocol version.
=back
=head2 new
my $tls = Mojo::IOLoop::TLS->new($handle);
Construct a new L<Mojo::IOLoop::Stream> object.
=head1 CONSTANTS
L<Mojo::IOLoop::TLS> implements the following constants, which can be
Expand Down

0 comments on commit ecb8c20

Please sign in to comment.