|  |  |  | GIO Reference Manual |  | 
|---|---|---|---|---|
| Top | Description | Object Hierarchy | Properties | ||||
#include <gio/gio.h>
                    GSocketConnection;
GSocketAddress *    g_socket_connection_get_local_address
                                                        (GSocketConnection *connection,
                                                         GError **error);
GSocketAddress *    g_socket_connection_get_remote_address
                                                        (GSocketConnection *connection,
                                                         GError **error);
GSocket *           g_socket_connection_get_socket      (GSocketConnection *connection);
                    GTcpConnection;
void                g_tcp_connection_set_graceful_disconnect
                                                        (GTcpConnection *connection,
                                                         gboolean graceful_disconnect);
gboolean            g_tcp_connection_get_graceful_disconnect
                                                        (GTcpConnection *connection);
                    GUnixConnection;
gint                g_unix_connection_receive_fd        (GUnixConnection *connection,
                                                         GCancellable *cancellable,
                                                         GError **error);
gboolean            g_unix_connection_send_fd           (GUnixConnection *connection,
                                                         gint fd,
                                                         GCancellable *cancellable,
                                                         GError **error);
GCredentials *      g_unix_connection_receive_credentials
                                                        (GUnixConnection *connection,
                                                         GCancellable *cancellable,
                                                         GError **error);
gboolean            g_unix_connection_send_credentials  (GUnixConnection *connection,
                                                         GCancellable *cancellable,
                                                         GError **error);
GSocketConnection * g_socket_connection_factory_create_connection
                                                        (GSocket *socket);
GType               g_socket_connection_factory_lookup_type
                                                        (GSocketFamily family,
                                                         GSocketType type,
                                                         gint protocol_id);
void                g_socket_connection_factory_register_type
                                                        (GType g_type,
                                                         GSocketFamily family,
                                                         GSocketType type,
                                                         gint protocol);
GObject +----GIOStream +----GSocketConnection +----GTcpConnection +----GUnixConnection
GObject +----GIOStream +----GSocketConnection +----GTcpConnection
GObject +----GIOStream +----GSocketConnection +----GUnixConnection
"socket" GSocket* : Read / Write / Construct Only "graceful-disconnect" gboolean : Read / Write
GSocketConnection is a GIOStream for a connected socket. They can be created either by GSocketClient when connecting to a host, or by GSocketListener when accepting a new client.
The type of the GSocketConnection object returned from these calls depends on the type of the underlying socket that is in use. For instance, for a TCP/IP connection it will be a GTcpConnection.
Chosing what type of object to construct is done with the socket
connection factory, and it is possible for 3rd parties to register
custom socket connection types for specific combination of socket
family/type/protocol using g_socket_connection_factory_register_type().
typedef struct _GSocketConnection GSocketConnection;
A socket connection GIOStream object for connection-oriented sockets.
Since 2.22
GSocketAddress * g_socket_connection_get_local_address (GSocketConnection *connection,GError **error);
Try to get the local address of a socket connection.
| 
 | a GSocketConnection | 
| 
 | GError for error reporting, or NULLto ignore. | 
| Returns : | a GSocketAddress or NULLon error.
    Free the returned object withg_object_unref(). | 
Since 2.22
GSocketAddress * g_socket_connection_get_remote_address (GSocketConnection *connection,GError **error);
Try to get the remote address of a socket connection.
| 
 | a GSocketConnection | 
| 
 | GError for error reporting, or NULLto ignore. | 
| Returns : | a GSocketAddress or NULLon error.
    Free the returned object withg_object_unref(). | 
Since 2.22
GSocket *           g_socket_connection_get_socket      (GSocketConnection *connection);
Gets the underlying GSocket object of the connection. This can be useful if you want to do something unusual on it not supported by the GSocketConnection APIs.
| 
 | a GSocketConnection | 
| Returns : | a GSocketAddress or NULLon error. | 
Since 2.22
typedef struct _GTcpConnection GTcpConnection;
A GSocketConnection for TCP/IP connections.
Since 2.22
void g_tcp_connection_set_graceful_disconnect (GTcpConnection *connection,gboolean graceful_disconnect);
This enabled graceful disconnects on close. A graceful disconnect means that we signal the recieving end that the connection is terminated and wait for it to close the connection before closing the connection.
A graceful disconnect means that we can be sure that we successfully sent all the outstanding data to the other end, or get an error reported. However, it also means we have to wait for all the data to reach the other side and for it to acknowledge this by closing the socket, which may take a while. For this reason it is disabled by default.
| 
 | a GTcpConnection | 
| 
 | Whether to do graceful disconnects or not | 
Since 2.22
gboolean            g_tcp_connection_get_graceful_disconnect
                                                        (GTcpConnection *connection);
Checks if graceful disconnects are used. See
g_tcp_connection_set_graceful_disconnect().
| 
 | a GTcpConnection | 
| Returns : | TRUEif graceful disconnect is used on close,FALSEotherwise | 
Since 2.22
gint g_unix_connection_receive_fd (GUnixConnection *connection,GCancellable *cancellable,GError **error);
Receives a file descriptor from the sending end of the connection.
The sending end has to call g_unix_connection_send_fd() for this
to work.
As well as reading the fd this also reads a single byte from the stream, as this is required for fd passing to work on some implementations.
| 
 | a GUnixConnection | 
| 
 | optional GCancellable object, NULLto ignore | 
| 
 | GError for error reporting, or NULLto ignore | 
| Returns : | a file descriptor on success, -1 on error. | 
Since 2.22
gboolean g_unix_connection_send_fd (GUnixConnection *connection,gint fd,GCancellable *cancellable,GError **error);
Passes a file descriptor to the recieving side of the
connection. The recieving end has to call g_unix_connection_receive_fd()
to accept the file descriptor.
As well as sending the fd this also writes a single byte to the stream, as this is required for fd passing to work on some implementations.
| 
 | a GUnixConnection | 
| 
 | a file descriptor | 
| 
 | optional GCancellable object, NULLto ignore. | 
| 
 | GError for error reporting, or NULLto ignore. | 
| Returns : | a TRUEon success,NULLon error. | 
Since 2.22
GCredentials * g_unix_connection_receive_credentials (GUnixConnection *connection,GCancellable *cancellable,GError **error);
Receives credentials from the sending end of the connection.  The
sending end has to call g_unix_connection_send_credentials() (or
similar) for this to work.
As well as reading the credentials this also reads (and discards) a single byte from the stream, as this is required for credentials passing to work on some implementations.
| 
 | A GUnixConnection. | 
| 
 | A GCancellable or NULL. | 
| 
 | Return location for error or NULL. | 
| Returns : | Received credentials on success (free with g_object_unref()),NULLiferroris set. | 
Since 2.26
gboolean g_unix_connection_send_credentials (GUnixConnection *connection,GCancellable *cancellable,GError **error);
Passes the credentials of the current user the receiving side
of the connection. The recieving end has to call
g_unix_connection_receive_credentials() (or similar) to accept the
credentials.
As well as sending the credentials this also writes a single NUL byte to the stream, as this is required for credentials passing to work on some implementations.
Note that this function only works on Linux, currently.
| 
 | A GUnixConnection. | 
| 
 | A GCancellable or NULL. | 
| 
 | Return location for error or NULL. | 
| Returns : | TRUEon success,FALSEiferroris set. | 
Since 2.26
GSocketConnection * g_socket_connection_factory_create_connection
                                                        (GSocket *socket);
Creates a GSocketConnection subclass of the right type for
socket.
| 
 | a GSocket | 
| Returns : | a GSocketConnection | 
Since 2.22
GType g_socket_connection_factory_lookup_type (GSocketFamily family,GSocketType type,gint protocol_id);
Looks up the GType to be used when creating socket connections on
sockets with the specified family,type and protocol_id.
If no type is registered, the GSocketConnection base type is returned.
| 
 | a GSocketFamily | 
| 
 | a GSocketType | 
| 
 | a protocol id | 
| Returns : | a GType | 
Since 2.22
void g_socket_connection_factory_register_type (GType g_type,GSocketFamily family,GSocketType type,gint protocol);
Looks up the GType to be used when creating socket connections on
sockets with the specified family,type and protocol.
If no type is registered, the GSocketConnection base type is returned.
| 
 | a GType, inheriting from G_TYPE_SOCKET_CONNECTION | 
| 
 | a GSocketFamily | 
| 
 | a GSocketType | 
| 
 | a protocol id | 
Since 2.22
"graceful-disconnect" property"graceful-disconnect" gboolean : Read / Write
Whether or not close does a graceful disconnect.
Default value: FALSE