summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2009-05-29 10:26:00 +0100
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2009-06-26 15:21:30 +0100
commit36a0860290d959ac9a1a52d304ea4520fa635e59 (patch)
treece70ed60936a956d037f042d4c80d385844234d7
parent2706d378ca1c221c1d7f2265fb2c9cc19b700978 (diff)
downloadtelepathy-salut-36a0860290d959ac9a1a52d304ea4520fa635e59.tar.gz
factor out create_dbus_server
-rw-r--r--src/tube-dbus.c58
1 files changed, 49 insertions, 9 deletions
diff --git a/src/tube-dbus.c b/src/tube-dbus.c
index 38505d41..afac7744 100644
--- a/src/tube-dbus.c
+++ b/src/tube-dbus.c
@@ -377,15 +377,29 @@ do_close (SalutTubeDBus *self)
}
}
-static void
-tube_dbus_open (SalutTubeDBus *self)
+/* There is two step to enable receiving a D-Bus connection from the local
+ * application:
+ * - listen on the socket
+ * - add the socket in the mainloop
+ *
+ * We need to know the socket path to return from the AcceptDBusTube D-Bus
+ * call but the socket in the mainloop must be added only when we are ready
+ * to receive connections, that is when the bytestream is fully open with the
+ * remote contact.
+ *
+ * See also Bug 13891:
+ * https://bugs.freedesktop.org/show_bug.cgi?id=13891
+ * */
+static gboolean
+create_dbus_server (SalutTubeDBus *self,
+ GError **err)
{
#define SERVER_LISTEN_MAX_TRIES 5
SalutTubeDBusPrivate *priv = SALUT_TUBE_DBUS_GET_PRIVATE (self);
guint i;
- g_signal_connect (priv->bytestream, "data-received",
- G_CALLBACK (data_received_cb), self);
+ if (priv->dbus_srv != NULL)
+ return TRUE;
for (i = 0; i < SERVER_LISTEN_MAX_TRIES; i++)
{
@@ -404,7 +418,7 @@ tube_dbus_open (SalutTubeDBus *self)
dbus_error_init (&error);
priv->dbus_srv = dbus_server_listen (priv->dbus_srv_addr, &error);
- if (priv->dbus_srv_addr != NULL)
+ if (priv->dbus_srv != NULL)
break;
DEBUG ("dbus_server_listen failed (try %u): %s: %s", i, error.name,
@@ -412,18 +426,44 @@ tube_dbus_open (SalutTubeDBus *self)
dbus_error_free (&error);
}
- if (priv->dbus_srv_addr == NULL)
+ if (priv->dbus_srv == NULL)
{
DEBUG ("all attempts failed. Close the tube");
- salut_tube_iface_accept (SALUT_TUBE_IFACE (self), NULL);
- return;
+
+ g_free (priv->dbus_srv_addr);
+ priv->dbus_srv_addr = NULL;
+
+ g_free (priv->socket_path);
+ priv->socket_path = NULL;
+
+ g_set_error (err, TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
+ "Can't create D-Bus server");
+ return FALSE;
}
DEBUG ("listening on %s", priv->dbus_srv_addr);
dbus_server_set_new_connection_function (priv->dbus_srv, new_connection_cb,
self, NULL);
- dbus_server_setup_with_g_main (priv->dbus_srv, NULL);
+
+ return TRUE;
+}
+
+static void
+tube_dbus_open (SalutTubeDBus *self)
+{
+ SalutTubeDBusPrivate *priv = SALUT_TUBE_DBUS_GET_PRIVATE (self);
+
+ g_signal_connect (priv->bytestream, "data-received",
+ G_CALLBACK (data_received_cb), self);
+
+ if (!create_dbus_server (self, NULL))
+ do_close (self);
+
+ if (priv->dbus_srv != NULL)
+ {
+ dbus_server_setup_with_g_main (priv->dbus_srv, NULL);
+ }
}
static void