fix error message on disconnect from peer
[spider.git] / perl / Msg.pm
index 60906c5964df83b0e547cd28628caaafefdf149c..3fa0e6762166816f86d31ebaaf2d2849b45a5ef9 100644 (file)
@@ -234,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) {