Gio.SocketService¶
- Subclasses:
Methods¶
- Inherited:
- Structs:
class |
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/c |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
The |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent_instance |
r |
Class Details¶
- class Gio.SocketService(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
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 [signal`Gio`.SocketService::incoming] signal is emitted.A
GSocketService
is a subclass of [class`Gio`.SocketListener] and you need to add the addresses you want to accept connections on with the [class`Gio`.SocketListener] APIs.There are two options for implementing a network service based on
GSocketService
. The first is to create the service using [ctor`Gio`.SocketService.new] and to connect to the [signal`Gio`.SocketService::incoming] signal. The second is to subclassGSocketService
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 [class`Gio`.ThreadedSocketService].
The socket service runs on the main loop of the thread-default context (see [method`GLib`.MainContext.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.
New in version 2.22.
- classmethod new()[source]¶
- Returns:
a new
Gio.SocketService
.- Return type:
Creates a new
Gio.SocketService
with no sockets to listen for. New listeners can be added with e.g.Gio.SocketListener.add_address
() orGio.SocketListener.add_inet_port
().New services are created active, there is no need to call
Gio.SocketService.start
(), unlessGio.SocketService.stop
() has been called before.New in version 2.22.
- is_active()[source]¶
-
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, callGio.SocketListener.close
(). (This will happen automatically when theGio.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:
connection (
Gio.SocketConnection
) –source_object (
GObject.Object
) –
- Return type:
signal emitted when new connections are accepted
Signal Details¶
- Gio.SocketService.signals.incoming(socket_service, connection, source_object)¶
- Signal Name:
incoming
- Flags:
- Parameters:
socket_service (
Gio.SocketService
) – The object which received the signalconnection (
Gio.SocketConnection
) – a newGio.SocketConnection
objectsource_object (
GObject.Object
orNone
) – the source_object passed toGio.SocketListener.add_address
()
- Returns:
True
to stop other handlers from being called- Return type:
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.