[glib] Implemented g_socket_client_connect_to_uri() method



commit 0ebb79a7488121ae4a18cc84ac92e25ddb2b9544
Author: Nicolas Dufresne <nicolas dufresne collabora co uk>
Date:   Thu Apr 29 18:51:42 2010 -0400

    Implemented g_socket_client_connect_to_uri() method
    
    Using this rather than g_socket_client_connect() or
    g_socket_client_connect_to_host() allows #GSocketClient to
    determine when to use application-specific proxy protocols.
    
    Reviewed-by: Dan Winship <danw gnome org>

 docs/reference/gio/gio-sections.txt |    3 +
 gio/gio.symbols                     |    3 +
 gio/gsocketclient.c                 |  122 ++++++++++++++++++++++++++++++++++-
 gio/gsocketclient.h                 |   14 ++++
 4 files changed, 141 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt
index 06861c3..62a4ac4 100644
--- a/docs/reference/gio/gio-sections.txt
+++ b/docs/reference/gio/gio-sections.txt
@@ -1788,6 +1788,9 @@ g_socket_client_connect_to_host_finish
 g_socket_client_connect_to_service
 g_socket_client_connect_to_service_async
 g_socket_client_connect_to_service_finish
+g_socket_client_connect_to_uri
+g_socket_client_connect_to_uri_async
+g_socket_client_connect_to_uri_finish
 g_socket_client_set_family
 g_socket_client_set_local_address
 g_socket_client_set_protocol
diff --git a/gio/gio.symbols b/gio/gio.symbols
index 465dedc..9b1a687 100644
--- a/gio/gio.symbols
+++ b/gio/gio.symbols
@@ -1354,6 +1354,9 @@ g_socket_client_connect_to_host_finish
 g_socket_client_connect_to_service
 g_socket_client_connect_to_service_async
 g_socket_client_connect_to_service_finish
+g_socket_client_connect_to_uri
+g_socket_client_connect_to_uri_async
+g_socket_client_connect_to_uri_finish
 g_socket_client_get_family
 g_socket_client_get_local_address
 g_socket_client_get_protocol
diff --git a/gio/gsocketclient.c b/gio/gsocketclient.c
index 9284366..aa4ff38 100644
--- a/gio/gsocketclient.c
+++ b/gio/gsocketclient.c
@@ -754,7 +754,7 @@ g_socket_client_connect (GSocketClient       *client,
 
 /**
  * g_socket_client_connect_to_host:
- * @client: a #SocketClient
+ * @client: a #GSocketClient
  * @host_and_port: the name and optionally port of the host to connect to
  * @default_port: the default port to connect to
  * @cancellable: a #GCancellable, or %NULL
@@ -858,6 +858,59 @@ g_socket_client_connect_to_service (GSocketClient  *client,
   return connection;
 }
 
+/**
+ * g_socket_client_connect_to_uri:
+ * @client: a #GSocketClient
+ * @uri: A network URI
+ * @default_port: the default port to connect to
+ * @cancellable: a #GCancellable, or %NULL
+ * @error: a pointer to a #GError, or %NULL
+ *
+ * This is a helper function for g_socket_client_connect().
+ *
+ * Attempts to create a TCP connection with a network URI.
+ *
+ * @uri may be any valid URI containing an "authority" (hostname/port)
+ * component. If a port is not specified in the URI, @default_port
+ * will be used.
+ *
+ * Using this rather than g_socket_client_connect() or
+ * g_socket_client_connect_to_host() allows #GSocketClient to
+ * determine when to use application-specific proxy protocols.
+ *
+ * Upon a successful connection, a new #GSocketConnection is constructed
+ * and returned.  The caller owns this new object and must drop their
+ * reference to it when finished with it.
+ *
+ * In the event of any failure (DNS error, service not found, no hosts
+ * connectable) %NULL is returned and @error (if non-%NULL) is set
+ * accordingly.
+ *
+ * Returns: a #GSocketConnection on success, %NULL on error.
+ *
+ * Since: 2.26
+ */
+GSocketConnection *
+g_socket_client_connect_to_uri (GSocketClient  *client,
+				const gchar    *uri,
+				guint16         default_port,
+				GCancellable   *cancellable,
+				GError        **error)
+{
+  GSocketConnectable *connectable;
+  GSocketConnection *connection;
+
+  connectable = g_network_address_parse_uri (uri, default_port, error);
+  if (connectable == NULL)
+    return NULL;
+
+  connection = g_socket_client_connect (client, connectable,
+					cancellable, error);
+  g_object_unref (connectable);
+
+  return connection;
+}
+
 typedef struct
 {
   GSimpleAsyncResult *result;
@@ -1255,6 +1308,52 @@ g_socket_client_connect_to_service_async (GSocketClient       *client,
 }
 
 /**
+ * g_socket_client_connect_to_uri_async:
+ * @client: a #GSocketClient
+ * @uri: a network uri
+ * @default_port: the default port to connect to
+ * @cancellable: a #GCancellable, or %NULL
+ * @callback: a #GAsyncReadyCallback
+ * @user_data: user data for the callback
+ *
+ * This is the asynchronous version of g_socket_client_connect_to_uri().
+ *
+ * When the operation is finished @callback will be
+ * called. You can then call g_socket_client_connect_to_uri_finish() to get
+ * the result of the operation.
+ *
+ * Since: 2.26
+ */
+void
+g_socket_client_connect_to_uri_async (GSocketClient        *client,
+				      const gchar          *uri,
+				      guint16               default_port,
+				      GCancellable         *cancellable,
+				      GAsyncReadyCallback   callback,
+				      gpointer              user_data)
+{
+  GSocketConnectable *connectable;
+  GError *error;
+
+  error = NULL;
+  connectable = g_network_address_parse_uri (uri, default_port, &error);
+  if (connectable == NULL)
+    {
+      g_simple_async_report_gerror_in_idle (G_OBJECT (client),
+					    callback, user_data, error);
+      g_error_free (error);
+    }
+  else
+    {
+      g_socket_client_connect_async (client,
+				     connectable, cancellable,
+				     callback, user_data);
+      g_object_unref (connectable);
+    }
+}
+
+
+/**
  * g_socket_client_connect_finish:
  * @client: a #GSocketClient.
  * @result: a #GAsyncResult.
@@ -1321,3 +1420,24 @@ g_socket_client_connect_to_service_finish (GSocketClient  *client,
 {
   return g_socket_client_connect_finish (client, result, error);
 }
+
+/**
+ * g_socket_client_connect_to_uri_finish:
+ * @client: a #GSocketClient.
+ * @result: a #GAsyncResult.
+ * @error: a #GError location to store the error occuring, or %NULL to
+ * ignore.
+ *
+ * Finishes an async connect operation. See g_socket_client_connect_to_uri_async()
+ *
+ * Returns: a #GSocketConnection on success, %NULL on error.
+ *
+ * Since: 2.26
+ */
+GSocketConnection *
+g_socket_client_connect_to_uri_finish (GSocketClient  *client,
+				       GAsyncResult   *result,
+				       GError        **error)
+{
+  return g_socket_client_connect_finish (client, result, error);
+}
diff --git a/gio/gsocketclient.h b/gio/gsocketclient.h
index ace29af..0fa7970 100644
--- a/gio/gsocketclient.h
+++ b/gio/gsocketclient.h
@@ -103,6 +103,11 @@ GSocketConnection *     g_socket_client_connect_to_service              (GSocket
 									 const gchar          *service,
                                                                          GCancellable         *cancellable,
                                                                          GError              **error);
+GSocketConnection *     g_socket_client_connect_to_uri                  (GSocketClient        *client,
+									 const gchar          *uri,
+									 guint16               default_port,
+                                                                         GCancellable         *cancellable,
+                                                                         GError              **error);
 void                    g_socket_client_connect_async                   (GSocketClient        *client,
                                                                          GSocketConnectable   *connectable,
                                                                          GCancellable         *cancellable,
@@ -130,6 +135,15 @@ void                    g_socket_client_connect_to_service_async        (GSocket
 GSocketConnection *     g_socket_client_connect_to_service_finish       (GSocketClient        *client,
                                                                          GAsyncResult         *result,
                                                                          GError              **error);
+void                    g_socket_client_connect_to_uri_async            (GSocketClient        *client,
+									 const gchar          *uri,
+									 guint16               default_port,
+                                                                         GCancellable         *cancellable,
+                                                                         GAsyncReadyCallback   callback,
+                                                                         gpointer              user_data);
+GSocketConnection *     g_socket_client_connect_to_uri_finish           (GSocketClient        *client,
+                                                                         GAsyncResult         *result,
+                                                                         GError              **error);
 
 G_END_DECLS
 



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