Mercurial > hg > nginx-tests
changeset 1825:3629eda94c1b
Tests: handling of EWOULDBLOCK from sysread() with IO::Socket::SSL.
With IO::Socket::SSL, when select() reports that the socket is readable,
reading from it might still fail with EWOULDBLOCK, since no application
data is available in the socket. In particular, this might happen with
TLSv1.3 when a session ticket is received after the handshake. Fix is
to explicitly check for EWOULDBLOCK errors.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 21 Mar 2023 02:57:39 +0300 |
parents | 5d3aee48ed8e |
children | 1f125771f1a1 |
files | lib/Test/Nginx/IMAP.pm lib/Test/Nginx/POP3.pm lib/Test/Nginx/SMTP.pm lib/Test/Nginx/Stream.pm |
diffstat | 4 files changed, 10 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/Test/Nginx/IMAP.pm Tue Mar 21 02:57:20 2023 +0300 +++ b/lib/Test/Nginx/IMAP.pm Tue Mar 21 02:57:39 2023 +0300 @@ -68,7 +68,9 @@ while (IO::Select->new($socket)->can_read(8)) { $socket->blocking(0); my $n = $socket->sysread(my $buf, 1024); + my $again = !defined $n && $!{EWOULDBLOCK}; $socket->blocking(1); + next if $again; last unless $n; $self->{_read_buffer} .= $buf;
--- a/lib/Test/Nginx/POP3.pm Tue Mar 21 02:57:20 2023 +0300 +++ b/lib/Test/Nginx/POP3.pm Tue Mar 21 02:57:39 2023 +0300 @@ -68,7 +68,9 @@ while (IO::Select->new($socket)->can_read(8)) { $socket->blocking(0); my $n = $socket->sysread(my $buf, 1024); + my $again = !defined $n && $!{EWOULDBLOCK}; $socket->blocking(1); + next if $again; last unless $n; $self->{_read_buffer} .= $buf;
--- a/lib/Test/Nginx/SMTP.pm Tue Mar 21 02:57:20 2023 +0300 +++ b/lib/Test/Nginx/SMTP.pm Tue Mar 21 02:57:39 2023 +0300 @@ -68,7 +68,9 @@ while (IO::Select->new($socket)->can_read(8)) { $socket->blocking(0); my $n = $socket->sysread(my $buf, 1024); + my $again = !defined $n && $!{EWOULDBLOCK}; $socket->blocking(1); + next if $again; last unless $n; $self->{_read_buffer} .= $buf;
--- a/lib/Test/Nginx/Stream.pm Tue Mar 21 02:57:20 2023 +0300 +++ b/lib/Test/Nginx/Stream.pm Tue Mar 21 02:57:39 2023 +0300 @@ -84,8 +84,10 @@ $s = $self->{_socket}; $s->blocking(0); - if (IO::Select->new($s)->can_read($extra{read_timeout} || 8)) { - $s->sysread($buf, 1024); + while (IO::Select->new($s)->can_read($extra{read_timeout} || 8)) { + my $n = $s->sysread($buf, 1024); + next if !defined $n && $!{EWOULDBLOCK}; + last; } log_in($buf);