X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FMsg.pm;h=f2881c8ff9a947932c926bb1c4f5a0cf9e57fac1;hb=b5b494bfe442d798ed1d9a05fc2c4f9e31f4aa11;hp=cdb72aa0e920e41433c8ab724d58b41c1719b8b1;hpb=f935566e70cd40345937910094a5fa3394a58dc1;p=spider.git diff --git a/perl/Msg.pm b/perl/Msg.pm index cdb72aa0..f2881c8f 100644 --- a/perl/Msg.pm +++ b/perl/Msg.pm @@ -208,10 +208,6 @@ sub disconnect { $call ||= 'unallocated'; dbg("Connection $conn->{cnum} $call disconnected") if isdbg('connll'); - unless ($main::is_win) { - kill 'TERM', $conn->{pid} if exists $conn->{pid}; - } - # get rid of any references for (keys %$conn) { if (ref($conn->{$_})) { @@ -219,10 +215,16 @@ sub disconnect { } } - return unless defined($sock); - set_event_handler ($sock, read => undef, write => undef, error => undef); - shutdown($sock, 3); - close($sock); + if (defined($sock)) { + set_event_handler ($sock, read => undef, write => undef, error => undef); + shutdown($sock, 3); + close($sock); + } + + unless ($main::is_win) { + kill 'TERM', $conn->{pid} if exists $conn->{pid}; + } + } sub send_now { @@ -354,6 +356,22 @@ sub new_server { return $self; } +sub nolinger +{ + my $conn = shift; + 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 { my $conn = shift; @@ -436,6 +454,7 @@ sub new_client { my $conn = $server_conn->new($server_conn->{rproc}); $conn->{sock} = $sock; blocking($sock, 0); + $conn->nolinger; $conn->{blocking} = 0; my ($rproc, $eproc) = &{$server_conn->{rproc}} ($conn, $conn->{peerhost} = $sock->peerhost(), $conn->{peerport} = $sock->peerport()); $conn->{sort} = 'Incoming';