summaryrefslogtreecommitdiff
path: root/telepathy-glib/util.c
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2010-09-23 16:50:20 +0200
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2010-09-28 10:15:34 +0200
commit5f37c8413dcf32b90d980eb8457a2b3efd883e1d (patch)
treeb1cd6ea5972d21a2cee52f2df72343ad086b4ae4 /telepathy-glib/util.c
parent958703156670c679ced48285a5ca3ec56208dc98 (diff)
downloadtelepathy-glib-5f37c8413dcf32b90d980eb8457a2b3efd883e1d.tar.gz
factor out _tp_create_temp_unix_socket()
Diffstat (limited to 'telepathy-glib/util.c')
-rw-r--r--telepathy-glib/util.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/telepathy-glib/util.c b/telepathy-glib/util.c
index 78ebaca6f..c2b3b7fbe 100644
--- a/telepathy-glib/util.c
+++ b/telepathy-glib/util.c
@@ -27,11 +27,19 @@
* GLib, but aren't.
*/
+#include <config.h>
+
#include <gobject/gvaluecollector.h>
+#ifdef HAVE_GIO_UNIX
+#include <gio/gunixsocketaddress.h>
+#include <gio/gunixconnection.h>
+#endif /* HAVE_GIO_UNIX */
+
#include <telepathy-glib/util-internal.h>
#include <telepathy-glib/util.h>
+#include <stdio.h>
#include <string.h>
#define DEBUG_FLAG TP_DEBUG_MISC
@@ -1490,3 +1498,35 @@ next_i:
continue;
}
}
+
+#ifdef HAVE_GIO_UNIX
+GSocketAddress *
+_tp_create_temp_unix_socket (GSocketService *service,
+ GError **error)
+{
+ guint i;
+ GSocketAddress *address;
+
+ /* why doesn't GIO provide a method to create a socket we don't
+ * care about? Iterate until we find a valid temporary name.
+ *
+ * Try a maximum of 10 times to get a socket */
+ for (i = 0; i < 10; i++)
+ {
+ address = g_unix_socket_address_new (tmpnam (NULL));
+
+ g_clear_error (error);
+
+ if (g_socket_listener_add_address (
+ G_SOCKET_LISTENER (service),
+ address, G_SOCKET_TYPE_STREAM,
+ G_SOCKET_PROTOCOL_DEFAULT,
+ NULL, NULL, error))
+ return address;
+ else
+ g_object_unref (address);
+ }
+
+ return NULL;
+}
+#endif /* HAVE_GIO_UNIX */