[Spice-devel] [PATCH spice-server 1/3] stream: implement interface for manual flush

Frediano Ziglio fziglio at redhat.com
Fri Feb 10 12:10:54 UTC 2017


The writing to network was always immediate.
Every write in the stream cause a write to the OS.
Can this have some penalty if you don't write large data as network
packets can be more fragmented or you encrypt data is smaller chunks
(when data are encrypted some padding is added then data is split in
multiple of encryption block which is usually the size of encryption
key and this is done for every write).

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/reds-stream.c |  9 +++++++++
 server/reds-stream.h | 20 ++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/server/reds-stream.c b/server/reds-stream.c
index d0dadb9..67968f9 100644
--- a/server/reds-stream.c
+++ b/server/reds-stream.c
@@ -210,6 +210,15 @@ bool reds_stream_write_all(RedsStream *stream, const void *in_buf, size_t n)
     return TRUE;
 }
 
+bool reds_stream_set_auto_flush(RedsStream *s, bool enable)
+{
+    return false;
+}
+
+void reds_stream_flush(RedsStream *s)
+{
+}
+
 #if HAVE_SASL
 static ssize_t reds_stream_sasl_write(RedsStream *s, const void *buf, size_t nbyte);
 #endif
diff --git a/server/reds-stream.h b/server/reds-stream.h
index a8d1736..c1c0da9 100644
--- a/server/reds-stream.h
+++ b/server/reds-stream.h
@@ -76,6 +76,26 @@ int reds_stream_get_family(const RedsStream *stream);
 int reds_stream_is_plain_unix(const RedsStream *stream);
 int reds_stream_send_msgfd(RedsStream *stream, int fd);
 
+/**
+ * Set auto flush flags.
+ * If set stream will send data to the underlying socket as
+ * soon as data are written. This is the default.
+ * If not set you should call reds_stream_flush to force
+ * data to be sent. Failing to call reds_stream_flush on a
+ * manual flush stream could lead to latency.
+ * Disabling auto flush can fail while enabling cannot.
+ *
+ * Returns true if success or false on failure.
+ */
+bool reds_stream_set_auto_flush(RedsStream *stream, bool enable);
+
+/**
+ * Flush data to the underlying socket.
+ * Calling this function on a stream with auto flush set has
+ * no result.
+ */
+void reds_stream_flush(RedsStream *stream);
+
 typedef enum {
     REDS_SASL_ERROR_OK,
     REDS_SASL_ERROR_GENERIC,
-- 
2.9.3



More information about the Spice-devel mailing list