SocketConnection

gio.socket_connection.SocketConnection is a gio.iostream.IOStream for a connected socket. They can be created either by gio.socket_client.SocketClient when connecting to a host, or by gio.socket_listener.SocketListener when accepting a new client.

The type of the gio.socket_connection.SocketConnection 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 gio.tcp_connection.TcpConnection.

Choosing what type of object to construct is done with the socket connection factory, and it is possible for third parties to register custom socket connection types for specific combination of socket family/type/protocol using gio.socket_connection.SocketConnection.factoryRegisterType.

To close a gio.socket_connection.SocketConnection, use gio.iostream.IOStream.close. Closing both substreams of the gio.iostream.IOStream separately will not close the underlying gio.socket.Socket.

Members

Functions

connect
bool connect(gio.socket_address.SocketAddress address, gio.cancellable.Cancellable cancellable)

Connect connection to the specified remote address.

connectAsync
void connectAsync(gio.socket_address.SocketAddress address, gio.cancellable.Cancellable cancellable, gio.types.AsyncReadyCallback callback)

Asynchronously connect connection to the specified remote address.

connectFinish
bool connectFinish(gio.async_result.AsyncResult result)

Gets the result of a gio.socket_connection.SocketConnection.connectAsync call.

getLocalAddress
gio.socket_address.SocketAddress getLocalAddress()

Try to get the local address of a socket connection.

getRemoteAddress
gio.socket_address.SocketAddress getRemoteAddress()

Try to get the remote address of a socket connection.

getSocket
gio.socket.Socket getSocket()

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.

isConnected
bool isConnected()

Checks if connection is connected. This is equivalent to calling gio.socket.Socket.isConnected on connection's underlying #GSocket.

Static functions

factoryLookupType
gobject.types.GType factoryLookupType(gio.types.SocketFamily family, gio.types.SocketType type, int protocolId)

Looks up the #GType to be used when creating socket connections on sockets with the specified family, type and protocol_id.

factoryRegisterType
void factoryRegisterType(gobject.types.GType gType, gio.types.SocketFamily family, gio.types.SocketType type, int protocol)

Looks up the #GType to be used when creating socket connections on sockets with the specified family, type and protocol.

Inherited Members

From IOStream

spliceFinish
bool spliceFinish(gio.async_result.AsyncResult result)

Finishes an asynchronous io stream splice operation.

clearPending
void clearPending()

Clears the pending flag on stream.

close
bool close(gio.cancellable.Cancellable cancellable)

Closes the stream, releasing resources related to it. This will also close the individual input and output streams, if they are not already closed.

closeAsync
void closeAsync(int ioPriority, gio.cancellable.Cancellable cancellable, gio.types.AsyncReadyCallback callback)

Requests an asynchronous close of the stream, releasing resources related to it. When the operation is finished callback will be called. You can then call gio.iostream.IOStream.closeFinish to get the result of the operation.

closeFinish
bool closeFinish(gio.async_result.AsyncResult result)

Closes a stream.

getInputStream
gio.input_stream.InputStream getInputStream()

Gets the input stream for this object. This is used for reading.

getOutputStream
gio.output_stream.OutputStream getOutputStream()

Gets the output stream for this object. This is used for writing.

hasPending
bool hasPending()

Checks if a stream has pending actions.

isClosed
bool isClosed()

Checks if a stream is closed.

setPending
bool setPending()

Sets stream to have actions pending. If the pending flag is already set or stream is closed, it will return false and set error.

spliceAsync
void spliceAsync(gio.iostream.IOStream stream2, gio.types.IOStreamSpliceFlags flags, int ioPriority, gio.cancellable.Cancellable cancellable, gio.types.AsyncReadyCallback callback)

Asynchronously splice the output stream of stream1 to the input stream of stream2, and splice the output stream of stream2 to the input stream of stream1.