GThreadedSocketService: GIO Reference Manual

## GThreadedSocketService GThreadedSocketService — A threaded GSocketService |

## Functions

GSocketService * | g_threaded_socket_service_new ()

## Properties

gint | max-threads | Read / Write / Construct Only

## Signals

gboolean | run | Run Last

## Types and Values

| GThreadedSocketService

## Object Hierarchy

        GObject
        ╰── GSocketListener
            ╰── GSocketService
                ╰── GThreadedSocketService

## Includes

    #include <gio/gio.h>

## Description

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 “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 “run”, or subclass and override the default handler.

## Functions

### g_threaded_socket_service_new ()

    GSocketService *
    g_threaded_socket_service_new (int max_threads);

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

#### Parameters

max_threads | the maximal number of threads to execute concurrently handling incoming clients, -1 means no limit |

#### Returns

a new GSocketService.

Since: 2.22

## Types and Values

### GThreadedSocketService

    typedef struct _GThreadedSocketService GThreadedSocketService;

A helper class for handling accepting incoming connections in the glib mainloop and handling them in a thread.

Since: 2.22

## Property Details

### The `“max-threads”` property

      “max-threads”              gint

The max number of threads handling clients for this service.

Flags: Read / Write / Construct Only

Allowed values: >= -1

Default value: 10

## Signal Details

### The `“run”` signal

    gboolean
    user_function (GThreadedSocketService *service,
                   GSocketConnection      *connection,
                   GObject                *source_object,
                   gpointer                user_data)

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.

#### Parameters

service | the GThreadedSocketService. |
connection | a new GSocketConnection object. |
source_object | the source_object passed to `g_socket_listener_add_address()`. |
user_data | user data set when the signal handler was connected. |

#### Returns

`TRUE` to stop further signal handlers from being called

Flags: Run Last

## See Also

GSocketService.