[wing] wing/wingnamedpipelistener: remove support for listening on multiple pipes



commit 38d112dd7ce5501b9df0428d2161895af0d9129e
Author: Silvio Lazzeretti <silviola amazon com>
Date:   Tue Aug 9 10:17:06 2022 +0200

    wing/wingnamedpipelistener: remove support for listening on multiple pipes

 tests/named-pipe.c           |  83 +++++++-------
 wing/wingnamedpipelistener.c | 255 ++++++-------------------------------------
 wing/wingnamedpipelistener.h |   5 +-
 3 files changed, 76 insertions(+), 267 deletions(-)
---
diff --git a/tests/named-pipe.c b/tests/named-pipe.c
index e745e78..0c229d5 100644
--- a/tests/named-pipe.c
+++ b/tests/named-pipe.c
@@ -39,19 +39,20 @@ test_add_named_pipe (gconstpointer user_data)
   listener = wing_named_pipe_listener_new ();
   wing_named_pipe_listener_set_use_iocp (listener, test_data->use_iocp);
 
-  wing_named_pipe_listener_add_named_pipe (listener,
+  wing_named_pipe_listener_set_named_pipe (listener,
                                            "\\\\.\\pipe\\gtest-good-named-pipe-name",
                                            NULL,
                                            FALSE,
-                                           NULL,
                                            &error);
   g_assert_no_error (error);
+  g_object_unref (listener);
 
-  wing_named_pipe_listener_add_named_pipe (listener,
+  listener = wing_named_pipe_listener_new ();
+  wing_named_pipe_listener_set_use_iocp (listener, test_data->use_iocp);
+  wing_named_pipe_listener_set_named_pipe (listener,
                                            "\\\\.\\gtest-bad-named-pipe-name",
                                            NULL,
                                            FALSE,
-                                           NULL,
                                            &error);
   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_FAILED);
 
@@ -61,59 +62,65 @@ test_add_named_pipe (gconstpointer user_data)
 static void
 test_add_named_pipe_multiple_instances_no_protect (gconstpointer user_data)
 {
-  WingNamedPipeListener *listener;
+  WingNamedPipeListener *listener1;
+  WingNamedPipeListener *listener2;
   GError *error = NULL;
   TestData *test_data = (TestData *) user_data;
 
-  listener = wing_named_pipe_listener_new ();
-  wing_named_pipe_listener_set_use_iocp (listener, test_data->use_iocp);
+  listener1 = wing_named_pipe_listener_new ();
+  wing_named_pipe_listener_set_use_iocp (listener1, test_data->use_iocp);
 
-  wing_named_pipe_listener_add_named_pipe (listener,
+  wing_named_pipe_listener_set_named_pipe (listener1,
                                            "\\\\.\\pipe\\unprotected-named-pipe",
                                            NULL,
                                            FALSE,
-                                           NULL,
                                            &error);
   g_assert_no_error (error);
 
-  wing_named_pipe_listener_add_named_pipe (listener,
+  listener2 = wing_named_pipe_listener_new ();
+  wing_named_pipe_listener_set_use_iocp (listener2, test_data->use_iocp);
+
+  wing_named_pipe_listener_set_named_pipe (listener2,
                                            "\\\\.\\pipe\\unprotected-named-pipe",
                                            NULL,
                                            FALSE,
-                                           NULL,
                                            &error);
   g_assert_no_error (error);
 
-  g_object_unref (listener);
+  g_object_unref (listener1);
+  g_object_unref (listener2);
 }
 
 static void
 test_add_named_pipe_multiple_instances_protected (gconstpointer user_data)
 {
-  WingNamedPipeListener *listener;
+  WingNamedPipeListener *listener1;
+  WingNamedPipeListener *listener2;
   GError *error = NULL;
   TestData *test_data = (TestData *) user_data;
 
-  listener = wing_named_pipe_listener_new ();
-  wing_named_pipe_listener_set_use_iocp (listener, test_data->use_iocp);
+  listener1 = wing_named_pipe_listener_new ();
+  wing_named_pipe_listener_set_use_iocp (listener1, test_data->use_iocp);
 
-  wing_named_pipe_listener_add_named_pipe (listener,
+  wing_named_pipe_listener_set_named_pipe (listener1,
                                            "\\\\.\\pipe\\protected-named-pipe",
                                            NULL,
                                            TRUE,
-                                           NULL,
                                            &error);
   g_assert_no_error (error);
 
-  wing_named_pipe_listener_add_named_pipe (listener,
+  listener2 = wing_named_pipe_listener_new ();
+  wing_named_pipe_listener_set_use_iocp (listener2, test_data->use_iocp);
+
+  wing_named_pipe_listener_set_named_pipe (listener2,
                                            "\\\\.\\pipe\\protected-named-pipe",
                                            NULL,
                                            TRUE,
-                                           NULL,
                                            &error);
   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_FAILED);
 
-  g_object_unref (listener);
+  g_object_unref (listener1);
+  g_object_unref (listener2);
 }
 
 static void
@@ -126,7 +133,7 @@ accepted_cb (GObject      *source,
   gboolean *success = user_data;
   GError *error = NULL;
 
-  conn = wing_named_pipe_listener_accept_finish (listener, result, NULL, &error);
+  conn = wing_named_pipe_listener_accept_finish (listener, result, &error);
   g_assert_no_error (error);
   g_object_unref (conn);
 
@@ -163,11 +170,10 @@ test_connect_basic (gconstpointer user_data)
   listener = wing_named_pipe_listener_new ();
   wing_named_pipe_listener_set_use_iocp (listener, test_data->use_iocp);
 
-  wing_named_pipe_listener_add_named_pipe (listener,
+  wing_named_pipe_listener_set_named_pipe (listener,
                                            "\\\\.\\pipe\\gtest-named-pipe-name",
                                            NULL,
                                            FALSE,
-                                           NULL,
                                            &error);
   g_assert_no_error (error);
 
@@ -207,11 +213,10 @@ test_connect_before_accept (gconstpointer user_data)
   listener = wing_named_pipe_listener_new ();
   wing_named_pipe_listener_set_use_iocp (listener, test_data->use_iocp);
 
-  wing_named_pipe_listener_add_named_pipe (listener,
+  wing_named_pipe_listener_set_named_pipe (listener,
                                            "\\\\.\\pipe\\gtest-named-pipe-name",
                                            NULL,
                                            FALSE,
-                                           NULL,
                                            &error);
   g_assert_no_error (error);
 
@@ -250,11 +255,10 @@ test_connect_sync (gconstpointer user_data)
   listener = wing_named_pipe_listener_new ();
   wing_named_pipe_listener_set_use_iocp (listener, test_data->use_iocp);
 
-  wing_named_pipe_listener_add_named_pipe (listener,
+  wing_named_pipe_listener_set_named_pipe (listener,
                                            "\\\\.\\pipe\\gtest-connect-sync",
                                            NULL,
                                            FALSE,
-                                           NULL,
                                            &error);
   g_assert_no_error (error);
 
@@ -307,7 +311,7 @@ accept_cancelled_cb (GObject      *source,
   gboolean *cancelled = user_data;
   GError *error = NULL;
 
-  conn = wing_named_pipe_listener_accept_finish (listener, result, NULL, &error);
+  conn = wing_named_pipe_listener_accept_finish (listener, result, &error);
   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
 
   *cancelled = TRUE;
@@ -336,11 +340,10 @@ test_accept_cancel (gconstpointer user_data)
   listener = wing_named_pipe_listener_new ();
   wing_named_pipe_listener_set_use_iocp (listener, test_data->use_iocp);
 
-  wing_named_pipe_listener_add_named_pipe (listener,
+  wing_named_pipe_listener_set_named_pipe (listener,
                                            "\\\\.\\pipe\\gtest-named-pipe-name-cancel",
                                            NULL,
                                            FALSE,
-                                           NULL,
                                            &error);
   g_assert_no_error (error);
 
@@ -374,11 +377,10 @@ test_connect_accept_cancel (gconstpointer user_data)
   listener = wing_named_pipe_listener_new ();
   wing_named_pipe_listener_set_use_iocp (listener, test_data->use_iocp);
 
-  wing_named_pipe_listener_add_named_pipe (listener,
+  wing_named_pipe_listener_set_named_pipe (listener,
                                            "\\\\.\\pipe\\gtest-named-pipe-name-connect-then-cancel",
                                            NULL,
                                            FALSE,
-                                           NULL,
                                            &error);
   g_assert_no_error (error);
 
@@ -434,11 +436,10 @@ test_multi_client_basic (gconstpointer user_data)
   listener = wing_named_pipe_listener_new ();
   wing_named_pipe_listener_set_use_iocp (listener, test_data->use_iocp);
 
-  wing_named_pipe_listener_add_named_pipe (listener,
+  wing_named_pipe_listener_set_named_pipe (listener,
                                            "\\\\.\\pipe\\gtest-named-pipe-name-connect-multi-client",
                                            NULL,
                                            FALSE,
-                                           NULL,
                                            &error);
   g_assert_no_error (error);
 
@@ -515,7 +516,7 @@ accepted_read_write_cb (GObject      *source,
   WingNamedPipeConnection **conn = user_data;
   GError *error = NULL;
 
-  *conn = wing_named_pipe_listener_accept_finish (listener, result, NULL, &error);
+  *conn = wing_named_pipe_listener_accept_finish (listener, result, &error);
   g_assert_no_error (error);
 }
 
@@ -720,11 +721,10 @@ test_read_write_basic (gconstpointer user_data)
   listener = wing_named_pipe_listener_new ();
   wing_named_pipe_listener_set_use_iocp (listener, test_data->use_iocp);
 
-  wing_named_pipe_listener_add_named_pipe (listener,
+  wing_named_pipe_listener_set_named_pipe (listener,
                                            "\\\\.\\pipe\\gtest-named-pipe-name",
                                            NULL,
                                            FALSE,
-                                           NULL,
                                            &error);
   g_assert_no_error (error);
 
@@ -767,11 +767,10 @@ test_read_write_several_connections (gconstpointer user_data)
   listener = wing_named_pipe_listener_new ();
   wing_named_pipe_listener_set_use_iocp (listener, test_data->use_iocp);
 
-  wing_named_pipe_listener_add_named_pipe (listener,
+  wing_named_pipe_listener_set_named_pipe (listener,
                                            "\\\\.\\pipe\\gtest-named-pipe-name-read-write-several",
                                            NULL,
                                            FALSE,
-                                           NULL,
                                            &error);
   g_assert_no_error (error);
 
@@ -824,11 +823,10 @@ test_read_write_same_time_several_connections (gconstpointer user_data)
   listener = wing_named_pipe_listener_new ();
   wing_named_pipe_listener_set_use_iocp (listener, test_data->use_iocp);
 
-  wing_named_pipe_listener_add_named_pipe (listener,
+  wing_named_pipe_listener_set_named_pipe (listener,
                                            "\\\\.\\pipe\\gtest-named-pipe-name-read-write-several",
                                            NULL,
                                            FALSE,
-                                           NULL,
                                            &error);
   g_assert_no_error (error);
 
@@ -914,11 +912,10 @@ test_cancel_read (gconstpointer user_data)
   listener = wing_named_pipe_listener_new ();
   wing_named_pipe_listener_set_use_iocp (listener, test_data->use_iocp);
 
-  wing_named_pipe_listener_add_named_pipe (listener,
+  wing_named_pipe_listener_set_named_pipe (listener,
                                            "\\\\.\\pipe\\gtest-named-pipe-name",
                                            NULL,
                                            FALSE,
-                                           NULL,
                                            &error);
   g_assert_no_error (error);
 
diff --git a/wing/wingnamedpipelistener.c b/wing/wingnamedpipelistener.c
index 249a47d..5de48dd 100644
--- a/wing/wingnamedpipelistener.c
+++ b/wing/wingnamedpipelistener.c
@@ -34,14 +34,12 @@ typedef struct
   gunichar2 *security_descriptorw;
   HANDLE handle;
   OVERLAPPED overlapped;
-  GObject *source_object;
   gboolean already_connected;
 } PipeData;
 
 typedef struct
 {
-  GPtrArray *named_pipes;
-  GMainContext *main_context;
+  PipeData *named_pipe;
   gboolean use_iocp;
 } WingNamedPipeListenerPrivate;
 
@@ -60,8 +58,7 @@ static GQuark source_quark = 0;
 
 static PipeData *
 pipe_data_new (const gchar *pipe_name,
-               const gchar *security_descriptor,
-               GObject     *source_object)
+               const gchar *security_descriptor)
 {
   PipeData *data;
 
@@ -75,8 +72,6 @@ pipe_data_new (const gchar *pipe_name,
                                          TRUE, /* manual-reset event */
                                          TRUE, /* initial state = signaled */
                                          NULL); /* unnamed event object */
-  if (source_object)
-    data->source_object = g_object_ref (source_object);
 
   return data;
 }
@@ -91,7 +86,6 @@ pipe_data_free (PipeData *data)
   if (data->handle != INVALID_HANDLE_VALUE)
     CloseHandle (data->handle);
   CloseHandle (data->overlapped.hEvent);
-  g_clear_object (&data->source_object);
   g_slice_free (PipeData, data);
 }
 
@@ -149,10 +143,7 @@ wing_named_pipe_listener_finalize (GObject *object)
 
   priv = wing_named_pipe_listener_get_instance_private (listener);
 
-  if (priv->main_context)
-    g_main_context_unref (priv->main_context);
-
-  g_ptr_array_free (priv->named_pipes, TRUE);
+  g_clear_pointer (&priv->named_pipe, pipe_data_free);
 
   G_OBJECT_CLASS (wing_named_pipe_listener_parent_class)->finalize (object);
 }
@@ -188,11 +179,6 @@ wing_named_pipe_listener_class_init (WingNamedPipeListenerClass *klass)
 static void
 wing_named_pipe_listener_init (WingNamedPipeListener *listener)
 {
-  WingNamedPipeListenerPrivate *priv;
-
-  priv = wing_named_pipe_listener_get_instance_private (listener);
-
-  priv->named_pipes = g_ptr_array_new_with_free_func ((GDestroyNotify) pipe_data_free);
 }
 
 /**
@@ -305,12 +291,11 @@ create_pipe_from_pipe_data (PipeData  *pipe_data,
 }
 
 /**
- * wing_named_pipe_listener_add_named_pipe:
+ * wing_named_pipe_listener_set_named_pipe:
  * @listener: a #WingNamedPipeListener.
  * @pipe_name: a name for the pipe.
  * @security_descriptor: (allow-none): a security descriptor or %NULL.
  * @protect_first_instance: if %TRUE, the pipe creation will fail if the pipe already exists
- * @source_object: (allow-none): Optional #GObject identifying this source
  * @error: #GError for error reporting, or %NULL to ignore.
  *
  * Adds @named_pipe to the set of named pipes that we try to accept clients
@@ -330,19 +315,13 @@ create_pipe_from_pipe_data (PipeData  *pipe_data,
  * https://msdn.microsoft.com/en-us/library/windows/desktop/aa379570(v=vs.85).aspx
  * or set to %NULL to not set any security descriptor to the pipe.
  *
- * @source_object will be passed out in the various calls
- * to accept to identify this particular source, which is
- * useful if you're listening on multiple pipes and do
- * different things depending on what pipe is connected to.
- *
  * Returns: %TRUE on success, %FALSE on error.
  */
 gboolean
-wing_named_pipe_listener_add_named_pipe (WingNamedPipeListener  *listener,
+wing_named_pipe_listener_set_named_pipe (WingNamedPipeListener  *listener,
                                          const gchar            *pipe_name,
                                          const gchar            *security_descriptor,
                                          gboolean                protect_first_instance,
-                                         GObject                *source_object,
                                          GError                **error)
 {
   WingNamedPipeListenerPrivate *priv;
@@ -353,14 +332,15 @@ wing_named_pipe_listener_add_named_pipe (WingNamedPipeListener  *listener,
 
   priv = wing_named_pipe_listener_get_instance_private (listener);
 
-  pipe_data = pipe_data_new (pipe_name, security_descriptor, source_object);
+  pipe_data = pipe_data_new (pipe_name, security_descriptor);
   if (!create_pipe_from_pipe_data (pipe_data, protect_first_instance, error))
     {
       pipe_data_free (pipe_data);
       return FALSE;
     }
 
-  g_ptr_array_add (priv->named_pipes, pipe_data);
+  g_clear_pointer (&priv->named_pipe, pipe_data_free);
+  priv->named_pipe = pipe_data;
 
   return TRUE;
 }
@@ -378,18 +358,7 @@ connect_ready (HANDLE   handle,
 
   priv = wing_named_pipe_listener_get_instance_private (listener);
 
-  for (i = 0; i < priv->named_pipes->len; i++)
-    {
-      PipeData *pdata;
-
-      pdata = priv->named_pipes->pdata[i];
-      if (pdata->overlapped.hEvent == handle)
-        {
-          pipe_data = pdata;
-          break;
-        }
-    }
-
+  pipe_data = priv->named_pipe;
   g_return_val_if_fail (pipe_data != NULL, FALSE);
 
   if (!GetOverlappedResult (pipe_data->handle, &pipe_data->overlapped, &cbret, FALSE))
@@ -409,12 +378,6 @@ connect_ready (HANDLE   handle,
       WingNamedPipeConnection *connection;
       GError *error = NULL;
 
-      if (pipe_data->source_object != NULL)
-        g_object_set_qdata_full (G_OBJECT (task),
-                                 source_quark,
-                                 g_object_ref (pipe_data->source_object),
-                                 g_object_unref);
-
       connection = g_object_new (WING_TYPE_NAMED_PIPE_CONNECTION,
                                  "pipe-name", pipe_data->pipe_name,
                                  "handle", pipe_data->handle,
@@ -437,126 +400,25 @@ connect_ready (HANDLE   handle,
   return G_SOURCE_REMOVE;
 }
 
-static GList *
-add_sources (WingNamedPipeListener *listener,
-             WingSourceFunc         callback,
-             gpointer               callback_data,
-             GCancellable          *cancellable,
-             GMainContext          *context)
-{
-  WingNamedPipeListenerPrivate *priv;
-  GList *sources;
-  guint i;
-
-  priv = wing_named_pipe_listener_get_instance_private (listener);
-
-  sources = NULL;
-  for (i = 0; i < priv->named_pipes->len; i++)
-    {
-      PipeData *data;
-      GSource *source;
-
-      data = priv->named_pipes->pdata[i];
-
-      source = wing_create_source (data->overlapped.hEvent,
-                                   G_IO_IN,
-                                   cancellable);
-      g_source_set_callback (source,
-                             (GSourceFunc) callback,
-                             callback_data, NULL);
-      g_source_attach (source, context);
-
-      sources = g_list_prepend (sources, source);
-    }
-
-  return sources;
-}
-
 static void
-free_sources (GList *sources)
+free_source (GSource *source)
 {
-  while (sources != NULL)
+  if (source != NULL)
     {
-      GSource *source;
-
-      source = sources->data;
-      sources = g_list_delete_link (sources, sources);
       g_source_destroy (source);
       g_source_unref (source);
     }
 }
 
-struct AcceptData {
-  WingNamedPipeListener *listener;
-  GMainLoop *loop;
-  PipeData *pipe_data;
-};
-
-static gboolean
-accept_callback (HANDLE   handle,
-                 gpointer user_data)
-{
-  struct AcceptData *data = user_data;
-  WingNamedPipeListenerPrivate *priv;
-  PipeData *pipe_data = NULL;
-  guint i;
-
-  priv = wing_named_pipe_listener_get_instance_private (data->listener);
-
-  for (i = 0; i < priv->named_pipes->len; i++)
-    {
-      PipeData *pdata;
-
-      pdata = priv->named_pipes->pdata[i];
-      if (pdata->overlapped.hEvent == handle)
-        {
-          pipe_data = pdata;
-          break;
-        }
-    }
-
-  data->pipe_data = pipe_data;
-  g_main_loop_quit (data->loop);
-
-  return G_SOURCE_REMOVE;
-}
-
-/* Check if any of the named pipes is already connected
- * and pick the the first one.
- */
-static PipeData *
-find_first_connected (WingNamedPipeListener *listener)
-{
-  WingNamedPipeListenerPrivate *priv;
-  guint i;
-
-  priv = wing_named_pipe_listener_get_instance_private (listener);
-
-  for (i = 0; i < priv->named_pipes->len; i++)
-    {
-      PipeData *pdata = priv->named_pipes->pdata[i];
-
-      if (pdata->already_connected)
-        return pdata;
-    }
-
-  return NULL;
-}
-
 /**
  * wing_named_pipe_listener_accept:
  * @listener: a #WingNamedPipeListener
- * @source_object: (out) (transfer none) (allow-none): location where #GObject pointer will be stored, or 
%NULL.
  * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
  * @error: #GError for error reporting, or %NULL to ignore.
  *
  * Blocks waiting for a client to connect to any of the named pipes added
  * to the listener. Returns the #WingNamedPipeConnection that was accepted.
  *
- * If @source_object is not %NULL it will be filled out with the source
- * object specified when the corresponding named pipe was added
- * to the listener.
- *
  * If @cancellable is not %NULL, then the operation can be cancelled by
  * triggering the cancellable object from another thread. If the operation
  * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
@@ -565,61 +427,27 @@ find_first_connected (WingNamedPipeListener *listener)
  */
 WingNamedPipeConnection *
 wing_named_pipe_listener_accept (WingNamedPipeListener  *listener,
-                                 GObject               **source_object,
                                  GCancellable           *cancellable,
                                  GError                **error)
 {
   WingNamedPipeListenerPrivate *priv;
   PipeData *pipe_data = NULL;
   WingNamedPipeConnection *connection = NULL;
+  gboolean success;
 
   g_return_val_if_fail (WING_IS_NAMED_PIPE_LISTENER (listener), NULL);
 
   priv = wing_named_pipe_listener_get_instance_private (listener);
 
-  if (priv->named_pipes->len == 1)
-    {
-      gboolean success;
-
-      pipe_data = priv->named_pipes->pdata[0];
-      success = pipe_data->already_connected;
-
-      if (!success)
-        success = WaitForSingleObject (pipe_data->overlapped.hEvent, INFINITE) == WAIT_OBJECT_0;
+  pipe_data = priv->named_pipe;
+  g_return_val_if_fail(pipe_data != NULL, NULL);
 
-      if (!success)
-        pipe_data = NULL;
-    }
-  else
-    {
-      pipe_data = find_first_connected (listener);
+  success = pipe_data->already_connected;
 
-      if (pipe_data == NULL)
-        {
-          GList *sources;
-          struct AcceptData data;
-          GMainLoop *loop;
-
-          if (priv->main_context == NULL)
-            priv->main_context = g_main_context_new ();
-
-          loop = g_main_loop_new (priv->main_context, FALSE);
-          data.loop = loop;
-          data.listener = listener;
-
-          sources = add_sources (listener,
-                                 accept_callback,
-                                 &data,
-                                 cancellable,
-                                 priv->main_context);
-          g_main_loop_run (loop);
-          pipe_data = data.pipe_data;
-          free_sources (sources);
-          g_main_loop_unref (loop);
-        }
-    }
+  if (!success)
+    success = WaitForSingleObject (pipe_data->overlapped.hEvent, INFINITE) == WAIT_OBJECT_0;
 
-  if (pipe_data != NULL)
+  if (success)
     {
       connection = g_object_new (WING_TYPE_NAMED_PIPE_CONNECTION,
                                  "pipe-name", pipe_data->pipe_name,
@@ -628,9 +456,6 @@ wing_named_pipe_listener_accept (WingNamedPipeListener  *listener,
                                  "use-iocp", priv->use_iocp,
                                  NULL);
 
-      if (source_object)
-        *source_object = pipe_data->source_object;
-
       /* Put another pipe to listen so more clients can already connect */
       if (!create_pipe_from_pipe_data (pipe_data, FALSE, error))
         g_clear_object (&connection);
@@ -658,36 +483,28 @@ wing_named_pipe_listener_accept_async (WingNamedPipeListener *listener,
                                        GAsyncReadyCallback    callback,
                                        gpointer               user_data)
 {
-  PipeData *pipe_data;
   GTask *task;
-  GList *sources;
+  GSource *source;
+  WingNamedPipeListenerPrivate *priv;
 
   task = g_task_new (listener, cancellable, callback, user_data);
 
-  pipe_data = find_first_connected (listener);
+  priv = wing_named_pipe_listener_get_instance_private (listener);
+  g_return_if_fail (priv->named_pipe != NULL);
 
-  if (pipe_data != NULL)
+  if (priv->named_pipe->already_connected)
     {
       WingNamedPipeConnection *connection;
-      WingNamedPipeListenerPrivate *priv;
       GError *error = NULL;
 
-      priv = wing_named_pipe_listener_get_instance_private (listener);
-
-      if (pipe_data->source_object)
-        g_object_set_qdata_full (G_OBJECT (task),
-                                 source_quark,
-                                 g_object_ref (pipe_data->source_object),
-                                 g_object_unref);
-
       connection = g_object_new (WING_TYPE_NAMED_PIPE_CONNECTION,
-                                 "pipe-name", pipe_data->pipe_name,
-                                 "handle", pipe_data->handle,
+                                 "pipe-name", priv->named_pipe->pipe_name,
+                                 "handle", priv->named_pipe->handle,
                                  "close-handle", TRUE,
                                  "use-iocp", priv->use_iocp,
                                  NULL);
 
-      if (!create_pipe_from_pipe_data (pipe_data, FALSE, &error))
+      if (!create_pipe_from_pipe_data (priv->named_pipe, FALSE, &error))
         {
           g_object_unref (connection);
           g_task_return_error (task, error);
@@ -700,19 +517,21 @@ wing_named_pipe_listener_accept_async (WingNamedPipeListener *listener,
       return;
     }
 
-  sources = add_sources (listener,
-                         connect_ready,
-                         task,
-                         cancellable,
-                         g_main_context_get_thread_default ());
-  g_task_set_task_data (task, sources, (GDestroyNotify) free_sources);
+  source = wing_create_source (priv->named_pipe->overlapped.hEvent,
+                               G_IO_IN,
+                               cancellable);
+  g_source_set_callback (source,
+                         (GSourceFunc) connect_ready,
+                         task, NULL);
+  g_source_attach (source, g_main_context_get_thread_default ());
+
+  g_task_set_task_data (task, source, (GDestroyNotify) free_source);
 }
 
 /**
  * wing_named_pipe_listener_accept_finish:
  * @listener: a #WingNamedPipeListener.
  * @result: a #GAsyncResult.
- * @source_object: (out) (transfer none) (allow-none): Optional #GObject identifying this source
  * @error: a #GError location to store the error occurring, or %NULL to ignore.
  *
  * Finishes an async accept operation. See wing_named_pipe_listener_accept_async()
@@ -722,15 +541,11 @@ wing_named_pipe_listener_accept_async (WingNamedPipeListener *listener,
 WingNamedPipeConnection *
 wing_named_pipe_listener_accept_finish (WingNamedPipeListener  *listener,
                                         GAsyncResult           *result,
-                                        GObject               **source_object,
                                         GError                **error)
 {
   g_return_val_if_fail (WING_IS_NAMED_PIPE_LISTENER (listener), NULL);
   g_return_val_if_fail (g_task_is_valid (result, listener), NULL);
 
-  if (source_object)
-    *source_object = g_object_get_qdata (G_OBJECT (result), source_quark);
-
   return g_task_propagate_pointer (G_TASK (result), error);
 }
 
diff --git a/wing/wingnamedpipelistener.h b/wing/wingnamedpipelistener.h
index 4623a83..fc41678 100644
--- a/wing/wingnamedpipelistener.h
+++ b/wing/wingnamedpipelistener.h
@@ -55,16 +55,14 @@ WING_AVAILABLE_IN_ALL
 WingNamedPipeListener    *wing_named_pipe_listener_new            (void);
 
 WING_AVAILABLE_IN_ALL
-gboolean                  wing_named_pipe_listener_add_named_pipe (WingNamedPipeListener  *listener,
+gboolean                  wing_named_pipe_listener_set_named_pipe (WingNamedPipeListener  *listener,
                                                                    const gchar            *pipe_name,
                                                                    const gchar            
*security_descriptor,
                                                                    gboolean                
protect_first_instance,
-                                                                   GObject                *source_object,
                                                                    GError                **error);
 
 WING_AVAILABLE_IN_ALL
 WingNamedPipeConnection  *wing_named_pipe_listener_accept         (WingNamedPipeListener  *listener,
-                                                                   GObject               **source_object,
                                                                    GCancellable           *cancellable,
                                                                    GError                **error);
 
@@ -77,7 +75,6 @@ void                      wing_named_pipe_listener_accept_async   (WingNamedPipe
 WING_AVAILABLE_IN_ALL
 WingNamedPipeConnection  *wing_named_pipe_listener_accept_finish  (WingNamedPipeListener  *listener,
                                                                    GAsyncResult           *result,
-                                                                   GObject               **source_object,
                                                                    GError                **error);
 
 WING_AVAILABLE_IN_ALL


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]