[Perl] Testing for EAGAIN / EWOULDBLOCK on a recv
- by Robert S. Barnes
I'm testing a socket to see if it's still open:
my $dummy = '';
my $ret = recv($sock, $dummy, 1, MSG_DONTWAIT | MSG_PEEK);
if (!defined $ret || (length($dummy) == 0
&& $! != EAGAIN && $! != EWOULDBLOCK )) {
logerr("Broken pipe? ".__LINE__." $!");
} else {
# socket still connected, reuse
logerr(__LINE__.": $!");
return $sock;
}
I'm passing this code a socket I know for certain is open and it's always going through the first branch and logging "Broken pipe? 149 Resource temporarily unavailable".
I don't understand how this is happening since "Resource temporarily unavailable" is supposed to correspond to EAGAIN as far as I know.
I'm sure there must be something simple I'm missing. And yes, I know this is not a full proof way to test and I account for that.