qmp_read_avail : reworks

qmp response could me more than 1 json.

we can have 1 json with event info, and 1 json with return infos.

We die if we receive an error message in response.

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
This commit is contained in:
Alexandre Derumier 2012-06-25 10:02:45 +02:00 committed by Dietmar Maurer
parent 35cb731c42
commit f667373f27

View File

@ -2702,8 +2702,20 @@ my $qmp_read_avail = sub {
} }
die "qmp read timeout\n" if !scalar(@ready); die "qmp read timeout\n" if !scalar(@ready);
my $obj = from_json($res);
return $obj; my @jsons = split("\n", $res);
my $obj = {};
my $event = {};
my $return = {};
foreach my $json (@jsons) {
$obj = from_json($json);
$event = $obj->{event} if exists $obj->{event};
$return = $obj->{QMP} if exists $obj->{QMP};
$return = $obj->{"return"} if exists $obj->{"return"};
die $obj->{error}->{desc} if exists $obj->{error}->{desc} && $obj->{error}->{desc} !~ m/Connection can not be completed immediately/;
}
return ($return,$event);
}; };
sub __read_avail { sub __read_avail {