[Spice-commits] 2 commits - src/spice-channel.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Aug 12 12:22:57 UTC 2020


 src/spice-channel.c |   24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

New commits:
commit 2dc26823d229e670f3f35e5204660d6e72e51a55
Author: Frediano Ziglio <freddy77 at gmail.com>
Date:   Wed Aug 12 11:48:57 2020 +0100

    spice-channel: Compute correct network wait condition after SSL_connect error
    
    Do not pass always G_IO_OUT. In case SSL_connect is waiting for
    data and error was SSL_ERROR_WANT_READ instead of SSL_ERROR_WANT_WRITE
    this was creating a tight loop repeatedly calling SSL_connect till
    data arrived.
    Note that G_IO_ERR and G_IO_HUP are always detected so no need to
    add them.
    
    Signed-off-by: Frediano Ziglio <freddy77 at gmail.com>

diff --git a/src/spice-channel.c b/src/spice-channel.c
index d5e2911..217a83f 100644
--- a/src/spice-channel.c
+++ b/src/spice-channel.c
@@ -2636,7 +2636,7 @@ ssl_reconnect:
         if (rc <= 0) {
             rc = SSL_get_error(c->ssl, rc);
             if (rc == SSL_ERROR_WANT_READ || rc == SSL_ERROR_WANT_WRITE) {
-                g_coroutine_socket_wait(&c->coroutine, c->sock, G_IO_OUT|G_IO_ERR|G_IO_HUP);
+                g_coroutine_socket_wait(&c->coroutine, c->sock, ssl_error_to_cond(rc));
                 goto ssl_reconnect;
             } else {
                 g_warning("%s: SSL_connect: %s",
commit 5042a8e1c833e847c130f5aa3d85171e9e363333
Author: Frediano Ziglio <freddy77 at gmail.com>
Date:   Wed Aug 12 11:45:58 2020 +0100

    spice-channel: Factor out a function to compute GIOCondition from OpenSSL error
    
    Code was duplicate in 2 places.
    The or operation ("|") was not necessary as condition was reset to
    0 some lines above in both functions.
    
    Signed-off-by: Frediano Ziglio <freddy77 at gmail.com>

diff --git a/src/spice-channel.c b/src/spice-channel.c
index 2988296..d5e2911 100644
--- a/src/spice-channel.c
+++ b/src/spice-channel.c
@@ -760,6 +760,18 @@ void spice_msg_out_send_internal(SpiceMsgOut *out)
     spice_channel_write_msg(out->channel, out);
 }
 
+static inline GIOCondition
+ssl_error_to_cond(int ssl_error)
+{
+    if (ssl_error == SSL_ERROR_WANT_READ) {
+        return G_IO_IN;
+    }
+    if (ssl_error == SSL_ERROR_WANT_WRITE) {
+        return G_IO_OUT;
+    }
+    return 0;
+}
+
 /*
  * Helper function to deal with the nonblocking part of _flush_wire() function.
  * It returns the result of the write and will set the proper bits in @cond in
@@ -783,10 +795,7 @@ static gint spice_channel_flush_wire_nonblocking(SpiceChannel *channel,
         ret = SSL_write(c->ssl, ptr, len);
         if (ret < 0) {
             ret = SSL_get_error(c->ssl, ret);
-            if (ret == SSL_ERROR_WANT_READ)
-                *cond |= G_IO_IN;
-            if (ret == SSL_ERROR_WANT_WRITE)
-                *cond |= G_IO_OUT;
+            *cond = ssl_error_to_cond(ret);
             ret = -1;
         }
     } else {
@@ -1007,10 +1016,7 @@ static int spice_channel_read_wire_nonblocking(SpiceChannel *channel,
         ret = SSL_read(c->ssl, data, len);
         if (ret < 0) {
             ret = SSL_get_error(c->ssl, ret);
-            if (ret == SSL_ERROR_WANT_READ)
-                *cond |= G_IO_IN;
-            if (ret == SSL_ERROR_WANT_WRITE)
-                *cond |= G_IO_OUT;
+            *cond = ssl_error_to_cond(ret);
             ret = -1;
         }
     } else {


More information about the Spice-commits mailing list