[kdbus] Integrate kdbus core with new API.
[platform/upstream/glib.git] / gio / tests / socket-common.c
index 8d2933b..e59fa9c 100644 (file)
@@ -1,5 +1,6 @@
 /* #included into both socket-client.c and socket-server.c */
 
+#ifdef G_OS_UNIX
 static const char *unix_socket_address_types[] = {
   "invalid",
   "anonymous",
@@ -7,6 +8,7 @@ static const char *unix_socket_address_types[] = {
   "abstract",
   "padded"
 };
+#endif
 
 static char *
 socket_address_to_string (GSocketAddress *address)
@@ -39,7 +41,7 @@ socket_address_to_string (GSocketAddress *address)
   return res;
 }
 
-GSocketAddress *
+static GSocketAddress *
 socket_address_from_string (const char *name)
 {
 #ifdef G_OS_UNIX
@@ -58,3 +60,64 @@ socket_address_from_string (const char *name)
 #endif
   return NULL;
 }
+
+static gboolean
+source_ready (GPollableInputStream *stream,
+             gpointer              data)
+{
+  g_main_loop_quit (loop);
+  return FALSE;
+}
+
+static void
+ensure_socket_condition (GSocket      *socket,
+                        GIOCondition  condition,
+                        GCancellable *cancellable)
+{
+  GSource *source;
+
+  if (!non_blocking)
+    return;
+
+  source = g_socket_create_source (socket, condition, cancellable);
+  g_source_set_callback (source,
+                        (GSourceFunc) source_ready,
+                        NULL, NULL);
+  g_source_attach (source, NULL);
+  g_source_unref (source);
+  g_main_loop_run (loop);
+}
+
+static void
+ensure_connection_condition (GIOStream    *stream,
+                            GIOCondition  condition,
+                            GCancellable *cancellable)
+{
+  GSource *source;
+
+  if (!non_blocking)
+    return;
+
+  if (condition & G_IO_IN)
+    source = g_pollable_input_stream_create_source (G_POLLABLE_INPUT_STREAM (g_io_stream_get_input_stream (stream)), cancellable);
+  else
+    source = g_pollable_output_stream_create_source (G_POLLABLE_OUTPUT_STREAM (g_io_stream_get_output_stream (stream)), cancellable);
+
+  g_source_set_callback (source,
+                        (GSourceFunc) source_ready,
+                        NULL, NULL);
+  g_source_attach (source, NULL);
+  g_source_unref (source);
+  g_main_loop_run (loop);
+}
+
+static gpointer
+cancel_thread (gpointer data)
+{
+  GCancellable *cancellable = data;
+
+  g_usleep (1000*1000*cancel_timeout);
+  g_print ("Cancelling\n");
+  g_cancellable_cancel (cancellable);
+  return NULL;
+}