add KEEPALIVE to TCP connections
[spider.git] / perl / Msg.pm
index 15dc26d4ff29fe85e0b56ec665655babb284c256..f2881c8ff9a947932c926bb1c4f5a0cf9e57fac1 100644 (file)
@@ -359,7 +359,17 @@ sub new_server {
 sub nolinger
 {
        my $conn = shift;
-       setsockopt($conn->{sock}, SOL_SOCKET, SO_LINGER, pack("ll", 0, 0)) or confess "setsockopt: $!";
+       my $buf;
+       if (isdbg('sock') && ($buf = getsockopt($conn->{sock}, SOL_SOCKET, SO_LINGER))) {
+               my ($l, $t) = unpack("ll", $buf);
+               dbg("Linger is: $buf = $l $t");
+       }
+       setsockopt($conn->{sock}, SOL_SOCKET, SO_LINGER, pack("ll", 0, 0)) or confess "setsockopt linger: $!";
+       setsockopt($conn->{sock}, SOL_SOCKET, SO_KEEPALIVE, 1) or confess "setsockopt keepalive: $!";
+       if (isdbg('sock') && ($buf = getsockopt($conn->{sock}, SOL_SOCKET, SO_LINGER))) {
+               my ($l, $t) = unpack("ll", $buf);
+               dbg("Linger is: $buf = $l $t");
+       }
 }
 
 sub dequeue