This code usually works like gangbusters, and I have no trouble processing multiple client streams at the same time. However, if the client is unexpectedly shut down, my code seems to just hang and won't accept any more connections or process data on any currently open connections. Originally, I didn't have the timeout of 5 seconds in the select, but I added it in for debug. And what I noticed is that once the client is killed, even the default timeout stops occurring. It's as if the select stops working altogether. I'm hoping some other eyes would shed light on what could be going wrong here. Any thoughts? Thanks much for your consideration.while (1) { # Set up bit vectors for polling my $fin = ''; my $fout; vec ($fin, fileno ($sock) , 1) = 1; foreach my $streamID (keys %openStreamsSock) { vec ($fin, fileno($openStreamsSock{$streamID}) , 1) = 1; } # Wait for incoming message my $nfound = select ($fout=$fin, undef, undef, 5); if ($nfound) { if (vec($fout, fileno($sock),1)) { $openStreamsSock($streamRequest++) = $sock->accept(); } else { foreach my $streamID (keys %openStreamsSock) { if (vec($fout, fileno($openStreamsSock{$streamID}),1)) { # read data off the socket; not a message here, just r +aw data $msgSize = sysread ($openStreamsSock{$streamID}, $msgReceived, 1048576); if (defined ($msgSize) && ($msgSize > 0)) { writeStreamData ($streamID, $msgReceived); } else { # $msgSize being 0 indicates end of stream, or # $msgSize being undef indicates error, so close close ($openStreamsSock{$streamID}); delete ($openStreamsSock{$streamID}); } } } } } else { print "$0: Normal timeout of select...\n"; } }
In reply to socket select hangs after client restarts by planetjeff
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |