From 01f96fa995df77a7db5080b83e45f0e0a061aea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Mon, 9 Jan 2012 14:35:40 +0100 Subject: [PATCH spice-gtk] Remove the non-interruptible version g_io_wait() Use the common g_coroutine_socket_wait() https://bugs.freedesktop.org/show_bug.cgi?id=44570 --- gtk/gio-coroutine.c | 45 +++++++++++++++------------------------------ gtk/gio-coroutine.h | 8 ++++---- gtk/spice-channel.c | 12 ++++++------ gtk/spice-session-priv.h | 3 ++- gtk/spice-session.c | 12 ++++++++---- 5 files changed, 35 insertions(+), 45 deletions(-) diff --git a/gtk/gio-coroutine.c b/gtk/gio-coroutine.c index c6dabe6..4816cdd 100644 --- a/gtk/gio-coroutine.c +++ b/gtk/gio-coroutine.c @@ -39,52 +39,37 @@ static gboolean g_io_wait_helper(GSocket *sock G_GNUC_UNUSED, return FALSE; } -GIOCondition g_io_wait(GSocket *sock, GIOCondition cond) -{ - GIOCondition *ret; - GSource *src = g_socket_create_source(sock, - cond | G_IO_HUP | G_IO_ERR | G_IO_NVAL, - NULL); - g_source_set_callback(src, (GSourceFunc)g_io_wait_helper, coroutine_self(), NULL); - g_source_attach(src, NULL); - ret = coroutine_yield(NULL); - g_source_unref(src); - return *ret; -} - - -GIOCondition g_io_wait_interruptible(GCoroutine *self, +GIOCondition g_coroutine_socket_wait(GCoroutine *self, GSocket *sock, GIOCondition cond) { - GIOCondition *ret; - gint id; + GIOCondition *ret, val = 0; + GSource *src; g_return_val_if_fail(self != NULL, 0); + g_return_val_if_fail(self->source_id == 0, 0); g_return_val_if_fail(sock != NULL, 0); - GSource *src = g_socket_create_source(sock, - cond | G_IO_HUP | G_IO_ERR | G_IO_NVAL, - NULL); + src = g_socket_create_source(sock, cond | G_IO_HUP | G_IO_ERR | G_IO_NVAL, NULL); g_source_set_callback(src, (GSourceFunc)g_io_wait_helper, self, NULL); - id = g_source_attach(src, NULL); - self->waiting = TRUE; + self->source_id = g_source_attach(src, NULL); ret = coroutine_yield(NULL); - self->waiting = FALSE; g_source_unref(src); - if (ret == NULL) { - g_source_remove(id); - return 0; - } else - return *ret; + if (ret != NULL) + val = *ret; + else + g_source_remove(self->source_id); + + self->source_id = 0; + return val; } -void g_io_wakeup(GCoroutine *self) +void g_coroutine_wakeup(GCoroutine *self) { g_return_if_fail(self != NULL); - if (self->waiting) + if (self->source_id != 0) coroutine_yieldto(&self->coroutine, NULL); } diff --git a/gtk/gio-coroutine.h b/gtk/gio-coroutine.h index 43dbc55..b42e327 100644 --- a/gtk/gio-coroutine.h +++ b/gtk/gio-coroutine.h @@ -31,7 +31,7 @@ typedef struct _GCoroutine GCoroutine; struct _GCoroutine { struct coroutine coroutine; - gboolean waiting; + guint source_id; }; /* @@ -47,10 +47,10 @@ typedef gboolean (*GConditionWaitFunc)(gpointer); typedef void (*GSignalEmitMainFunc)(GObject *object, int signum, gpointer params); -GIOCondition g_io_wait (GSocket *sock, GIOCondition cond); +void g_coroutine_wakeup (GCoroutine *coroutine); +GIOCondition g_coroutine_socket_wait(GCoroutine *coroutine, GSocket *sock, GIOCondition cond); + gboolean g_condition_wait (GConditionWaitFunc func, gpointer data); -void g_io_wakeup (GCoroutine *coroutine); -GIOCondition g_io_wait_interruptible(GCoroutine *coroutine, GSocket *sock, GIOCondition cond); void g_signal_emit_main_context(GObject *object, GSignalEmitMainFunc func, int signum, gpointer params, const char *debug_info); void g_object_notify_main_context(GObject *object, const gchar *property_name); diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c index f9332b2..e4b4d03 100644 --- a/gtk/spice-channel.c +++ b/gtk/spice-channel.c @@ -649,7 +649,7 @@ static void spice_channel_flush_wire(SpiceChannel *channel, } if (ret == -1) { if (cond != 0) { - g_io_wait(c->sock, cond); + g_coroutine_socket_wait(&c->coroutine, c->sock, cond); continue; } else { SPICE_DEBUG("Closing the channel: spice_channel_flush %d", errno); @@ -775,7 +775,7 @@ reread: if (ret == -1) { if (cond != 0) { - g_io_wait(c->sock, cond); + g_coroutine_socket_wait(&c->coroutine, c->sock, cond); goto reread; } else { c->has_error = TRUE; @@ -1584,7 +1584,7 @@ void spice_channel_wakeup(SpiceChannel *channel) { SpiceChannelPrivate *c = channel->priv; - g_io_wakeup(&c->coroutine); + g_coroutine_wakeup(&c->coroutine); } G_GNUC_INTERNAL @@ -1877,7 +1877,7 @@ static gboolean spice_channel_iterate(SpiceChannel *channel) } SPICE_CHANNEL_GET_CLASS(channel)->iterate_write(channel); - ret = g_io_wait_interruptible(&c->coroutine, c->sock, G_IO_IN); + ret = g_coroutine_socket_wait(&c->coroutine, c->sock, G_IO_IN); #ifdef WIN32 /* FIXME: windows gsocket is buggy, it doesn't return correct condition... */ @@ -1948,7 +1948,7 @@ static void *spice_channel_coroutine(void *data) } reconnect: - c->sock = spice_session_channel_open_host(c->session, c->tls); + c->sock = spice_session_channel_open_host(c->session, channel, c->tls); if (c->sock == NULL) { if (!c->tls) { SPICE_DEBUG("connection failed, trying with TLS port"); @@ -2027,7 +2027,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_io_wait(c->sock, G_IO_OUT|G_IO_ERR|G_IO_HUP); + g_coroutine_socket_wait(&c->coroutine, c->sock, G_IO_OUT|G_IO_ERR|G_IO_HUP); goto ssl_reconnect; } else { g_warning("%s: SSL_connect: %s", diff --git a/gtk/spice-session-priv.h b/gtk/spice-session-priv.h index bb5ae9b..5df1182 100644 --- a/gtk/spice-session-priv.h +++ b/gtk/spice-session-priv.h @@ -97,7 +97,8 @@ void spice_session_set_connection_id(SpiceSession *session, int id); int spice_session_get_connection_id(SpiceSession *session); gboolean spice_session_get_client_provided_socket(SpiceSession *session); -GSocket* spice_session_channel_open_host(SpiceSession *session, gboolean use_tls); +GSocket* spice_session_channel_open_host(SpiceSession *session, SpiceChannel *channel, + gboolean use_tls); void spice_session_channel_new(SpiceSession *session, SpiceChannel *channel); void spice_session_channel_destroy(SpiceSession *session, SpiceChannel *channel); void spice_session_channel_migrate(SpiceSession *session, SpiceChannel *channel); diff --git a/gtk/spice-session.c b/gtk/spice-session.c index be6753a..8b58781 100644 --- a/gtk/spice-session.c +++ b/gtk/spice-session.c @@ -1358,9 +1358,11 @@ gboolean spice_session_has_channel_type(SpiceSession *session, gint type) /* ------------------------------------------------------------------ */ /* private functions */ -static GSocket *channel_connect_socket(GSocketAddress *sockaddr, +static GSocket *channel_connect_socket(SpiceChannel *channel, + GSocketAddress *sockaddr, GError **error) { + SpiceChannelPrivate *c = channel->priv; GSocket *sock = g_socket_new(g_socket_address_get_family(sockaddr), G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, @@ -1374,7 +1376,7 @@ static GSocket *channel_connect_socket(GSocketAddress *sockaddr, if (*error && (*error)->code == G_IO_ERROR_PENDING) { g_clear_error(error); SPICE_DEBUG("Socket pending"); - g_io_wait(sock, G_IO_OUT | G_IO_ERR | G_IO_HUP); + g_coroutine_socket_wait(&c->coroutine, sock, G_IO_OUT | G_IO_ERR | G_IO_HUP); if (!g_socket_check_connect_result(sock, error)) { SPICE_DEBUG("Failed to connect %s", (*error)->message); @@ -1393,8 +1395,10 @@ static GSocket *channel_connect_socket(GSocketAddress *sockaddr, return sock; } +/* coroutine context */ G_GNUC_INTERNAL -GSocket* spice_session_channel_open_host(SpiceSession *session, gboolean use_tls) +GSocket* spice_session_channel_open_host(SpiceSession *session, SpiceChannel *channel, + gboolean use_tls) { SpiceSessionPrivate *s = SPICE_SESSION_GET_PRIVATE(session); GSocketConnectable *addr; @@ -1424,7 +1428,7 @@ GSocket* spice_session_channel_open_host(SpiceSession *session, gboolean use_tls (sockaddr = g_socket_address_enumerator_next(enumerator, NULL, &conn_error))) { SPICE_DEBUG("Trying one socket"); g_clear_error(&conn_error); - sock = channel_connect_socket(sockaddr, &conn_error); + sock = channel_connect_socket(channel, sockaddr, &conn_error); if (conn_error != NULL) g_warning("%s", conn_error->message); g_object_unref(sockaddr); -- 1.7.7.5