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.SocketListenerAbstract: No Structure: Gio.SocketServiceClassA
Gio.SocketServiceis 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 theGio.SocketService::incomingsignal is emitted.A
Gio.SocketServiceis a subclass ofGio.SocketListenerand you need to add the addresses you want to accept connections on with theGio.SocketListenerAPIs.There are two options for implementing a network service based on
Gio.SocketService. The first is to create the service usingGio.SocketService.new() and to connect to theGio.SocketService::incomingsignal. The second is to subclassGio.SocketServiceand 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.SocketServiceCreates a new
Gio.SocketServicewith 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]¶ Returns: Trueif the service is active,FalseotherwiseReturn type: boolCheck 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.SocketServiceis 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: - connection (
-
classmethod
Signal Details¶
-
Gio.SocketService.signals.incoming(socket_service, connection, source_object)¶ Signal Name: incomingFlags: Parameters: - socket_service (
Gio.SocketService) – The object which received the signal - connection (
Gio.SocketConnection) – a newGio.SocketConnectionobject - source_object (
GObject.ObjectorNone) – the source_object passed toGio.SocketListener.add_address()
Returns: Trueto stop other handlers from being calledReturn type: The
::incomingsignal 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.
- socket_service (