in reply to socket select hangs after client restarts

# Check client streams, close any in error

I don't think that is what $eout indicates. I know BrowserUK said:

The 4-arg select is defined as select RBITS,WBITS,EBITS,TIMEOUT where EBITS are those streams in your select group that have experienced error conditions.

but that is not my understanding of $eout. As far as I can tell, $eout indicates file handles with urgent data--not filehandles that have experienced an IO error. In other words, 'exceptional conditions' does not mean 'exceptions'.

5) You're right, I wasn't depopulating $fin (now $rin, to match standard), but at the top of the loop I reinitialized $fin and then set it up again by adding the listening socket and all currently open sockets. That should have taken care of initializing it correctly each time I get to the select.

You're right, I missed that. I chopped out that part of your code to fit it into my example. I'll have to add that back in and see if I can track down what's going on.

I also worked up an example using IO::Socket and I0::Select, which allows you to dispense with all the bit twiddling (which I loathe). The server code is greatly simplified:

#SERVER: use strict; use warnings; use 5.010; use IO::Socket; use IO::Select; my $LISTEN_SOCK = IO::Socket::INET->new( LocalPort => 12555, Listen => 5, Reuse => 1, ) or die "Couldn't create socket: $@"; my $sock_group = IO::Select->new() or die "Couldn't create select"; $sock_group->add($LISTEN_SOCK); warn "listening for connections...\n"; while (1) { my @ready_to_read = $sock_group->can_read; for my $READABLE_SOCK (@ready_to_read) { if ($READABLE_SOCK eq $LISTEN_SOCK) { my $NEW_CONNECTION = $LISTEN_SOCK->accept() or warn "Couldn't connect: $!"; if($NEW_CONNECTION) { $sock_group->add($NEW_CONNECTION); } } else { my $status = $READABLE_SOCK->sysread( my($available_data), + 8096 ); if ($status > 0) { #read some data STDOUT->syswrite($available_data); } elsif ($status == 0) { #read eof=>client closed socket $sock_group->remove($READABLE_SOCK); close $READABLE_SOCK; } else { #undef=>IO error warn "IO error while reading socket: $READABLE_SOCK"; } } } }
#CLIENT: (same as previous)