Skip to content

Commit

Permalink
TLSProxy/Proxy.pm: harmonize inner loop with the way sockets are.
Browse files Browse the repository at this point in the history
Reviewed-by: Richard Levitte <[email protected]>
(Merged from openssl#5887)
  • Loading branch information
Andy Polyakov committed Apr 8, 2018
1 parent 6e30190 commit 55fd5d3
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions util/perl/TLSProxy/Proxy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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";
Expand Down

0 comments on commit 55fd5d3

Please sign in to comment.