+ change some zmq api functions

This commit is contained in:
garnier-quentin 2016-08-02 11:14:59 +02:00
parent 8c0e916d50
commit 326e133e2c
3 changed files with 40 additions and 14 deletions

View File

@ -363,9 +363,14 @@ sub request_dynamic {
identity => $options{identity}) == 0);
$self->{centreon_vmware_config}->{vsphere_server}->{$container}->{last_request} = time();
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
zmq_sendmsg($frontend, "server-" . $container, $flag);
zmq_sendmsg($frontend, 'REQCLIENT ' . $options{data}, ZMQ_NOBLOCK);
my $msg = zmq_msg_init_data("server-" . $container);
zmq_msg_send($msg, $frontend, $flag);
zmq_msg_close($msg);
$msg = zmq_msg_init_data('REQCLIENT ' . $options{data});
zmq_msg_send($msg, $frontend, ZMQ_NOBLOCK);
zmq_msg_close($msg);
}
sub request {
@ -417,9 +422,14 @@ sub request {
identity => $options{identity}) == 0);
$self->{counter_stats}->{$result->{container}}++;
my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE;
zmq_sendmsg($frontend, "server-" . $result->{container}, $flag);
zmq_sendmsg($frontend, 'REQCLIENT ' . $options{data}, ZMQ_NOBLOCK);
my $msg = zmq_msg_init_data("server-" . $result->{container});
zmq_msg_send($msg, $frontend, $flag);
zmq_msg_close($msg);
$msg = zmq_msg_init_data('REQCLIENT ' . $options{data});
zmq_msg_send($msg, $frontend, ZMQ_NOBLOCK);
zmq_msg_close($msg);
}
sub repserver {
@ -445,11 +455,15 @@ sub repserver {
sub router_event {
while (1) {
# Process all parts of the message
my $message = zmq_recvmsg($frontend);
my $identity = zmq_msg_data($message);
$message = zmq_recvmsg($frontend);
my $data = zmq_msg_data($message);
my $msg = zmq_msg_init();
zmq_msg_recv($msg, $frontend, ZMQ_DONTWAIT);
my $identity = zmq_msg_data($msg);
zmq_msg_close($msg);
$msg = zmq_msg_init();
zmq_msg_recv($msg, $frontend, ZMQ_DONTWAIT);
my $data = zmq_msg_data($msg);
zmq_msg_close($msg);
my $manager = centreon::vmware::common::init_response();
if ($centreon_vmware->{stop} != 0) {
@ -466,6 +480,7 @@ sub router_event {
$centreon_vmware->{centreon_vmware_config}->{vsphere_server}->{$1}->{ready} = 1;
}
centreon::vmware::common::free_response();
my $more = zmq_getsockopt($frontend, ZMQ_RCVMORE);
last unless $more;
}

View File

@ -40,6 +40,10 @@ sub init_response {
return $manager_display;
}
sub free_response {
$manager_display = {};
}
sub response {
my (%options) = @_;
@ -62,9 +66,13 @@ sub response {
zmq_setsockopt($options{endpoint}, ZMQ_LINGER, 10000);
}
if (defined($options{identity})) {
zmq_sendmsg($options{endpoint}, $options{identity}, $flag);
my $msg = zmq_msg_init_data($options{identity});
zmq_msg_send($msg, $options{endpoint}, $flag);
zmq_msg_close($msg);
}
zmq_sendmsg($options{endpoint}, $options{token} . " " . $stdout, ZMQ_NOBLOCK);
my $msg = zmq_msg_init_data($options{token} . " " . $stdout);
zmq_msg_send($msg, $options{endpoint}, ZMQ_NOBLOCK);
zmq_msg_close($msg);
}
sub vmware_error {

View File

@ -130,6 +130,7 @@ sub response_router {
short_msg => $options{msg});
$manager->{output}->{plugin} = $options{identity};
centreon::vmware::common::response(token => 'RESPSERVER2', endpoint => $backend);
centreon::vmware::common::free_response();
}
sub verify_child {
@ -198,12 +199,14 @@ sub reqclient {
sub vsphere_event {
while (1) {
# Process all parts of the message
my $message = zmq_recvmsg($backend);
if (!defined($message)) {
my $msg = zmq_msg_init();
my $rv = zmq_msg_recv($msg, $backend, undef);
if ($rv == -1) {
$connector->{logger}->writeLogError("zmq_recvmsg error: $!");
last;
}
my $data = zmq_msg_data($message);
my $data = zmq_msg_data($msg);
zmq_msg_close($msg);
if ($data =~ /^REQCLIENT\s+(.*)$/msi) {
$connector->reqclient(data => $1);