X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FMsg.pm;h=ceace3ca774c62603b22f2ab8577f8907c4af5f4;hb=0bca43685143e42a93bdcdaa9e34e115b22552e9;hp=d3817bedbd5fa8704aa9ce7bc062f22f62fd6f45;hpb=3c2ea668af700128a081cc7c17ca93cc685fad37;p=spider.git diff --git a/perl/Msg.pm b/perl/Msg.pm index d3817bed..ceace3ca 100644 --- a/perl/Msg.pm +++ b/perl/Msg.pm @@ -123,7 +123,7 @@ sub new $noconns++; - dbg("Connection created ($noconns)") if isdbg('connll'); + dbg("$class Connection $conn->{cnum} created (total $noconns)") if isdbg('connll'); return bless $conn, $class; } @@ -170,11 +170,11 @@ sub conns if (ref $pkg) { $call = $pkg->{call} unless $call; return undef unless $call; - dbg("changing $pkg->{call} to $call") if isdbg('connll') && exists $pkg->{call} && $call ne $pkg->{call}; + dbg((ref $pkg) . " changing $pkg->{call} to $call") if isdbg('connll') && exists $pkg->{call} && $call ne $pkg->{call}; delete $conns{$pkg->{call}} if exists $pkg->{call} && exists $conns{$pkg->{call}} && $pkg->{call} ne $call; $pkg->{call} = $call; $ref = $conns{$call} = $pkg; - dbg("Connection $pkg->{cnum} $call stored") if isdbg('connll'); + dbg((ref $pkg) . " Connection $pkg->{cnum} $call stored") if isdbg('connll'); } else { $ref = $conns{$call}; } @@ -205,6 +205,7 @@ sub peerhost $conn->{peerhost} ||= 'ax25' if $conn->ax25; $conn->{peerhost} ||= $conn->{sock}->peerhost if $conn->{sock} && $conn->{sock}->isa('IO::Socket::INET'); $conn->{peerhost} ||= 'UNKNOWN'; + $conn->{peerhost} =~ s/^::ffff://; return $conn->{peerhost}; } @@ -221,6 +222,8 @@ sub connect { $conn->{peerhost} = $to_host; $conn->{peerport} = $to_port; $conn->{sort} = 'Outgoing'; + + dbg((ref $conn) . " connecting $conn->{cnum} to $to_host:$to_port") if isdbg('connll'); my $sock; if ($blocking_supported) { @@ -245,7 +248,9 @@ sub connect { } $conn->{sock} = $sock; - $conn->{peerhost} = $sock->peerhost; # for consistency +# $conn->{peerhost} = $sock->peerhost; # for consistency + + dbg((ref $conn) . " connected $conn->{cnum} to $to_host:$to_port") if isdbg('connll'); if ($conn->{rproc}) { my $callback = sub {$conn->_rcv}; @@ -320,7 +325,7 @@ sub disconnect delete $conns{$call} if $ref && $ref == $conn; } $call ||= 'unallocated'; - dbg("Connection $conn->{cnum} $call disconnected") if isdbg('connll'); + dbg((ref $conn) . " Connection $conn->{cnum} $call disconnected") if isdbg('connll'); # get rid of any references for (keys %$conn) { @@ -460,8 +465,8 @@ sub new_server { my $self = $pkg->new($login_proc); $self->{sock} = $io_socket->new ( - LocalAddr => "$my_host:$my_port", -# LocalPort => $my_port, + LocalAddr => $my_host, + LocalPort => $my_port, Listen => SOMAXCONN, Proto => 'tcp', Reuse => 1); @@ -500,15 +505,17 @@ sub nolinger sub dequeue { my $conn = shift; - - if ($conn->{msg} =~ /\n/) { - my @lines = split /\r?\n/, $conn->{msg}; - if ($conn->{msg} =~ /\n$/) { + return if $conn->{disconnecting}; + + if ($conn->{msg} =~ /\cJ/) { + my @lines = split /\cM?\cJ/, $conn->{msg}; + if ($conn->{msg} =~ /\cM?\cJ$/) { delete $conn->{msg}; } else { $conn->{msg} = pop @lines; } for (@lines) { + last if $conn->{disconnecting}; &{$conn->{rproc}}($conn, defined $_ ? $_ : ''); } } @@ -717,8 +724,8 @@ sub DESTROY my $call = $conn->{call} || 'unallocated'; my $host = $conn->{peerhost} || ''; my $port = $conn->{peerport} || ''; - dbg("Connection $conn->{cnum} $call [$host $port] being destroyed") if isdbg('connll'); $noconns--; + dbg((ref $conn) . " Connection $conn->{cnum} $call [$host $port] being destroyed (total $noconns)") if isdbg('connll'); } 1;