From: Guilhem Moulin Date: Tue, 8 Mar 2016 16:30:48 +0000 (+0100) Subject: Net::IMAP::InterIMAP: try again if connect(2) was interrupted. X-Git-Url: https://git.g-eek.se/?a=commitdiff_plain;h=c61cd2c80674757c9a910b4d379e5b92f65cbec7;p=interimap.git Net::IMAP::InterIMAP: try again if connect(2) was interrupted. --- diff --git a/lib/Net/IMAP/InterIMAP.pm b/lib/Net/IMAP/InterIMAP.pm index be62a9d..785de38 100644 --- a/lib/Net/IMAP/InterIMAP.pm +++ b/lib/Net/IMAP/InterIMAP.pm @@ -1366,15 +1366,18 @@ sub _tcp_connect($$$) { my ($err, @res) = getaddrinfo($host, $port, \%hints); $self->fail("Can't getaddrinfo: $err") if $err ne ''; + SOCKETS: foreach my $ai (@res) { - socket my $s, $ai->{family}, $ai->{socktype}, $ai->{protocol}; + socket (my $s, $ai->{family}, $ai->{socktype}, $ai->{protocol}) or $self->panic("connect: $!"); # TODO: add a connection timeout # http://devpit.org/wiki/Connect%28%29_with_timeout_%28in_Perl%29 - if (defined $s and connect($s, $ai->{addr})) { - my $flags = fcntl($s, F_GETFL, 0) or $self->panic("fcntl F_GETFL: $!"); - fcntl($s, F_SETFL, $flags | FD_CLOEXEC) or $self->panic("fcntl F_SETFL: $!"); - return $s; + until (connect($s, $ai->{addr})) { + next if $! == EINTR; # try again if connect(2) was interrupted by a signal + next SOCKETS; } + my $flags = fcntl($s, F_GETFL, 0) or $self->panic("fcntl F_GETFL: $!"); + fcntl($s, F_SETFL, $flags | FD_CLOEXEC) or $self->panic("fcntl F_SETFL: $!"); + return $s; } $self->fail("Can't connect to $host:$port"); }