dgaramond2 has asked for the wisdom of the Perl Monks concerning the following question:

$Server = IO::Socket::UNIX->new(Listen=>1, ...) or die; while(1) { $sock = $Server->accept(); next unless $sock; ... }

Why does sometimes accept() return undef (and thus I need the 'next unless $sock' line)? Shouldn't accept() block and return a valid socket each time?

Replies are listed 'Best First'.
Re: Empty after accept?
by Fletch (Bishop) on Mar 13, 2006 at 13:08 UTC

    Not if there were an error (or I believe if you've set the socket to be non-blocking; but still in that case I think $! would still be set to EWOULDBLOCK). Check $! and see what it says.