diff options
author | Andy Polyakov <appro@openssl.org> | 2018-04-05 18:56:52 +0200 |
---|---|---|
committer | Andy Polyakov <appro@openssl.org> | 2018-04-08 11:41:56 +0200 |
commit | 55fd5d3fc5f7df2bbbdc11caa14a33da383cf65b (patch) | |
tree | 361a9854f1fee83b4408b048a8edfdf8549d340d | |
parent | 6e301900503f43564029754c799976c89950d33e (diff) |
TLSProxy/Proxy.pm: harmonize inner loop with the way sockets are.
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5887)
-rw-r--r-- | util/perl/TLSProxy/Proxy.pm | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/util/perl/TLSProxy/Proxy.pm b/util/perl/TLSProxy/Proxy.pm index c20b556c02..8f7f983ebc 100644 --- a/util/perl/TLSProxy/Proxy.pm +++ b/util/perl/TLSProxy/Proxy.pm @@ -356,7 +356,8 @@ sub clientstart my @ready; my $ctr = 0; local $SIG{PIPE} = "IGNORE"; - while( (!(TLSProxy::Message->end) + while($fdset->count + && (!(TLSProxy::Message->end) || (defined $self->sessionfile() && (-s $self->sessionfile()) == 0)) && $ctr < 10) { @@ -366,15 +367,25 @@ sub clientstart } foreach my $hand (@ready) { if ($hand == $server_sock) { - $server_sock->sysread($indata, 16384) or goto END; - $indata = $self->process_packet(1, $indata); - $client_sock->syswrite($indata); - $ctr = 0; + if ($server_sock->sysread($indata, 16384)) { + if ($indata = $self->process_packet(1, $indata)) { + $client_sock->syswrite($indata) or goto END; + } + $ctr = 0; + } else { + $fdset->remove($server_sock); + $client_sock->shutdown(SHUT_WR); + } } elsif ($hand == $client_sock) { - $client_sock->sysread($indata, 16384) or goto END; - $indata = $self->process_packet(0, $indata); - $server_sock->syswrite($indata); - $ctr = 0; + if ($client_sock->sysread($indata, 16384)) { + if ($indata = $self->process_packet(0, $indata)) { + $server_sock->syswrite($indata) or goto END; + } + $ctr = 0; + } else { + $fdset->remove($client_sock); + $server_sock->shutdown(SHUT_WR); + } } else { kill(3, $self->{real_serverpid}); die "Unexpected handle"; |