summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>2009-05-18 15:22:17 (GMT)
committerSjoerd Simons <sjoerd.simons@collabora.co.uk>2009-05-18 15:22:17 (GMT)
commit0237cccc056c8c832852883ead6f1787147518ae (patch)
treed032b00a37131a2d2fc2047d6d73ca41b423c977
parent3aaab444c19e7e1bbf0eb55c8b552af652eff48e (diff)
downloadgnio-connect-to-service.tar.gz
gnio-connect-to-service.tar.xz
Re-add API to connect to a host based on SRV recordsconnect-to-service
-rw-r--r--gio/gsocketclient.c95
-rw-r--r--gio/gsocketclient.h15
2 files changed, 109 insertions, 1 deletions
diff --git a/gio/gsocketclient.c b/gio/gsocketclient.c
index 71385ba..aac925c 100644
--- a/gio/gsocketclient.c
+++ b/gio/gsocketclient.c
@@ -34,6 +34,7 @@
#include <gio/gcancellable.h>
#include <gio/gioerror.h>
#include <gio/gnetworkaddress.h>
+#include <gio/gnetworkservice.h>
#include <gio/gsocketaddress.h>
/**
@@ -453,7 +454,7 @@ g_socket_client_class_init (GSocketClientClass *class)
*
* The type of the #GSocketConnection object returned depends on the type of
* the underlying socket that is used. For instance, for a TCP/IP connection
- * it will be a #GTcpConnection.
+ * it will be a #GSocketConnection.
*
* The socket created will be the same family as the the address that the
* @connectable resolves to, unless family is set with g_socket_client_set_family()
@@ -596,6 +597,48 @@ g_socket_client_connect_to_host (GSocketClient *client,
return connection;
}
+/**
+ * g_socket_client_connect_to_service:
+ * @client: a #GSocketConnection
+ * @domain: a domain name
+ * @service: the name of the service to connect to
+ * @cancellable: a #GCancellable, or %NULL
+ * @error: a pointer to a #GError, or %NULL
+ * @returns: a #GSocketConnection if successful, or %NULL on error
+ *
+ * Attempts to create a TCP connection to a service.
+ *
+ * This call looks up the SRV record for @service at @domain for the
+ * "tcp" protocol. It then attempts to connect, in turn, to each of
+ * the hosts providing the service until either a connection succeeds
+ * or there are no hosts remaining.
+ *
+ * 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.
+ **/
+GSocketConnection *
+g_socket_client_connect_to_service (GSocketClient *client,
+ const char *domain,
+ const char *service,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GSocketConnectable *connectable;
+ GSocketConnection *connection;
+
+ connectable = g_network_service_new (service, "tcp", domain);
+ connection = g_socket_client_connect (client, connectable,
+ cancellable, error);
+ g_object_unref (connectable);
+
+ return connection;
+}
+
typedef struct
{
GSimpleAsyncResult *result;
@@ -857,6 +900,35 @@ g_socket_client_connect_to_host_async (GSocketClient *client,
}
/**
+ * g_socket_client_connect_to_service_async:
+ * @client: a #GSocketClient
+ * @domain: a domain name
+ * @service: the name of the service 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_service().
+ **/
+void
+g_socket_client_connect_to_service_async (GSocketClient *client,
+ const char *domain,
+ const char *service,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSocketConnectable *connectable;
+
+ connectable = g_network_service_new (service, "tcp", domain);
+ 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.
@@ -902,3 +974,24 @@ g_socket_client_connect_to_host_finish (GSocketClient *client,
{
return g_socket_client_connect_finish (client, result, error);
}
+
+/**
+ * g_socket_client_connect_to_service_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_service_async()
+ *
+ * Returns: a #GSocketConnection on success, %NULL on error.
+ *
+ * Since: 2.22
+ **/
+GSocketConnection *
+g_socket_client_connect_to_service_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 11146e0..ce9bdf1 100644
--- a/gio/gsocketclient.h
+++ b/gio/gsocketclient.h
@@ -101,6 +101,11 @@ GSocketConnection * g_socket_client_connect_to_host (GSocket
int port,
GCancellable *cancellable,
GError **error);
+GSocketConnection * g_socket_client_connect_to_service (GSocketClient *client,
+ const char *domain,
+ const char *service,
+ GCancellable *cancellable,
+ GError **error);
void g_socket_client_connect_async (GSocketClient *client,
GSocketConnectable *connectable,
GCancellable *cancellable,
@@ -119,6 +124,16 @@ GSocketConnection * g_socket_client_connect_to_host_finish (GSocket
GAsyncResult *result,
GError **error);
+void g_socket_client_connect_to_service_async (GSocketClient *client,
+ const char *domain,
+ const char *service,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+GSocketConnection * g_socket_client_connect_to_service_finish (GSocketClient *client,
+ GAsyncResult *result,
+ GError **error);
+
G_END_DECLS
#endif /* __G_SOCKET_CLIENT_H___ */