[glib] GUnixConnection: add async variant for send/receive_credentials()



commit d077b66ee9b480569095e605ce98edab61afbb1c
Author: Xavier Claessens <xavier claessens collabora co uk>
Date:   Mon Jan 16 14:51:19 2012 +0100

    GUnixConnection: add async variant for send/receive_credentials()
    
    https://bugzilla.gnome.org/show_bug.cgi?id=629503

 docs/reference/gio/gio-sections.txt |    4 +
 gio/gio.symbols                     |    4 +
 gio/gunixconnection.c               |  195 ++++++++++++++++++++++++++++++-----
 gio/gunixconnection.h               |   15 +++-
 4 files changed, 193 insertions(+), 25 deletions(-)
---
diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt
index 5f50e24..09b5404 100644
--- a/docs/reference/gio/gio-sections.txt
+++ b/docs/reference/gio/gio-sections.txt
@@ -1933,7 +1933,11 @@ GUnixConnection
 g_unix_connection_receive_fd
 g_unix_connection_send_fd
 g_unix_connection_receive_credentials
+g_unix_connection_receive_credentials_async
+g_unix_connection_receive_credentials_finish
 g_unix_connection_send_credentials
+g_unix_connection_send_credentials_async
+g_unix_connection_send_credentials_finish
 <SUBSECTION Standard>
 GUnixConnectionClass
 G_IS_UNIX_CONNECTION
diff --git a/gio/gio.symbols b/gio/gio.symbols
index 8e62cf2..34b6436 100644
--- a/gio/gio.symbols
+++ b/gio/gio.symbols
@@ -1069,7 +1069,11 @@ g_unix_connection_get_type
 g_unix_connection_receive_fd
 g_unix_connection_send_fd
 g_unix_connection_receive_credentials
+g_unix_connection_receive_credentials_async
+g_unix_connection_receive_credentials_finish
 g_unix_connection_send_credentials
+g_unix_connection_send_credentials_async
+g_unix_connection_send_credentials_finish
 #endif
 #ifndef G_OS_WIN32
 g_unix_fd_message_get_type
diff --git a/gio/gunixconnection.c b/gio/gunixconnection.c
index c21353e..cce009b 100644
--- a/gio/gunixconnection.c
+++ b/gio/gunixconnection.c
@@ -256,15 +256,6 @@ gint                    g_unix_connection_receive_fd_finish             (GUnixCo
                                                                          GError              **error);
 
 
-gboolean                g_unix_connection_send_credentials              (GUnixConnection      *connection,
-                                                                         GError              **error);
-void                    g_unix_connection_send_credentials_async        (GUnixConnection      *connection,
-                                                                         gint                  io_priority,
-                                                                         GAsyncReadyCallback   callback,
-                                                                         gpointer              user_data);
-gboolean                g_unix_connection_send_credentials_finish       (GUnixConnection      *connection,
-                                                                         GError              **error);
-
 gboolean                g_unix_connection_send_fake_credentials         (GUnixConnection      *connection,
                                                                          guint64               pid,
                                                                          guint64               uid,
@@ -280,21 +271,6 @@ void                    g_unix_connection_send_fake_credentials_async   (GUnixCo
 gboolean                g_unix_connection_send_fake_credentials_finish  (GUnixConnection      *connection,
                                                                          GError              **error);
 
-gboolean                g_unix_connection_receive_credentials           (GUnixConnection      *connection,
-                                                                         guint64              *pid,
-                                                                         guint64              *uid,
-                                                                         guint64              *gid,
-                                                                         GError              **error);
-void                    g_unix_connection_receive_credentials_async     (GUnixConnection      *connection,
-                                                                         gint                  io_priority,
-                                                                         GAsyncReadyCallback   callback,
-                                                                         gpointer              user_data);
-gboolean                g_unix_connection_receive_credentials_finish    (GUnixConnection      *connection,
-                                                                         guint64              *pid,
-                                                                         guint64              *uid,
-                                                                         guint64              *gid,
-                                                                         GError              **error);
-
 gboolean                g_unix_connection_create_pair                   (GUnixConnection     **one,
                                                                          GUnixConnection     **two,
                                                                          GError              **error);
@@ -382,6 +358,89 @@ g_unix_connection_send_credentials (GUnixConnection      *connection,
   return ret;
 }
 
+static void
+send_credentials_async_thread (GSimpleAsyncResult *result,
+                               GObject            *object,
+                               GCancellable       *cancellable)
+{
+  GError *error = NULL;
+
+  if (!g_unix_connection_send_credentials (G_UNIX_CONNECTION (object),
+                                           cancellable,
+                                           &error))
+    {
+      g_simple_async_result_take_error (result, error);
+    }
+}
+
+/**
+ * g_unix_connection_send_credentials_async:
+ * @connection: A #GUnixConnection.
+ * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
+ * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
+ * @user_data: (closure): the data to pass to callback function
+ *
+ * Asynchronously send credentials.
+ *
+ * For more details, see g_unix_connection_send_credentials() which is
+ * the synchronous version of this call.
+ *
+ * When the operation is finished, @callback will be called. You can then call
+ * g_unix_connection_send_credentials_finish() to get the result of the operation.
+ *
+ * Since: 2.32
+ **/
+void
+g_unix_connection_send_credentials_async (GUnixConnection      *connection,
+                                          GCancellable         *cancellable,
+                                          GAsyncReadyCallback   callback,
+                                          gpointer              user_data)
+{
+  GSimpleAsyncResult *result;
+
+  result = g_simple_async_result_new (G_OBJECT (connection),
+                                      callback, user_data,
+                                      g_unix_connection_send_credentials_async);
+
+  g_simple_async_result_run_in_thread (result,
+                                       send_credentials_async_thread,
+                                       G_PRIORITY_DEFAULT,
+                                       cancellable);
+  g_object_unref (result);
+}
+
+/**
+ * g_unix_connection_send_credentials_finish:
+ * @connection: A #GUnixConnection.
+ * @result: a #GAsyncResult.
+ * @error: a #GError, or %NULL
+ *
+ * Finishes an asynchronous send credentials operation started with
+ * g_unix_connection_send_credentials_async().
+ *
+ * Returns: %TRUE if the operation was successful, otherwise %FALSE.
+ *
+ * Since: 2.32
+ **/
+gboolean
+g_unix_connection_send_credentials_finish (GUnixConnection *connection,
+                                           GAsyncResult    *result,
+                                           GError         **error)
+{
+  g_return_val_if_fail (
+      g_simple_async_result_is_valid (result,
+                                      G_OBJECT (connection),
+                                      g_unix_connection_send_credentials_async),
+      FALSE);
+
+  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
+                                             error))
+    return FALSE;
+
+
+  return TRUE;
+}
+
 /**
  * g_unix_connection_receive_credentials:
  * @connection: A #GUnixConnection.
@@ -584,3 +643,91 @@ g_unix_connection_receive_credentials (GUnixConnection      *connection,
   g_object_unref (socket);
   return ret;
 }
+
+static void
+receive_credentials_async_thread (GSimpleAsyncResult *result,
+                                  GObject            *object,
+                                  GCancellable       *cancellable)
+{
+  GCredentials *creds;
+  GError *error = NULL;
+
+  creds = g_unix_connection_receive_credentials (G_UNIX_CONNECTION (object),
+                                                 cancellable,
+                                                 &error);
+
+  if (creds == NULL)
+    g_simple_async_result_take_error (result, error);
+  else
+    g_simple_async_result_set_op_res_gpointer (result, creds, g_object_unref);
+}
+
+/**
+ * g_unix_connection_receive_credentials_async:
+ * @connection: A #GUnixConnection.
+ * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
+ * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
+ * @user_data: (closure): the data to pass to callback function
+ *
+ * Asynchronously receive credentials.
+ *
+ * For more details, see g_unix_connection_receive_credentials() which is
+ * the synchronous version of this call.
+ *
+ * When the operation is finished, @callback will be called. You can then call
+ * g_unix_connection_receive_credentials_finish() to get the result of the operation.
+ *
+ * Since: 2.32
+ **/
+void
+g_unix_connection_receive_credentials_async (GUnixConnection      *connection,
+                                              GCancellable         *cancellable,
+                                              GAsyncReadyCallback   callback,
+                                              gpointer              user_data)
+{
+  GSimpleAsyncResult *result;
+
+  result = g_simple_async_result_new (G_OBJECT (connection),
+                                      callback, user_data,
+                                      g_unix_connection_receive_credentials_async);
+
+  g_simple_async_result_run_in_thread (result,
+                                       receive_credentials_async_thread,
+                                       G_PRIORITY_DEFAULT,
+                                       cancellable);
+
+  g_object_unref (result);
+}
+
+/**
+ * g_unix_connection_receive_credentials_finish:
+ * @connection: A #GUnixConnection.
+ * @result: a #GAsyncResult.
+ * @error: a #GError, or %NULL
+ *
+ * Finishes an asynchronous receive credentials operation started with
+ * g_unix_connection_receive_credentials_async().
+ *
+ * Returns: (transfer full): a #GCredentials, or %NULL on error.
+ *     Free the returned object with g_object_unref().
+ *
+ * Since: 2.32
+ **/
+GCredentials *
+g_unix_connection_receive_credentials_finish (GUnixConnection *connection,
+                                              GAsyncResult    *result,
+                                              GError         **error)
+{
+  g_return_val_if_fail (
+      g_simple_async_result_is_valid (result,
+                                      G_OBJECT (connection),
+                                      g_unix_connection_receive_credentials_async),
+      NULL);
+
+  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
+                                             error))
+    return NULL;
+
+  return g_object_ref (g_simple_async_result_get_op_res_gpointer (
+      G_SIMPLE_ASYNC_RESULT (result)));
+}
diff --git a/gio/gunixconnection.h b/gio/gunixconnection.h
index c38b0c9..e598ef5 100644
--- a/gio/gunixconnection.h
+++ b/gio/gunixconnection.h
@@ -74,11 +74,24 @@ gint                    g_unix_connection_receive_fd                    (GUnixCo
 gboolean                g_unix_connection_send_credentials              (GUnixConnection      *connection,
                                                                          GCancellable         *cancellable,
                                                                          GError              **error);
+void                    g_unix_connection_send_credentials_async        (GUnixConnection      *connection,
+                                                                         GCancellable         *cancellable,
+                                                                         GAsyncReadyCallback   callback,
+                                                                         gpointer              user_data);
+gboolean                g_unix_connection_send_credentials_finish       (GUnixConnection      *connection,
+                                                                         GAsyncResult         *result,
+                                                                         GError              **error);
 
 GCredentials           *g_unix_connection_receive_credentials           (GUnixConnection      *connection,
                                                                          GCancellable         *cancellable,
                                                                          GError              **error);
-
+void                    g_unix_connection_receive_credentials_async     (GUnixConnection      *connection,
+                                                                         GCancellable         *cancellable,
+                                                                         GAsyncReadyCallback   callback,
+                                                                         gpointer              user_data);
+GCredentials           *g_unix_connection_receive_credentials_finish    (GUnixConnection      *connection,
+                                                                         GAsyncResult         *result,
+                                                                         GError              **error);
 
 G_END_DECLS
 



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