qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [RFC 03/18] qmp.py: Cleanly handle unexpectedly closed


From: Philippe Mathieu-Daudé
Subject: Re: [Qemu-devel] [RFC 03/18] qmp.py: Cleanly handle unexpectedly closed socket
Date: Wed, 4 Apr 2018 05:26:26 -0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

On 03/29/2018 06:38 PM, Eduardo Habkost wrote:
> QEMUMonitorProtocol.cmd() returns None if the socket was closed,
> so callers must handle this case explicltly.
> 
> Signed-off-by: Eduardo Habkost <address@hidden>

Reviewed-by: Philippe Mathieu-Daudé <address@hidden>

> ---
>  scripts/qmp/qmp.py | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/scripts/qmp/qmp.py b/scripts/qmp/qmp.py
> index e9cb6b2683..91b537ea04 100644
> --- a/scripts/qmp/qmp.py
> +++ b/scripts/qmp/qmp.py
> @@ -73,6 +73,8 @@ class QEMUMonitorProtocol(object):
>              raise QMPConnectError
>          # Greeting seems ok, negotiate capabilities
>          resp = self.cmd('qmp_capabilities')
> +        if resp is None:
> +            raise QMPConnectError("QMP connection unexpectedly closed")
>          if "return" in resp:
>              return greeting
>          raise QMPCapabilitiesError
> @@ -182,6 +184,8 @@ class QEMUMonitorProtocol(object):
>          @param name: command name (string)
>          @param args: command arguments (dict)
>          @param cmd_id: command id (dict, list, string or int)
> +        @return QMP response as a Python dict or None if the connection has
> +                been closed
>          """
>          qmp_cmd = {'execute': name}
>          if args:
> @@ -195,6 +199,8 @@ class QEMUMonitorProtocol(object):
>          Build and send a QMP command to the monitor, report errors if any
>          """
>          ret = self.cmd(cmd, kwds)
> +        if ret is None:
> +            raise QMPConnectError("QMP connection unexpectedly closed")
>          if "error" in ret:
>              raise Exception(ret['error']['desc'])
>          return ret['return']
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]