ThreadedSocketService

open class ThreadedSocketService(pointer: <Error class: unknown class><<Error class: unknown class>>) : SocketService

A #GThreadedSocketService is a simple subclass of #GSocketService that handles incoming connections by creating a worker thread and dispatching the connection to it by emitting the #GThreadedSocketService::run signal in the new thread.

The signal handler may perform blocking IO and need not return until the connection is closed.

The service is implemented using a thread pool, so there is a limited amount of threads available to serve incoming requests. The service automatically stops the #GSocketService from accepting new connections when all threads are busy.

As with #GSocketService, you may connect to #GThreadedSocketService::run, or subclass and override the default handler.

Skipped during bindings generation

  • method max-threads: Property has no getter nor setter

Since

2.22

Constructors

Link copied to clipboard
constructor(maxThreads: Int)

Creates a new #GThreadedSocketService with no listeners. Listeners must be added with one of the #GSocketListener "add" methods.

constructor(pointer: <Error class: unknown class><<Error class: unknown class>>)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val gioSocketListenerPointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard
val gioSocketServicePointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard
val gioThreadedSocketServicePointer: <Error class: unknown class><<Error class: unknown class>>

Functions

Link copied to clipboard
open fun acceptAsync(cancellable: Cancellable? = null, callback: AsyncReadyCallback)

This is the asynchronous version of g_socket_listener_accept().

Link copied to clipboard
open fun acceptSocketAsync(cancellable: Cancellable? = null, callback: AsyncReadyCallback)

This is the asynchronous version of g_socket_listener_accept_socket().

Link copied to clipboard
open fun addAnyInetPort(sourceObject: <Error class: unknown class>? = null): <Error class: unknown class><<Error class: unknown class>>

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

Link copied to clipboard
open fun addInetPort(port: <Error class: unknown class>, sourceObject: <Error class: unknown class>? = null): <Error class: unknown class><Boolean>

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.

Link copied to clipboard
open fun addSocket(socket: Socket, sourceObject: <Error class: unknown class>? = null): <Error class: unknown class><Boolean>

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.

Link copied to clipboard
open fun close()

Closes all the sockets in the listener.

Link copied to clipboard
fun connectEvent(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: (event: SocketListenerEvent, socket: Socket) -> Unit): <Error class: unknown class>

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.

Link copied to clipboard
fun connectIncoming(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: (connection: SocketConnection, <Error class: unknown class>?) -> Boolean): <Error class: unknown class>

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.

Link copied to clipboard
fun connectRun(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: (connection: SocketConnection, <Error class: unknown class>?) -> Boolean): <Error class: unknown class>

The ::run signal is emitted in a worker thread in response to an incoming connection. This thread is dedicated to handling

Link copied to clipboard
open fun isActive(): Boolean

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.

Link copied to clipboard
open fun setBacklog(listenBacklog: Int)

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 g_socket_listener_add_inet_port()) to be effective.

Link copied to clipboard
open fun 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 g_socket_service_stop().

Link copied to clipboard
open fun stop()

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