Gio.SocketService

g GObject.Object GObject.Object Gio.SocketListener Gio.SocketListener GObject.Object->Gio.SocketListener Gio.SocketService Gio.SocketService Gio.SocketListener->Gio.SocketService

Subclasses:Gio.ThreadedSocketService

Methods

Inherited:Gio.SocketListener (13), GObject.Object (37)
Structs:GObject.ObjectClass (5)
class new ()
  is_active ()
  start ()
  stop ()

Virtual Methods

Inherited:Gio.SocketListener (2), GObject.Object (7)
  do_incoming (connection, source_object)

Properties

Inherited:Gio.SocketListener (1)
Name Type Flags Short Description
active bool r/w/c Whether the service is currently accepting connections

Signals

Inherited:Gio.SocketListener (1), GObject.Object (1)
Name Short Description
incoming The ::incoming signal is emitted when a new incoming connection to service needs to be handled.

Fields

Inherited:Gio.SocketListener (1), GObject.Object (1)
Name Type Access Description
parent_instance Gio.SocketListener r  

Class Details

class Gio.SocketService(**kwargs)
Bases:Gio.SocketListener
Abstract:No
Structure:Gio.SocketServiceClass

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 Gio.SocketService ::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 Gio.SocketService.new() and to connect to the Gio.SocketService ::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.

New in version 2.22.

classmethod new()[source]
Returns:a new Gio.SocketService.
Return type:Gio.SocketService

Creates a new Gio.SocketService with no sockets to listen for. New listeners can be added with e.g. Gio.SocketListener.add_address() or Gio.SocketListener.add_inet_port().

New services are created active, there is no need to call Gio.SocketService.start(), unless Gio.SocketService.stop() has been called before.

New in version 2.22.

is_active()[source]
Returns:True if the service is active, False otherwise
Return type:bool

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.

New in version 2.22.

start()[source]

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 Gio.SocketService.stop().

This call is thread-safe, so it may be called from a thread handling an incoming client request.

New in version 2.22.

stop()[source]

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

This call is thread-safe, so it may be called from a thread handling an incoming client request.

Note that this only stops accepting new connections; it does not close the listening sockets, and you can call Gio.SocketService.start() again later to begin listening again. To close the listening sockets, call Gio.SocketListener.close(). (This will happen automatically when the Gio.SocketService is finalized.)

This must be called before calling Gio.SocketListener.close() as the socket service will start accepting connections immediately when a new socket is added.

New in version 2.22.

do_incoming(connection, source_object) virtual
Parameters:
Return type:

bool

Signal Details

Gio.SocketService.signals.incoming(socket_service, connection, source_object)
Signal Name:

incoming

Flags:

RUN_LAST

Parameters:
Returns:

True to stop other handlers from being called

Return type:

bool

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.

connection will be unreffed once the signal handler returns, so you need to ref it yourself if you are planning to use it.

New in version 2.22.

Property Details

Gio.SocketService.props.active
Name:active
Type:bool
Default Value:True
Flags:READABLE, WRITABLE, CONSTRUCT

Whether the service is currently accepting connections.

New in version 2.46.