aboutsummaryrefslogtreecommitdiff
path: root/QMP
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-10-18 16:49:29 +0200
committerKevin Wolf <kwolf@redhat.com>2012-10-24 10:26:22 +0200
commit9eb80eadd498fae2ad9eecbb89646b0cc4929cac (patch)
treeac36c81095422ecbbf9b6656c8cc9b12fd12b2bc /QMP
parentb952b5589a36114e06201c0d2e82c293dbad2b1f (diff)
downloadqemu-9eb80eadd498fae2ad9eecbb89646b0cc4929cac.zip
qemu-9eb80eadd498fae2ad9eecbb89646b0cc4929cac.tar.gz
qemu-9eb80eadd498fae2ad9eecbb89646b0cc4929cac.tar.bz2
qmp: add pull_event function
This function is unlike get_events in that it makes it easy to process one event at a time. This is useful in the mirroring test cases, where we want to process just one event (BLOCK_JOB_ERROR) and leave the others to a helper function. Acked-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'QMP')
-rw-r--r--QMP/qmp.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/QMP/qmp.py b/QMP/qmp.py
index 32510a1..c551df1 100644
--- a/QMP/qmp.py
+++ b/QMP/qmp.py
@@ -136,6 +136,26 @@ class QEMUMonitorProtocol:
raise Exception(ret['error']['desc'])
return ret['return']
+ def pull_event(self, wait=False):
+ """
+ Get and delete the first available QMP event.
+
+ @param wait: block until an event is available (bool)
+ """
+ self.__sock.setblocking(0)
+ try:
+ self.__json_read()
+ except socket.error, err:
+ if err[0] == errno.EAGAIN:
+ # No data available
+ pass
+ self.__sock.setblocking(1)
+ if not self.__events and wait:
+ self.__json_read(only_event=True)
+ event = self.__events[0]
+ del self.__events[0]
+ return event
+
def get_events(self, wait=False):
"""
Get a list of available QMP events.