SocketConnectableIF

Objects that describe one or more potential socket endpoints implement GSocketConnectable Callers can then use Socket.connectableEnumerate to get a gio.SocketAddressEnumerator to try out each socket address in turn until one succeeds, as shown in the sample code below.

1 
2 MyConnectionType *
3 connect_to_host (const char    *hostname,
4 guint16        port,
5 GCancellable  *cancellable,
6 GError       **error)
7 {
8 MyConnection *conn = NULL;
9 GSocketConnectable *addr;
10 GSocketAddressEnumerator *enumerator;
11 GSocketAddress *sockaddr;
12 GError *conn_error = NULL;
13 
14 addr = g_network_address_new (hostname, port);
15 enumerator = g_socket_connectable_enumerate (addr);
16 g_object_unref (addr);
17 
18 // Try each sockaddr until we succeed. Record the first connection error,
19 // but not any further ones (since they'll probably be basically the same
20 // as the first).
21 while (!conn && (sockaddr = g_socket_address_enumerator_next (enumerator, cancellable, error))
22 {
23 conn = connect_to_sockaddr (sockaddr, conn_error ? NULL : &conn_error);
24 g_object_unref (sockaddr);
25 }
26 g_object_unref (enumerator);
27 
28 if (conn)
29 {
30 if (conn_error)
31 {
32 // We couldn't connect to the first address, but we succeeded
33 // in connecting to a later address.
34 g_error_free (conn_error);
35 }
36 return conn;
37 }
38 else if (error)
39 {
40 /// Either initial lookup failed, or else the caller cancelled us.
41 if (conn_error)
42 g_error_free (conn_error);
43 return NULL;
44 }
45 else
46 {
47 g_error_propagate (error, conn_error);
48 return NULL;
49 }
50 }

Members

Functions

enumerate
SocketAddressEnumerator enumerate()

Creates a gio.SocketAddressEnumerator for connectable.

getSocketConnectableStruct
GSocketConnectable* getSocketConnectableStruct(bool transferOwnership = false)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

proxyEnumerate
SocketAddressEnumerator proxyEnumerate()

Creates a gio.SocketAddressEnumerator for connectable that will return GProxyAddresses for addresses that you must connect to via a proxy.

toString
string toString()

Format a GSocketConnectable as a string. This is a human-readable format for use in debugging output, and is not a stable serialization format. It is not suitable for use in user interfaces as it exposes too much information for a user.

Static functions

getType
GType getType()

Meta