SocketService

A gio.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 incoming signal is emitted.

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

There are two options for implementing a network service based on gio.SocketService The first is to create the service using Socket.serviceNew and to connect to the incoming signal. The second is to subclass gio.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.ThreadedSocketService

The socket service runs on the main loop of the [thread-default context][g-main-context-push-thread-default-context] 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(GSocketService* gSocketService, bool ownedRef)

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

this
this()

Creates a new gio.SocketService with no sockets to listen for. New listeners can be added with e.g. Socket.listenerAddAddress or Socket.listenerAddInetPort.

Members

Functions

addOnIncoming
gulong addOnIncoming(bool delegate(SocketConnection, ObjectG, SocketService) dlg, ConnectFlags connectFlags)

The ::incoming signal is emitted when a new incoming connection to service needs to be handled. The handler must initiate the handling of connection, but may not block; in essence, asynchronous operations must be used.

getSocketServiceStruct
GSocketService* getSocketServiceStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

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 Socket.serviceStop.

stop
void stop()

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

Static functions

getType
GType getType()

Variables

gSocketService
GSocketService* gSocketService;

the main Gtk struct

Inherited Members

From SocketListener

gSocketListener
GSocketListener* gSocketListener;

the main Gtk struct

getSocketListenerStruct
GSocketListener* getSocketListenerStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

getType
GType getType()
accept
SocketConnection accept(ObjectG sourceObject, Cancellable cancellable)

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

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

This is the asynchronous version of Socket.listenerAccept.

acceptFinish
SocketConnection acceptFinish(AsyncResultIF result, ObjectG sourceObject)

Finishes an async accept operation. See Socket.listenerAcceptAsync

acceptSocket
Socket acceptSocket(ObjectG sourceObject, Cancellable cancellable)

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

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

This is the asynchronous version of Socket.listenerAcceptSocket.

acceptSocketFinish
Socket acceptSocketFinish(AsyncResultIF result, ObjectG sourceObject)

Finishes an async accept operation. See Socket.listenerAcceptSocketAsync

addAddress
bool addAddress(SocketAddress address, GSocketType type, GSocketProtocol protocol, ObjectG sourceObject, 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 Socket.listenerAddAddress that creates a TCP/IP socket listening on IPv4 and IPv6 (if supported) on the specified port on all interfaces.

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.

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 gio.SocketListener (for example, by calling Socket.listenerAddInetPort) to be effective.

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

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.

Meta

Since

2.22