A GLib::ThreadedSocketService is a simple subclass of GLib::SocketService that handles incoming connections by creating a worker thread and dispatching the connection to it by emitting the ::run signal in the new thread.
The signal handler may perform blocking I/O 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 availible to serve incomming requests. The service automatically stops the GLib::SocketService from accepting new connections when all threads are busy.
As with GLib::SocketService, you may connect to “run”, or subclass and override the default handler.
GLib::ThreadedSocketService.new(max_threads = 10)
Creates a new GThreadedSocketService with no listeners. Listeners must be
added with Glib::SocketService#add_listeners.
- max_threads: the maximum number of threads to execute, concurrently handling incoming clients (-1 for no limit)
- Returns: a new GLib::ThreadedSocketService
Gets the maximum number of threads handling clients for this service.
- Returns: The maximum number of threads handling clients for this service
max-threads: Integer (Read/Write)
The maximum number of threads handling clients for this service
Allowed values: ≥ 0
Default value: 10
run: self, connection, source_object
- The ::run signal is emitted in a worker thread in response to an incoming connection. This thread is dedicated to handling connection and may perform blocking IO. The signal handler need not return until the connection is closed.