SocketService

A gio.socket_service.SocketService is an object that represents a service that is provided to the network or over local sockets. When a new connection is made to the service the gio.socket_service.SocketService.incoming signal is emitted.

A gio.socket_service.SocketService is a subclass of gio.socket_listener.SocketListener and you need to add the addresses you want to accept connections on with the gio.socket_listener.SocketListener APIs.

There are two options for implementing a network service based on gio.socket_service.SocketService. The first is to create the service using gio.socket_service.SocketService.new_ and to connect to the gio.socket_service.SocketService.incoming signal. The second is to subclass gio.socket_service.SocketService and override the default signal handler implementation.

In either case, the handler must immediately return, or else it will block additional incoming connections from being serviced. If you are interested in writing connection handlers that contain blocking code then see gio.threaded_socket_service.ThreadedSocketService.

The socket service runs on the main loop of the thread-default context (see glib.main_context.MainContext.pushThreadDefault) of the thread it is created in, and is not threadsafe in general. However, the calls to start and stop the service are thread-safe so these can be used from threads that handle incoming clients.

Constructors

this
this()

Creates a new #GSocketService with no sockets to listen for. New listeners can be added with e.g. gio.socket_listener.SocketListener.addAddress or gio.socket_listener.SocketListener.addInetPort.

Members

Functions

connectIncoming
ulong connectIncoming(T callback, Flag!"After" after)

Connect to Incoming signal.

isActive
bool isActive()

Check whether the service is active or not. An active service will accept new clients that connect, while a non-active service will let connecting clients queue up until the service is started.

start
void start()

Restarts the service, i.e. start accepting connections from the added sockets when the mainloop runs. This only needs to be called after the service has been stopped from gio.socket_service.SocketService.stop.

stop
void stop()

Stops the service, i.e. stops accepting connections from the added sockets when the mainloop runs.

Inherited Members

From SocketListener

accept
gio.socket_connection.SocketConnection accept(gobject.object.ObjectG sourceObject, gio.cancellable.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(gio.cancellable.Cancellable cancellable, gio.types.AsyncReadyCallback callback)

This is the asynchronous version of gio.socket_listener.SocketListener.accept.

acceptFinish
gio.socket_connection.SocketConnection acceptFinish(gio.async_result.AsyncResult result, gobject.object.ObjectG sourceObject)

Finishes an async accept operation. See gio.socket_listener.SocketListener.acceptAsync

acceptSocket
gio.socket.Socket acceptSocket(gobject.object.ObjectG sourceObject, gio.cancellable.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(gio.cancellable.Cancellable cancellable, gio.types.AsyncReadyCallback callback)

This is the asynchronous version of gio.socket_listener.SocketListener.acceptSocket.

acceptSocketFinish
gio.socket.Socket acceptSocketFinish(gio.async_result.AsyncResult result, gobject.object.ObjectG sourceObject)

Finishes an async accept operation. See gio.socket_listener.SocketListener.acceptSocketAsync

addAddress
bool addAddress(gio.socket_address.SocketAddress address, gio.types.SocketType type, gio.types.SocketProtocol protocol, gobject.object.ObjectG sourceObject, gio.socket_address.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(gobject.object.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, gobject.object.ObjectG sourceObject)

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

addSocket
bool addSocket(gio.socket.Socket socket, gobject.object.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.

setBacklog
void setBacklog(int listenBacklog)

Sets the listen backlog on the sockets in the listener. This must be called before adding any sockets, addresses or ports to the #GSocketListener (for example, by calling gio.socket_listener.SocketListener.addInetPort) to be effective.

connectEvent
ulong connectEvent(T callback, Flag!"After" after)

Connect to Event signal.