summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSjoerd Simons <sjoerd@luon.net>2013-04-28 15:30:10 +0200
committerSjoerd Simons <sjoerd@luon.net>2013-04-28 21:17:53 +0200
commitda178c9dbd46c0c067e9d44355687080939678a1 (patch)
treecbcbbe6c225dd2164370464d1d48ebe3517b5478
parente1291f040d13f205d4bb3c03bca28fef7312ff5e (diff)
Connect to the server in the non-main thread
To do interactive certificate verification with GTls one needs to block in the accept-certificate signal handler, which practically means the connection needs to be done in a seperate check. As a first step, instead using _connect_to_host_async in the main thread use a GTask to synchronously connect in a different thread instead.
-rw-r--r--configure.ac4
-rw-r--r--src/idle-server-connection.c24
2 files changed, 23 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac
index df9c964..f7fb648 100644
--- a/configure.ac
+++ b/configure.ac
@@ -86,10 +86,10 @@ AC_HEADER_STDC([])
AC_C_INLINE
AC_DEFINE(GLIB_VERSION_MIN_REQUIRED, GLIB_VERSION_2_28, [Ignore post 2.28 deprecations])
-AC_DEFINE(GLIB_VERSION_MAX_ALLOWED, GLIB_VERSION_2_30, [Prevent post 2.30 APIs])
+AC_DEFINE(GLIB_VERSION_MAX_ALLOWED, GLIB_VERSION_2_36, [Prevent post 2.36 APIs])
PKG_CHECK_MODULES([GLIB],
- [glib-2.0 >= 2.30.0, gobject-2.0 >= 2.30.0, gio-2.0 >= 2.30.0 ])
+ [glib-2.0 >= 2.36.0, gobject-2.0 >= 2.36.0, gio-2.0 >= 2.36.0 ])
PKG_CHECK_MODULES([DBUS], [dbus-1 >= 0.51, dbus-glib-1 >= 0.51])
diff --git a/src/idle-server-connection.c b/src/idle-server-connection.c
index 6c5894f..1605b61 100644
--- a/src/idle-server-connection.c
+++ b/src/idle-server-connection.c
@@ -254,7 +254,6 @@ cleanup:
}
static void _connect_to_host_ready(GObject *source_object, GAsyncResult *res, gpointer user_data) {
- GSocketClient *socket_client = G_SOCKET_CLIENT(source_object);
GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT(user_data);
IdleServerConnection *conn = IDLE_SERVER_CONNECTION(g_async_result_get_source_object(G_ASYNC_RESULT(result)));
IdleServerConnectionPrivate *priv = IDLE_SERVER_CONNECTION_GET_PRIVATE(conn);
@@ -265,7 +264,7 @@ static void _connect_to_host_ready(GObject *source_object, GAsyncResult *res, gp
gint socket_fd;
GError *error = NULL;
- socket_connection = g_socket_client_connect_to_host_finish(socket_client, res, &error);
+ socket_connection = g_task_propagate_pointer (G_TASK (res), &error);
if (socket_connection == NULL) {
IDLE_DEBUG("g_socket_client_connect_to_host failed: %s", error->message);
g_simple_async_result_set_error(result, TP_ERROR, TP_ERROR_NETWORK_ERROR, "%s", error->message);
@@ -294,9 +293,24 @@ cleanup:
g_object_unref(result);
}
+static void _connect_in_thread (GTask *task, gpointer source_object, gpointer task_data, GCancellable *cancellable)
+{
+ IdleServerConnection *conn = source_object;
+ IdleServerConnectionPrivate *priv = IDLE_SERVER_CONNECTION_GET_PRIVATE(conn);
+ GError *error = NULL;
+ GSocketConnection *socket_connection;
+
+ socket_connection = g_socket_client_connect_to_host (priv->socket_client, priv->host, priv->port, cancellable, &error);
+ if (socket_connection != NULL)
+ g_task_return_pointer (task, socket_connection, NULL);
+ else
+ g_task_return_error (task, error);
+}
+
void idle_server_connection_connect_async(IdleServerConnection *conn, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) {
IdleServerConnectionPrivate *priv = IDLE_SERVER_CONNECTION_GET_PRIVATE(conn);
GSimpleAsyncResult *result;
+ GTask *task;
if (priv->state != SERVER_CONNECTION_STATE_NOT_CONNECTED) {
IDLE_DEBUG("already connecting or connected!");
@@ -326,7 +340,11 @@ void idle_server_connection_connect_async(IdleServerConnection *conn, GCancellab
}
result = g_simple_async_result_new(G_OBJECT(conn), callback, user_data, idle_server_connection_connect_async);
- g_socket_client_connect_to_host_async(priv->socket_client, priv->host, priv->port, cancellable, _connect_to_host_ready, result);
+
+ task = g_task_new (conn, cancellable,
+ _connect_to_host_ready, result);
+ g_task_run_in_thread (task, _connect_in_thread);
+
change_state(conn, SERVER_CONNECTION_STATE_CONNECTING, SERVER_CONNECTION_STATE_REASON_REQUESTED);
}