fix error message on disconnect from peer
[spider.git] / perl / Msg.pm
index 352904102e32cf35d183ffcd1395e42f5c9c87a0..3fa0e6762166816f86d31ebaaf2d2849b45a5ef9 100644 (file)
@@ -61,11 +61,12 @@ sub set_error
        $conn->{eproc} = $callback;
 }
 
-sub set_eof
+sub set_on_eof
 {
        my $conn = shift;
        my $callback = shift;
-       $conn->{sock}->on_eof(sub {$callback});
+       $conn->{sock}->on_eof($callback);
+       $conn->{sock}->on_error($callback);
 }
 
 sub set_rproc
@@ -233,9 +234,14 @@ sub disconnect
                }
        }
 
-       if (defined($sock)) {
+       if (ref $sock && $sock->isa('AnyEvent::Handle') && exists $sock->{fh}) {
                shutdown($sock->{fh}, 2);
                $sock->destroy;
+       } else {
+               my $s;
+               $s = "already destroyed" unless exists $sock->{fh};
+               $s ||= ref $sock || $sock || "undefined";
+               dbg("Msg::disconnect trying to disconnect a $s socket") if isdbg('chan');
        }
        
        unless ($main::is_win) {