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

Frediano Ziglio fziglio at redhat.com
Tue Feb 16 15:36:25 UTC 2016


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 140b767..b630e12 100644
--- a/server/reds-stream.c
+++ b/server/reds-stream.c
@@ -209,6 +209,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 1123048..d439fe1 100644
--- a/server/reds-stream.h
+++ b/server/reds-stream.h
@@ -77,6 +77,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.5.0



More information about the Spice-devel mailing list