Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @@ -22,8 +22,8 @@ use constant TLS_WRITE => TLS ? IO::Socket::SSL::SSL_WANT_WRITE() : 0;
- # To regenerate the certificate run this command (18.04.2012)
- # openssl req -new -x509 -keyout server.key -out server.crt -nodes -days 7300
- -my $CERT = catfile dirname(__FILE__), 'server.crt';
- -my $KEY = catfile dirname(__FILE__), 'server.key';
- +our $CERT = catfile dirname(__FILE__), 'server.crt';
- +our $KEY = catfile dirname(__FILE__), 'server.key';
- has multi_accept => 50;
- has reactor => sub {
- @@ -109,6 +109,23 @@ sub start {
- $self->{handle} => sub { $self->_accept for 1 .. $self->multi_accept });
- }
- +sub start_tls {
- + my ($self, $handle, $args) = @_;
- + weaken $self;
- + my %opts = (
- + $self->{tls} ? %{$self->{tls}} : (),
- + $args ? %$args : (),
- + );
- + $opts{SSL_error_trap} = sub {
- + return unless my $handle = delete $self->{handles}{shift()};
- + $self->reactor->remove($handle);
- + close $handle;
- + };
- + return unless $handle = IO::Socket::SSL->start_SSL($handle, %opts);
- + $self->reactor->io($handle => sub { $self->_tls($handle) });
- + $self->{handles}{$handle} = $handle;
- +}
- +
- sub stop { $_[0]->reactor->remove($_[0]{handle}) }
- sub _accept {
- @@ -121,16 +138,8 @@ sub _accept {
- setsockopt $handle, IPPROTO_TCP, TCP_NODELAY, 1;
- # Start TLS handshake
- - return $self->emit_safe(accept => $handle) unless my $tls = $self->{tls};
- - weaken $self;
- - $tls->{SSL_error_trap} = sub {
- - return unless my $handle = delete $self->{handles}{shift()};
- - $self->reactor->remove($handle);
- - close $handle;
- - };
- - return unless $handle = IO::Socket::SSL->start_SSL($handle, %$tls);
- - $self->reactor->io($handle => sub { $self->_tls($handle) });
- - $self->{handles}{$handle} = $handle;
- + return $self->emit_safe(accept => $handle) unless $self->{tls};
- + $self->start_tls($handle);
- }
- sub _tls {
- @@ -273,6 +282,12 @@ Find a free TCP port, this is a utility function primarily used for tests.
- Start accepting connections.
- +=head2 start_tls
- +
- + $server->start_tls($handle);
- +
- +Perform TLS handshake for handle.
- +
- =head2 stop
- $server->stop;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement