Fix error 'send: Cannot determine peer address'

This commit is contained in:
Quentin Garnier 2013-12-03 16:36:28 +01:00
parent 65506b29f8
commit d920c1fca9
2 changed files with 20 additions and 10 deletions

View File

@ -528,10 +528,7 @@ sub run {
$self->{logger}->writeLogInfo("response = $data_element"); $self->{logger}->writeLogInfo("response = $data_element");
$data_element =~ s/^.*?\|//; $data_element =~ s/^.*?\|//;
${$self->{sockets}->{$id}->{obj}}->send($data_element . "\n"); centreon::esxd::common::response_client2($self, $id, $data_element . "\n");
$self->{read_select}->remove(${$self->{sockets}->{$id}->{obj}});
close ${$self->{sockets}->{$id}->{obj}};
delete $self->{sockets}->{$id};
} else { } else {
# Socket # Socket
my $line = <$rh>; my $line = <$rh>;
@ -570,10 +567,7 @@ sub run {
foreach (keys %{$self->{sockets}}) { foreach (keys %{$self->{sockets}}) {
if (time() - $self->{sockets}->{$_}->{ctime} > $self->{centreonesxd_config}->{timeout}) { if (time() - $self->{sockets}->{$_}->{ctime} > $self->{centreonesxd_config}->{timeout}) {
$self->{logger}->writeLogInfo("Timeout returns."); $self->{logger}->writeLogInfo("Timeout returns.");
${$self->{sockets}->{$_}->{obj}}->send("3|TIMEOUT\n"); centreon::esxd::common::response_client2($self, $_, "3|TIMEOUT\n");
$self->{read_select}->remove(${$self->{sockets}->{$_}->{obj}});
close ${$self->{sockets}->{$_}->{obj}};
delete $self->{sockets}->{$_};
} }
} }
} }

View File

@ -24,12 +24,28 @@ sub get_status {
return $ERRORS{$MYERRORS{$state}}; return $ERRORS{$MYERRORS{$state}};
} }
sub response_client2 {
my ($obj_esxd, $id, $msg) = @_;
# Avoid croak kill. Can be happened (not often)
eval {
${$obj_esxd->{sockets}->{$id}->{obj}}->send($msg);
};
$obj_esxd->{read_select}->remove(${$obj_esxd->{sockets}->{$id}->{obj}});
close ${$obj_esxd->{sockets}->{$id}->{obj}};
delete $obj_esxd->{sockets}->{$id};
}
sub response_client1 { sub response_client1 {
my ($obj_esxd, $rh, $current_fileno, $msg) = @_; my ($obj_esxd, $rh, $current_fileno, $msg) = @_;
$rh->send($msg);
delete $obj_esxd->{sockets}->{$current_fileno}; # Avoid croak kill. Can be happened (not often)
eval {
$rh->send($msg);
};
$obj_esxd->{read_select}->remove($rh); $obj_esxd->{read_select}->remove($rh);
close $rh; close $rh;
delete $obj_esxd->{sockets}->{$current_fileno};
} }
sub vmware_error { sub vmware_error {