sub setnonblocking { my $sock = shift; # Get the current state of the socket.. my $flags = fcntl($sock, F_GETFL, 0) or die "Can't get the flags on socket: $!\n"; # ..and then add O_NONBLOCK (nonblocking-ness) on to it. fcntl($sock, F_SETFL, $flags | O_NONBLOCK) or die "Can't set socket non-blocking: $!\n"; }