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

Submitted by Christophe de Dinechin on Feb. 21, 2018, 5:46 p.m.

Details

Message ID 20180221174636.37758-21-christophe@dinechin.org
State New
Headers show
Series "WIP: Refactor the streaming agent towards a more standard C++ style" ( rev: 2 ) in Spice

Not browsing as part of any series.

Commit Message

Christophe de Dinechin Feb. 21, 2018, 5:46 p.m.
From: Christophe de Dinechin <dinechin@redhat.com>

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

Patch hide | download patch | download mbox

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;
     }