You should take a look at perldoc perlio and perldoc IO::Socket .
There are many ways to build with non-blocking IOs, from the PIPE signal to recv , which you could use (depending on what you are doing):
return "Socket is closed" unless $sock->connected;
This is how I controlled a lot of sockets to serve them with select . When the socket is closed, I have to remove them from the list (nothing else, as if to disconnect, the socket no longer exists, so there is no need to close them):
unless (eval {$group{$grp}->{'socket'}->connected}) { delete $group{$grp}->{'socket'}; return 0; };
eval prevents a bad attempt to disconnect a socket, which will terminate your script with an io socket error.
Hope this helps!
source share