SocketConnection

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.

Choosing 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().

Constructors

this
this(GSocketConnection* gSocketConnection)

Sets our main struct and passes it to the parent class

Members

Functions

connect
int connect(SocketAddress address, Cancellable cancellable)

Connect connection to the specified remote address. Since 2.32

connectAsync
void connectAsync(SocketAddress address, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)

Asynchronously connect connection to the specified remote address. This clears the "blocking" flag on connection's underlying socket if it is currently set. Use g_socket_connection_connect_finish() to retrieve the result. Since 2.32

connectFinish
int connectFinish(AsyncResultIF result)

Gets the result of a g_socket_connection_connect_async() call. Since 2.32

getLocalAddress
SocketAddress getLocalAddress()

Try to get the local address of a socket connection. Since 2.22

getRemoteAddress
SocketAddress getRemoteAddress()

Try to get the remote address of a socket connection. Since 2.22

getSocket
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. Since 2.22

getSocketConnectionStruct
GSocketConnection* getSocketConnectionStruct()

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

isConnected
int isConnected()

Checks if connection is connected. This is equivalent to calling g_socket_is_connected() on connection's underlying GSocket. Since 2.32

setStruct
void setStruct(GObject* obj)
Undocumented in source. Be warned that the author may not have intended to support it.

Static functions

factoryCreateConnection
SocketConnection factoryCreateConnection(Socket socket)

Creates a GSocketConnection subclass of the right type for socket. Since 2.22

factoryLookupType
GType factoryLookupType(GSocketFamily family, GSocketType type, int protocolId)

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. Since 2.22

factoryRegisterType
void factoryRegisterType(GType gType, GSocketFamily family, GSocketType type, int 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. Since 2.22

Variables

gSocketConnection
GSocketConnection* gSocketConnection;

the main Gtk struct

Inherited Members

From IOStream

gIOStream
GIOStream* gIOStream;

the main Gtk struct

getIOStreamStruct
GIOStream* getIOStreamStruct()

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

setStruct
void setStruct(GObject* obj)
Undocumented in source. Be warned that the author may not have intended to support it.
getInputStream
InputStream getInputStream()

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

getOutputStream
OutputStream getOutputStream()

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

spliceAsync
void spliceAsync(IOStream stream2, GIOStreamSpliceFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)

Asyncronously 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. When the operation is finished callback will be called. You can then call g_io_stream_splice_finish() to get the result of the operation. Since 2.28

spliceFinish
int spliceFinish(AsyncResultIF result)

Finishes an asynchronous io stream splice operation. Since 2.28

close
int close(Cancellable cancellable)

Closes the stream, releasing resources related to it. This will also closes the individual input and output streams, if they are not already closed. Once the stream is closed, all other operations will return G_IO_ERROR_CLOSED. Closing a stream multiple times will not return an error. Closing a stream will automatically flush any outstanding buffers in the stream. Streams will be automatically closed when the last reference is dropped, but you might want to call this function to make sure resources are released as early as possible. Some streams might keep the backing store of the stream (e.g. a file descriptor) open after the stream is closed. See the documentation for the individual stream for details. On failure the first error that happened will be reported, but the close operation will finish as much as possible. A stream that failed to close will still return G_IO_ERROR_CLOSED for all operations. Still, it is important to check and report the error to the user, otherwise there might be a loss of data as all data might not be written. If cancellable is not NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error G_IO_ERROR_CANCELLED will be returned. Cancelling a close will still leave the stream closed, but some streams can use a faster close that doesn't block to e.g. check errors. The default implementation of this method just calls close on the individual input/output streams. Since 2.22

closeAsync
void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)

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 g_io_stream_close_finish() to get the result of the operation. For behaviour details see g_io_stream_close(). The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all. Since 2.22

closeFinish
int closeFinish(AsyncResultIF result)

Closes a stream. Since 2.22

isClosed
int isClosed()

Checks if a stream is closed. Since 2.22

hasPending
int hasPending()

Checks if a stream has pending actions. Since 2.22

setPending
int 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. Since 2.22

clearPending
void clearPending()

Clears the pending flag on stream. Since 2.22

Meta