[Spice-devel] [RFC PATCH spice-streaming-agent 2/2] Implement handling of error messages from the server

Frediano Ziglio fziglio at redhat.com
Thu Feb 22 17:13:48 UTC 2018


> 
> Signed-off-by: Lukáš Hrázký <lhrazky at redhat.com>
> ---
>  src/spice-streaming-agent.cpp | 18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-agent.cpp
> index b88225f..73baa48 100644
> --- a/src/spice-streaming-agent.cpp
> +++ b/src/spice-streaming-agent.cpp
> @@ -130,8 +130,22 @@ static void handle_stream_capabilities(uint32_t len)
>  
>  static void handle_stream_error(uint32_t len)
>  {
> -    // TODO read message and use it
> -    throw std::runtime_error("got an error message from server");
> +    const size_t MSG_SIZE = 256;
> +
> +    // TODO the message should have an upper size limit defined somewhere?

we don't specify in the protocol file.
syslog for different reason seems to limit to 1kb.
we can use that, server should not send a poem.

> +    if (len >= MSG_SIZE) {
> +        throw std::runtime_error("NotifyError message size " +
> std::to_string(len) +
> +                                 " is too long (longer than " +
> std::to_string(MSG_SIZE) + ")");
> +    }
> +
> +    uint8_t msg[MSG_SIZE];
> +    msg[len] = '\0'; // make sure to terminate the string - TODO is there a
> better way?

sounds good to me this termination code.

> +
> +    read_message(msg, len);
> +    StreamMsgNotifyError *error_msg = (StreamMsgNotifyError*) msg;
> +
> +    syslog(LOG_ERR, "Received NotifyError message from the client: %d -
> %s\n",
> +        error_msg->error_code, error_msg->msg);

messages are from the server, not client.

>  }
>  
>  static void read_command_from_device(void)

Frediano


More information about the Spice-devel mailing list