Gio.SocketService
Description: Reference for Gio.SocketService

### Class

# GioSocketService

since: 2.22

#### Description [src]

    class Gio.SocketService : Gio.SocketListener
    {
      priv: GSocketServicePrivate*
    }

A `GSocketService` 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 `GSocketService::incoming` signal is emitted.

A `GSocketService` is a subclass of `GSocketListener` and you need to add the addresses you want to accept connections on with the `GSocketListener` APIs.

There are two options for implementing a network service based on `GSocketService`. The first is to create the service using `g_socket_service_new()` and to connect to the `GSocketService::incoming` signal. The second is to subclass `GSocketService` 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 `GThreadedSocketService`.

The socket service runs on the main loop of the thread-default context (see `g_main_context_push_thread_default()`) 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.

Available since: 2.22

#### Hierarchy

#### Ancestors

- GSocketListener
- GObject

#### Descendants

- GThreadedSocketService

#### Constructors

###### g_socket_service_new

Creates a new `GSocketService` with no sockets to listen for. New listeners can be added with e.g. `g_socket_listener_add_address()` or g_socket_listener_add_inet_port().

since: 2.22

#### Instance methods

###### g_socket_service_is_active

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.

since: 2.22

###### g_socket_service_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().

since: 2.22

###### g_socket_service_stop

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

since: 2.22

##### Methods inherited from GSocketListener (12)

###### g_socket_listener_accept

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.

since: 2.22

###### g_socket_listener_accept_async

This is the asynchronous version of g_socket_listener_accept().

since: 2.22

###### g_socket_listener_accept_finish

Finishes an async accept operation. See g_socket_listener_accept_async().

since: 2.22

###### g_socket_listener_accept_socket

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

since: 2.22

###### g_socket_listener_accept_socket_async

This is the asynchronous version of g_socket_listener_accept_socket().

since: 2.22

###### g_socket_listener_accept_socket_finish

Finishes an async accept operation. See g_socket_listener_accept_socket_async().

since: 2.22

###### g_socket_listener_add_address

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.

since: 2.22

###### g_socket_listener_add_any_inet_port

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

since: 2.24

###### g_socket_listener_add_inet_port

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.

since: 2.22

###### g_socket_listener_add_socket

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.

since: 2.22

###### g_socket_listener_close

Closes all the sockets in the listener.

since: 2.22

###### g_socket_listener_set_backlog

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.

since: 2.22

##### Methods inherited from GObject (43)

Please see GObject for a full list of methods.

#### Properties

###### Gio.SocketService:active

Whether the service is currently accepting connections.

since: 2.46

##### Properties inherited from GSocketListener (1)

###### Gio.SocketListener:listen-backlog

The number of outstanding connections in the listen queue.

since: 2.22

#### Signals

###### Gio.SocketService::incoming

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.

since: 2.22

##### Signals inherited from GSocketListener (1)

###### GSocketListener::event

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.

since: 2.46

##### Signals inherited from GObject (1)

###### GObject::notify

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

#### Class structure

    struct GioSocketServiceClass {
      GSocketListenerClass parent_class;
      gboolean (* incoming) (
        GSocketService* service,
        GSocketConnection* connection,
        GObject* source_object
      );
      void (* _g_reserved1) (
    void
      );
      void (* _g_reserved2) (
    void
      );
      void (* _g_reserved3) (
    void
      );
      void (* _g_reserved4) (
    void
      );
      void (* _g_reserved5) (
    void
      );
      void (* _g_reserved6) (
    void
      );

    }

Class structure for `GSocketService`.

###### Class members

`parent_class: GSocketListenerClass`

  No description available.

`incoming: gboolean (* incoming) ( GSocketService* service, GSocketConnection* connection, GObject* source_object )`

  Signal emitted when new connections are accepted.

`_g_reserved1: void (* _g_reserved1) ( void )`

  No description available.

`_g_reserved2: void (* _g_reserved2) ( void )`

  No description available.

`_g_reserved3: void (* _g_reserved3) ( void )`

  No description available.

`_g_reserved4: void (* _g_reserved4) ( void )`

  No description available.

`_g_reserved5: void (* _g_reserved5) ( void )`

  No description available.

`_g_reserved6: void (* _g_reserved6) ( void )`

  No description available.

#### Virtual methods

###### Gio.SocketServiceClass.incoming

Signal emitted when new connections are accepted.