SocketListener

A GSocketListener is an object that keeps track of a set of server sockets and helps you accept sockets from any of the socket, either sync or async.

Add addresses and ports to listen on using g_socket_listener_add_address() and g_socket_listener_add_inet_port(). These will be listened on until g_socket_listener_close() is called. Dropping your final reference to the GSocketListener will not cause g_socket_listener_close() to be called implicitly, as some references to the GSocketListener may be held internally.

If you want to implement a network server, also look at GSocketService and GThreadedSocketService which are subclasses of GSocketListener that make this even easier.

Constructors

this
this(GSocketListener* gSocketListener, bool ownedRef = false)

Sets our main struct and passes it to the parent class.

this
this()

Creates a new GSocketListener with no sockets to listen for. New listeners can be added with e.g. g_socket_listener_add_address() or g_socket_listener_add_inet_port().

Members

Functions

accept
SocketConnection accept(out ObjectG sourceObject, Cancellable cancellable)

Blocks waiting for a client to connect to any of the sockets added to the listener. Returns a GSocketConnection for the socket that was accepted.

acceptAsync
void acceptAsync(Cancellable cancellable, GAsyncReadyCallback callback, void* userData)

This is the asynchronous version of g_socket_listener_accept().

acceptFinish
SocketConnection acceptFinish(AsyncResultIF result, out ObjectG sourceObject)

Finishes an async accept operation. See g_socket_listener_accept_async()

acceptSocket
Socket acceptSocket(out ObjectG sourceObject, Cancellable cancellable)

Blocks waiting for a client to connect to any of the sockets added to the listener. Returns the GSocket that was accepted.

acceptSocketAsync
void acceptSocketAsync(Cancellable cancellable, GAsyncReadyCallback callback, void* userData)

This is the asynchronous version of g_socket_listener_accept_socket().

acceptSocketFinish
Socket acceptSocketFinish(AsyncResultIF result, out ObjectG sourceObject)

Finishes an async accept operation. See g_socket_listener_accept_socket_async()

addAddress
bool addAddress(SocketAddress address, GSocketType type, GSocketProtocol protocol, ObjectG sourceObject, out SocketAddress effectiveAddress)

Creates a socket of type type and protocol protocol, binds it to address and adds it to the set of sockets we're accepting sockets from.

addAnyInetPort
ushort addAnyInetPort(ObjectG sourceObject)

Listens for TCP connections on any available port number for both IPv6 and IPv4 (if each is available).

addInetPort
bool addInetPort(ushort port, ObjectG sourceObject)

Helper function for g_socket_listener_add_address() that creates a TCP/IP socket listening on IPv4 and IPv6 (if supported) on the specified port on all interfaces.

addOnEvent
gulong addOnEvent(void delegate(GSocketListenerEvent, Socket, SocketListener) dlg, ConnectFlags connectFlags = cast(ConnectFlags)0)

Emitted when listener's activity on socket changes state. Note that when listener is used to listen on both IPv4 and IPv6, a separate set of signals will be emitted for each, and the order they happen in is undefined.

addSocket
bool addSocket(Socket socket, ObjectG sourceObject)

Adds socket to the set of sockets that we try to accept new clients from. The socket must be bound to a local address and listened to.

close
void close()

Closes all the sockets in the listener.

getSocketListenerStruct
GSocketListener* getSocketListenerStruct(bool transferOwnership = false)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

setBacklog
void setBacklog(int listenBacklog)

Sets the listen backlog on the sockets in the listener.

Static functions

getType
GType getType()

Variables

gSocketListener
GSocketListener* gSocketListener;

the main Gtk struct

Meta

Since

2.22