[Spice-devel] [PATCH v2 20/24] Throw an exception in case we can't write a complete packet.

Christophe de Dinechin christophe at dinechin.org
Wed Feb 21 17:46:32 UTC 2018


From: Christophe de Dinechin <dinechin at redhat.com>

Signed-off-by: Christophe de Dinechin <dinechin at redhat.com>
---
 src/spice-streaming-agent.cpp | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-agent.cpp
index 4e3a21c..61a73ce 100644
--- a/src/spice-streaming-agent.cpp
+++ b/src/spice-streaming-agent.cpp
@@ -62,6 +62,13 @@ class Stream
     typedef std::set<SpiceVideoCodecType> codecs_t;
 
 public:
+    class WriteError : public std::runtime_error
+    {
+    public:
+        WriteError(const char *msg): runtime_error(msg) {}
+    };
+
+public:
     Stream(const char *name)
         : codecs()
     {
@@ -92,8 +99,10 @@ public:
         size_t expected = message.size(payload...);
         size_t written = message.write(*this, payload...);
         bool result = written == expected;
-        if (!result)
-            syslog(LOG_WARNING, "sent only %zu bytes out of %zu", written, expected);
+        if (!result) {
+            syslog(LOG_ERR, "sent only %zu bytes out of %zu", written, expected);
+            throw WriteError("Unable to write complete packet");
+        }
         return result;
     }
 
-- 
2.13.5 (Apple Git-94)



More information about the Spice-devel mailing list