Functions
g_socket_client_connect_to_host ()
GSocketConnection *
g_socket_client_connect_to_host (GSocketClient *client,
const gchar *host_and_port,
guint16 default_port,
GCancellable *cancellable,
GError **error);
This is a helper function for g_socket_client_connect().
Attempts to create a TCP connection to the named host.
host_and_port
may be in any of a number of recognized formats; an IPv6
address, an IPv4 address, or a domain name (in which case a DNS
lookup is performed). Quoting with [] is supported for all address
types. A port override may be specified in the usual way with a
colon. Ports may be given as decimal numbers or symbolic names (in
which case an /etc/services lookup is performed).
If no port override is given in host_and_port
then default_port
will be
used as the port number to connect to.
In general, host_and_port
is expected to be provided by the user (allowing
them to give the hostname, and a port override if necessary) and
default_port
is expected to be provided by the application.
In the case that an IP address is given, a single connection
attempt is made. In the case that a name is given, multiple
connection attempts may be made, in turn and according to the
number of address records in DNS, until a connection succeeds.
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.
Since: 2.22
g_socket_client_connect_to_service ()
GSocketConnection *
g_socket_client_connect_to_service (GSocketClient *client,
const gchar *domain,
const gchar *service,
GCancellable *cancellable,
GError **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.
g_socket_client_connect_to_uri ()
GSocketConnection *
g_socket_client_connect_to_uri (GSocketClient *client,
const gchar *uri,
guint16 default_port,
GCancellable *cancellable,
GError **error);
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. TLS will be negotiated if “tls” is TRUE.
(GSocketClient does not know to automatically assume TLS for
certain URI schemes.)
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.
Since: 2.26
g_socket_client_set_family ()
void
g_socket_client_set_family (GSocketClient *client,
GSocketFamily family);
Sets the socket family of the socket client.
If this is set to something other than G_SOCKET_FAMILY_INVALID
then the sockets created by this object will be of the specified
family.
This might be useful for instance if you want to force the local
connection to be an ipv4 socket, even though the address might
be an ipv6 mapped to ipv4 address.
Since: 2.22
g_socket_client_set_local_address ()
void
g_socket_client_set_local_address (GSocketClient *client,
GSocketAddress *address);
Sets the local address of the socket client.
The sockets created by this object will bound to the
specified address (if not NULL) before connecting.
This is useful if you want to ensure that the local
side of the connection is on a specific port, or on
a specific interface.
Since: 2.22
g_socket_client_set_protocol ()
void
g_socket_client_set_protocol (GSocketClient *client,
GSocketProtocol protocol);
Sets the protocol of the socket client.
The sockets created by this object will use of the specified
protocol.
If protocol
is G_SOCKET_PROTOCOL_DEFAULT that means to use the default
protocol for the socket family and type.
Since: 2.22
g_socket_client_set_socket_type ()
void
g_socket_client_set_socket_type (GSocketClient *client,
GSocketType type);
Sets the socket type of the socket client.
The sockets created by this object will be of the specified
type.
It doesn't make sense to specify a type of G_SOCKET_TYPE_DATAGRAM,
as GSocketClient is used for connection oriented services.
Since: 2.22
g_socket_client_set_timeout ()
void
g_socket_client_set_timeout (GSocketClient *client,
guint timeout);
Sets the I/O timeout for sockets created by client
. timeout
is a
time in seconds, or 0 for no timeout (the default).
The timeout value affects the initial connection attempt as well,
so setting this may cause calls to g_socket_client_connect(), etc,
to fail with G_IO_ERROR_TIMED_OUT.
Since: 2.26
g_socket_client_set_enable_proxy ()
void
g_socket_client_set_enable_proxy (GSocketClient *client,
gboolean enable);
Sets whether or not client
attempts to make connections via a
proxy server. When enabled (the default), GSocketClient will use a
GProxyResolver to determine if a proxy protocol such as SOCKS is
needed, and automatically do the necessary proxy negotiation.
See also g_socket_client_set_proxy_resolver().
Since: 2.26
g_socket_client_set_proxy_resolver ()
void
g_socket_client_set_proxy_resolver (GSocketClient *client,
GProxyResolver *proxy_resolver);
Overrides the GProxyResolver used by client
. You can call this if
you want to use specific proxies, rather than using the system
default proxy settings.
Note that whether or not the proxy resolver is actually used
depends on the setting of “enable-proxy”, which is not
changed by this function (but which is TRUE by default)
Since: 2.36
g_socket_client_get_timeout ()
guint
g_socket_client_get_timeout (GSocketClient *client);
Gets the I/O timeout time for sockets created by client
.
See g_socket_client_set_timeout() for details.
Returns
the timeout in seconds
Since: 2.26
g_socket_client_get_tls ()
gboolean
g_socket_client_get_tls (GSocketClient *client);
Gets whether client
creates TLS connections. See
g_socket_client_set_tls() for details.
Returns
whether client
uses TLS
Since: 2.28
g_socket_client_get_tls_validation_flags ()
GTlsCertificateFlags
g_socket_client_get_tls_validation_flags
(GSocketClient *client);
Gets the TLS validation flags used creating TLS connections via
client
.
Returns
the TLS validation flags
Since: 2.28
g_socket_client_add_application_proxy ()
void
g_socket_client_add_application_proxy (GSocketClient *client,
const gchar *protocol);
Enable proxy protocols to be handled by the application. When the
indicated proxy protocol is returned by the GProxyResolver,
GSocketClient will consider this protocol as supported but will
not try to find a GProxy instance to handle handshaking. The
application must check for this case by calling
g_socket_connection_get_remote_address() on the returned
GSocketConnection, and seeing if it's a GProxyAddress of the
appropriate type, to determine whether or not it needs to handle
the proxy handshaking itself.
This should be used for proxy protocols that are dialects of
another protocol such as HTTP proxy. It also allows cohabitation of
proxy protocols that are reused between protocols. A good example
is HTTP. It can be used to proxy HTTP, FTP and Gopher and can also
be use as generic socket proxy through the HTTP CONNECT method.
When the proxy is detected as being an application proxy, TLS handshake
will be skipped. This is required to let the application do the proxy
specific handshake.