X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FMsg.pm;h=6702f152bc6811334a8cf1f6661791f0d0a2c7b7;hb=f7d2c39f20734d48a5306ac585f1bbee2fc2fbe7;hp=fd6e3b17dde3d015848675ec3f033e49381af631;hpb=838a7345a2540d9707dacf2ff61431b214e4cdac;p=spider.git diff --git a/perl/Msg.pm b/perl/Msg.pm index fd6e3b17..6702f152 100644 --- a/perl/Msg.pm +++ b/perl/Msg.pm @@ -51,6 +51,7 @@ sub new state => 0, lineend => "\r\n", csort => 'telnet', + timeval => 60, }; return bless $conn, $class; @@ -61,20 +62,22 @@ sub new sub connect { my ($pkg, $to_host, $to_port, $rproc) = @_; + # Create a connection end-point object + my $conn = $pkg; + unless (ref $pkg) { + $conn = $pkg->new($rproc); + } + # Create a new internet socket my $sock = IO::Socket::INET->new ( PeerAddr => $to_host, PeerPort => $to_port, Proto => 'tcp', - Reuse => 1); + Reuse => 1, + Timeout => $conn->{timeval} / 2); return undef unless $sock; - # Create a connection end-point object - my $conn = $pkg; - unless (ref $pkg) { - $conn = $pkg->new($rproc); - } $conn->{sock} = $sock; if ($conn->{rproc}) { @@ -119,7 +122,7 @@ sub _send { my ($conn, $flush) = @_; my $sock = $conn->{sock}; return unless defined($sock); - my ($rq) = $conn->{outqueue}; + my $rq = $conn->{outqueue}; # If $flush is set, set the socket to blocking, and send all # messages in the queue - return only if there's an error @@ -245,9 +248,12 @@ sub _rcv { # Complement to _send if ($bytes_read > 0) { if ($msg =~ /\n/) { @lines = split /\r?\n/, $msg; - $lines[0] = '' unless @lines; - $lines[0] = $conn->{msg} . $lines[0] if exists $conn->{msg}; - push @lines, ' ' unless @lines; + if (@lines) { + $lines[0] = $conn->{msg} . $lines[0] if exists $conn->{msg}; + } else { + $lines[0] = $conn->{msg} if exists $conn->{msg}; + push @lines, '' unless @lines; + } if ($msg =~ /\n$/) { delete $conn->{msg}; } else {