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

Lukáš Hrázký lhrazky at redhat.com
Thu Feb 22 14:11:29 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?
+    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?
+
+    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);
 }
 
 static void read_command_from_device(void)
-- 
2.16.1



More information about the Spice-devel mailing list