Patchwork [v3,16/17] QMP: Fix python helper /wrt long return strings

login
register
mail settings
Submitter Jan Kiszka
Date May 23, 2010, 10:59 a.m.
Message ID <834d0bba21d14e502c1f7274eb244ed3b682ae1d.1274612367.git.jan.kiszka@web.de>
Download mbox | patch
Permalink /patch/53321/
State New
Headers show

Comments

Jan Kiszka - May 23, 2010, 10:59 a.m.
From: Jan Kiszka <jan.kiszka@siemens.com>

Remove the arbitrary limitation of 1024 characters per return string and
read complete lines instead. Required for device_show.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 QMP/qmp.py |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
Luiz Capitulino - May 27, 2010, 8:35 p.m.
On Sun, 23 May 2010 12:59:29 +0200
Jan Kiszka <jan.kiszka@web.de> wrote:

> From: Jan Kiszka <jan.kiszka@siemens.com>
> 
> Remove the arbitrary limitation of 1024 characters per return string and
> read complete lines instead. Required for device_show.

 Thanks for both fixes, I have started working on a better version of this
script that mimics better the user monitor but it's only half done.

> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>  QMP/qmp.py |    6 +++++-
>  1 files changed, 5 insertions(+), 1 deletions(-)
> 
> diff --git a/QMP/qmp.py b/QMP/qmp.py
> index d9da603..4062f84 100644
> --- a/QMP/qmp.py
> +++ b/QMP/qmp.py
> @@ -63,10 +63,14 @@ class QEMUMonitorProtocol:
>  
>      def __json_read(self):
>          try:
> -            return json.loads(self.sock.recv(1024))
> +            while True:
> +                line = json.loads(self.sockfile.readline())
> +                if not 'event' in line:
> +                    return line
>          except ValueError:
>              return
>  
>      def __init__(self, filename):
>          self.filename = filename
>          self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
> +        self.sockfile = self.sock.makefile()

Patch

diff --git a/QMP/qmp.py b/QMP/qmp.py
index d9da603..4062f84 100644
--- a/QMP/qmp.py
+++ b/QMP/qmp.py
@@ -63,10 +63,14 @@  class QEMUMonitorProtocol:
 
     def __json_read(self):
         try:
-            return json.loads(self.sock.recv(1024))
+            while True:
+                line = json.loads(self.sockfile.readline())
+                if not 'event' in line:
+                    return line
         except ValueError:
             return
 
     def __init__(self, filename):
         self.filename = filename
         self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+        self.sockfile = self.sock.makefile()