if($ssh2->connect($dest, $port)) { my $sock = $ssh2->sock; setsockopt($sock, SOL_SOCKET, SO_KEEPALIVE, 1) or die "fatal: cant set socket in SO_KEEPALIVE mode $!"; ... }