[Spice-devel] [PATCH 06/13] server/reds: make writev fallback more generic

Marc-André Lureau marcandre.lureau at redhat.com
Tue Feb 22 08:09:00 PST 2011


We are going to reuse it for SASL/SSF encode write().
---
 server/reds.c |   38 ++++++++++++++++----------------------
 1 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/server/reds.c b/server/reds.c
index 2aefe31..c07b840 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -356,26 +356,6 @@ static ssize_t stream_ssl_read_cb(RedsStream *s, void *buf, size_t size)
     return return_code;
 }
 
-static ssize_t stream_ssl_writev_cb(RedsStream *s, const struct iovec *vector, int count)
-{
-    int i;
-    int n;
-    ssize_t ret = 0;
-    int ssl_error;
-
-    for (i = 0; i < count; ++i) {
-        n = SSL_write(s->ssl, vector[i].iov_base, vector[i].iov_len);
-        if (n <= 0) {
-            ssl_error = SSL_get_error(s->ssl, n);
-            ssl_error_eagain(ssl_error); /* just to be sure we have EAGAIN */
-            return ret == 0 ? n : ret;
-        } else
-            ret += n;
-    }
-
-    return ret;
-}
-
 static void reds_stream_remove_watch(RedsStream* s)
 {
     if (s->watch) {
@@ -1920,7 +1900,7 @@ static void reds_accept_ssl_connection(int fd, int event, void *data)
 
     link->stream->write = stream_ssl_write_cb;
     link->stream->read = stream_ssl_read_cb;
-    link->stream->writev = stream_ssl_writev_cb;
+    link->stream->writev = NULL;
 
     return_code = SSL_accept(link->stream->ssl);
     if (return_code == 1) {
@@ -3166,7 +3146,21 @@ ssize_t reds_stream_write(RedsStream *s, const void *buf, size_t nbyte)
 
 ssize_t reds_stream_writev(RedsStream *s, const struct iovec *iov, int iovcnt)
 {
-    return s->writev(s, iov, iovcnt);
+    int i;
+    int n;
+    ssize_t ret = 0;
+
+    if (s->writev != NULL)
+        return s->writev(s, iov, iovcnt);
+
+    for (i = 0; i < iovcnt; ++i) {
+        n = reds_stream_write(s, iov[i].iov_base, iov[i].iov_len);
+        if (n <= 0)
+            return ret == 0 ? n : ret;
+        ret += n;
+    }
+
+    return ret;
 }
 
 void reds_stream_free(RedsStream *s)
-- 
1.7.4



More information about the Spice-devel mailing list