mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-09 19:06:15 +01:00
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>
This commit is contained in:
parent
a6c3820f46
commit
0ebb79a748
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
@ -1254,6 +1307,52 @@ g_socket_client_connect_to_service_async (GSocketClient *client,
|
||||
g_object_unref (connectable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user