[Spice-devel] [PATCH spice-gtk 1/9] channel: delay event report to after coroutine exit

Marc-André Lureau marcandre.lureau at redhat.com
Tue Jan 13 08:38:20 PST 2015


Move to a common place error reporting, after the coroutine exits.
---
 gtk/spice-channel-priv.h |  3 ++-
 gtk/spice-channel.c      | 25 +++++++++++++------------
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/gtk/spice-channel-priv.h b/gtk/spice-channel-priv.h
index bd7f490..d70cf86 100644
--- a/gtk/spice-channel-priv.h
+++ b/gtk/spice-channel-priv.h
@@ -66,7 +66,6 @@ struct _SpiceMsgIn {
 
 enum spice_channel_state {
     SPICE_CHANNEL_STATE_UNCONNECTED = 0,
-    SPICE_CHANNEL_STATE_FAILED_AUTHENTICATION,
     SPICE_CHANNEL_STATE_RECONNECTING,
     SPICE_CHANNEL_STATE_CONNECTING,
     SPICE_CHANNEL_STATE_READY,
@@ -110,6 +109,8 @@ struct _SpiceChannelPrivate {
 
     char                        name[16];
     enum spice_channel_state    state;
+    SpiceChannelEvent           event;
+
     spice_parse_channel_func_t  parser;
     SpiceMessageMarshallers     *marshallers;
     guint                       channel_watch;
diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
index 0301204..2f0ae1a 100644
--- a/gtk/spice-channel.c
+++ b/gtk/spice-channel.c
@@ -1122,7 +1122,7 @@ static void spice_channel_failed_authentication(SpiceChannel *channel)
                             SPICE_CLIENT_ERROR_AUTH_NEEDS_PASSWORD,
                             _("Authentication failed: password is required"));
 
-    c->state = SPICE_CHANNEL_STATE_FAILED_AUTHENTICATION;
+    c->event = SPICE_CHANNEL_ERROR_AUTH;
 
     c->has_error = TRUE; /* force disconnect */
 }
@@ -2240,8 +2240,9 @@ static gboolean spice_channel_delayed_unref(gpointer data)
 
     g_return_val_if_fail(c->coroutine.coroutine.exited == TRUE, FALSE);
 
-    if (c->state == SPICE_CHANNEL_STATE_FAILED_AUTHENTICATION) {
-        g_coroutine_signal_emit(channel, signals[SPICE_CHANNEL_EVENT], 0, SPICE_CHANNEL_ERROR_AUTH);
+    if (c->event != SPICE_CHANNEL_NONE) {
+        g_coroutine_signal_emit(channel, signals[SPICE_CHANNEL_EVENT], 0, c->event);
+        c->event = SPICE_CHANNEL_NONE;
         g_clear_error(&c->error);
     }
 
@@ -2352,13 +2353,13 @@ static void *spice_channel_coroutine(void *data)
     if (spice_session_get_client_provided_socket(c->session)) {
         if (c->fd < 0) {
             g_critical("fd not provided!");
-            g_coroutine_signal_emit(channel, signals[SPICE_CHANNEL_EVENT], 0, SPICE_CHANNEL_ERROR_CONNECT);
+            c->event = SPICE_CHANNEL_ERROR_CONNECT;
             goto cleanup;
         }
 
         if (!(c->sock = g_socket_new_from_fd(c->fd, NULL))) {
                 CHANNEL_DEBUG(channel, "Failed to open socket from fd %d", c->fd);
-                g_coroutine_signal_emit(channel, signals[SPICE_CHANNEL_EVENT], 0, SPICE_CHANNEL_ERROR_CONNECT);
+                c->event = SPICE_CHANNEL_ERROR_CONNECT;
                 goto cleanup;
         }
 
@@ -2378,8 +2379,7 @@ reconnect:
             goto reconnect;
         } else {
             CHANNEL_DEBUG(channel, "Connect error");
-            g_coroutine_signal_emit(channel, signals[SPICE_CHANNEL_EVENT], 0, SPICE_CHANNEL_ERROR_CONNECT);
-            g_clear_error(&c->error);
+            c->event = SPICE_CHANNEL_ERROR_CONNECT;
             goto cleanup;
         }
     }
@@ -2391,7 +2391,7 @@ reconnect:
         c->ctx = SSL_CTX_new(SSLv23_method());
         if (c->ctx == NULL) {
             g_critical("SSL_CTX_new failed");
-            g_coroutine_signal_emit(channel, signals[SPICE_CHANNEL_EVENT], 0, SPICE_CHANNEL_ERROR_TLS);
+            c->event = SPICE_CHANNEL_ERROR_TLS;
             goto cleanup;
         }
 
@@ -2407,7 +2407,7 @@ reconnect:
                     g_warning("only pubkey active");
                     verify = SPICE_SESSION_VERIFY_PUBKEY;
                 } else {
-                    g_coroutine_signal_emit(channel, signals[SPICE_CHANNEL_EVENT], 0, SPICE_CHANNEL_ERROR_TLS);
+                    c->event = SPICE_CHANNEL_ERROR_TLS;
                     goto cleanup;
                 }
             }
@@ -2425,7 +2425,7 @@ reconnect:
         c->ssl = SSL_new(c->ctx);
         if (c->ssl == NULL) {
             g_critical("SSL_new failed");
-            g_coroutine_signal_emit(channel, signals[SPICE_CHANNEL_EVENT], 0, SPICE_CHANNEL_ERROR_TLS);
+            c->event = SPICE_CHANNEL_ERROR_TLS;
             goto cleanup;
         }
 
@@ -2454,7 +2454,7 @@ ssl_reconnect:
             } else {
                 g_warning("%s: SSL_connect: %s",
                           c->name, ERR_error_string(rc, NULL));
-                g_coroutine_signal_emit(channel, signals[SPICE_CHANNEL_EVENT], 0, SPICE_CHANNEL_ERROR_TLS);
+                c->event = SPICE_CHANNEL_ERROR_TLS;
                 goto cleanup;
             }
         }
@@ -2489,7 +2489,8 @@ cleanup:
 
     SPICE_CHANNEL_GET_CLASS(channel)->channel_disconnect(channel);
 
-    if (c->state == SPICE_CHANNEL_STATE_RECONNECTING) {
+    if (c->event == SPICE_CHANNEL_NONE &&
+        c->state == SPICE_CHANNEL_STATE_RECONNECTING) {
         spice_channel_connect(channel);
         g_object_unref(channel);
     } else
-- 
2.1.0



More information about the Spice-devel mailing list