X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FMsg.pm;h=f2881c8ff9a947932c926bb1c4f5a0cf9e57fac1;hb=b5b494bfe442d798ed1d9a05fc2c4f9e31f4aa11;hp=333693b73a2e65d2ef89d0a620e4b4da9133befa;hpb=55f3823f3ad86d76e1e995b0f255f1804684de18;p=spider.git diff --git a/perl/Msg.pm b/perl/Msg.pm index 333693b7..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 { @@ -348,13 +350,28 @@ sub new_server { # LocalPort => $my_port, Listen => SOMAXCONN, Proto => 'tcp', - ReuseAddr => 1, - ); + Reuse => 1); die "Could not create socket: $! \n" unless $self->{sock}; set_event_handler ($self->{sock}, read => sub { $self->new_client } ); 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; @@ -437,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';