Gio.SocketListener¶
| Subclasses: | Gio.SocketService | 
|---|
Methods¶
| Inherited: | GObject.Object (37) | 
|---|---|
| Structs: | GObject.ObjectClass (5) | 
| class | new() | 
| accept(cancellable) | |
| accept_async(cancellable, callback, *user_data) | |
| accept_finish(result) | |
| accept_socket(cancellable) | |
| accept_socket_async(cancellable, callback, *user_data) | |
| accept_socket_finish(result) | |
| add_address(address, type, protocol, source_object) | |
| add_any_inet_port(source_object) | |
| add_inet_port(port, source_object) | |
| add_socket(socket, source_object) | |
| close() | |
| set_backlog(listen_backlog) | 
Properties¶
| Name | Type | Flags | Short Description | 
|---|---|---|---|
| listen-backlog | int | r/w/c | outstanding connections in the listen queue | 
Signals¶
| Inherited: | GObject.Object (1) | 
|---|
| Name | Short Description | 
|---|---|
| event | Emitted when listener’s activity on socket changes state. | 
Class Details¶
- 
class Gio.SocketListener(**kwargs)¶
- Bases: - GObject.Object- Abstract: - No - Structure: - Gio.SocketListenerClass- A - Gio.SocketListeneris an object that keeps track of a set of server sockets and helps you accept sockets from any of the socket, either sync or async.- Add addresses and ports to listen on using - Gio.SocketListener.add_address() and- Gio.SocketListener.add_inet_port(). These will be listened on until- Gio.SocketListener.close() is called. Dropping your final reference to the- Gio.SocketListenerwill not cause- Gio.SocketListener.close() to be called implicitly, as some references to the- Gio.SocketListenermay be held internally.- If you want to implement a network server, also look at - Gio.SocketServiceand- Gio.ThreadedSocketServicewhich are subclasses of- Gio.SocketListenerthat make this even easier.- New in version 2.22. - 
classmethod new()[source]¶
- Returns: - a new - Gio.SocketListener.- Return type: - Gio.SocketListener- Creates a new - Gio.SocketListenerwith no sockets to listen for. New listeners can be added with e.g.- Gio.SocketListener.add_address() or- Gio.SocketListener.add_inet_port().- New in version 2.22. 
 - 
accept(cancellable)[source]¶
- Parameters: - cancellable ( - Gio.Cancellableor- None) – optional- Gio.Cancellableobject,- Noneto ignore.- Raises: - GLib.Error- Returns: - a - Gio.SocketConnectionon success,- Noneon error.- source_object: - location where - GObject.Objectpointer will be stored, or- None- Return type: - ( - Gio.SocketConnection, source_object:- GObject.Objector- None)- Blocks waiting for a client to connect to any of the sockets added to the listener. Returns a - Gio.SocketConnectionfor the socket that was accepted.- If source_object is not - Noneit will be filled out with the source object specified when the corresponding socket or address was added to the listener.- If cancellable is not - None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error- Gio.IOErrorEnum.CANCELLEDwill be returned.- New in version 2.22. 
 - 
accept_async(cancellable, callback, *user_data)[source]¶
- Parameters: - cancellable (Gio.CancellableorNone) – aGio.Cancellable, orNone
- callback (Gio.AsyncReadyCallbackorNone) – aGio.AsyncReadyCallback
- user_data (objectorNone) – user data for the callback
 - This is the asynchronous version of - Gio.SocketListener.accept().- When the operation is finished callback will be called. You can then call - Gio.SocketListener.accept_socket() to get the result of the operation.- New in version 2.22. 
- cancellable (
 - 
accept_finish(result)[source]¶
- Parameters: - result ( - Gio.AsyncResult) – a- Gio.AsyncResult.- Raises: - GLib.Error- Returns: - a - Gio.SocketConnectionon success,- Noneon error.- source_object: - Optional - GObject.Objectidentifying this source- Return type: - ( - Gio.SocketConnection, source_object:- GObject.Objector- None)- Finishes an async accept operation. See - Gio.SocketListener.accept_async()- New in version 2.22. 
 - 
accept_socket(cancellable)[source]¶
- Parameters: - cancellable ( - Gio.Cancellableor- None) – optional- Gio.Cancellableobject,- Noneto ignore.- Raises: - GLib.Error- Returns: - a - Gio.Socketon success,- Noneon error.- source_object: - location where - GObject.Objectpointer will be stored, or- None.- Return type: - ( - Gio.Socket, source_object:- GObject.Objector- None)- Blocks waiting for a client to connect to any of the sockets added to the listener. Returns the - Gio.Socketthat was accepted.- If you want to accept the high-level - Gio.SocketConnection, not a- Gio.Socket, which is often the case, then you should use- Gio.SocketListener.accept() instead.- If source_object is not - Noneit will be filled out with the source object specified when the corresponding socket or address was added to the listener.- If cancellable is not - None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error- Gio.IOErrorEnum.CANCELLEDwill be returned.- New in version 2.22. 
 - 
accept_socket_async(cancellable, callback, *user_data)[source]¶
- Parameters: - cancellable (Gio.CancellableorNone) – aGio.Cancellable, orNone
- callback (Gio.AsyncReadyCallbackorNone) – aGio.AsyncReadyCallback
- user_data (objectorNone) – user data for the callback
 - This is the asynchronous version of - Gio.SocketListener.accept_socket().- When the operation is finished callback will be called. You can then call - Gio.SocketListener.accept_socket_finish() to get the result of the operation.- New in version 2.22. 
- cancellable (
 - 
accept_socket_finish(result)[source]¶
- Parameters: - result ( - Gio.AsyncResult) – a- Gio.AsyncResult.- Raises: - GLib.Error- Returns: - a - Gio.Socketon success,- Noneon error.- source_object: - Optional - GObject.Objectidentifying this source- Return type: - ( - Gio.Socket, source_object:- GObject.Objector- None)- Finishes an async accept operation. See - Gio.SocketListener.accept_socket_async()- New in version 2.22. 
 - 
add_address(address, type, protocol, source_object)[source]¶
- Parameters: - address (Gio.SocketAddress) – aGio.SocketAddress
- type (Gio.SocketType) – aGio.SocketType
- protocol (Gio.SocketProtocol) – aGio.SocketProtocol
- source_object (GObject.ObjectorNone) – OptionalGObject.Objectidentifying this source
 - Raises: - Returns: - Trueon success,- Falseon error.- effective_address: - location to store the address that was bound to, or - None.- Return type: - ( - bool, effective_address:- Gio.SocketAddress)- 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. - Note that adding an IPv6 address, depending on the platform, may or may not result in a listener that also accepts IPv4 connections. For more deterministic behavior, see - Gio.SocketListener.add_inet_port().- source_object will be passed out in the various calls to accept to identify this particular source, which is useful if you’re listening on multiple addresses and do different things depending on what address is connected to. - If successful and effective_address is non- - Nonethen it will be set to the address that the binding actually occurred at. This is helpful for determining the port number that was used for when requesting a binding to port 0 (ie: “any port”). This address, if requested, belongs to the caller and must be freed.- Call - Gio.SocketListener.close() to stop listening on address; this will not be done automatically when you drop your final reference to self, as references may be held internally.- New in version 2.22. 
- address (
 - 
add_any_inet_port(source_object)[source]¶
- Parameters: - source_object ( - GObject.Objector- None) – Optional- GObject.Objectidentifying this source- Raises: - GLib.Error- Returns: - the port number, or 0 in case of failure. - Return type: - int- Listens for TCP connections on any available port number for both IPv6 and IPv4 (if each is available). - This is useful if you need to have a socket for incoming connections but don’t care about the specific port number. - source_object will be passed out in the various calls to accept to identify this particular source, which is useful if you’re listening on multiple addresses and do different things depending on what address is connected to. - New in version 2.24. 
 - 
add_inet_port(port, source_object)[source]¶
- Parameters: - port (int) – an IP port number (non-zero)
- source_object (GObject.ObjectorNone) – OptionalGObject.Objectidentifying this source
 - Raises: - Returns: - Return type: - Helper function for - Gio.SocketListener.add_address() that creates a TCP/IP socket listening on IPv4 and IPv6 (if supported) on the specified port on all interfaces.- source_object will be passed out in the various calls to accept to identify this particular source, which is useful if you’re listening on multiple addresses and do different things depending on what address is connected to. - Call - Gio.SocketListener.close() to stop listening on port; this will not be done automatically when you drop your final reference to self, as references may be held internally.- New in version 2.22. 
- port (
 - 
add_socket(socket, source_object)[source]¶
- Parameters: - socket (Gio.Socket) – a listeningGio.Socket
- source_object (GObject.ObjectorNone) – OptionalGObject.Objectidentifying this source
 - Raises: - Returns: - Return type: - 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. - source_object will be passed out in the various calls to accept to identify this particular source, which is useful if you’re listening on multiple addresses and do different things depending on what address is connected to. - The socket will not be automatically closed when the self is finalized unless the listener held the final reference to the socket. Before GLib 2.42, the socket was automatically closed on finalization of the self, even if references to it were held elsewhere. - New in version 2.22. 
- socket (
 - 
set_backlog(listen_backlog)[source]¶
- Parameters: - listen_backlog ( - int) – an integer- Sets the listen backlog on the sockets in the listener. This must be called before adding any sockets, addresses or ports to the - Gio.SocketListener(for example, by calling- Gio.SocketListener.add_inet_port()) to be effective.- See - Gio.Socket.set_listen_backlog() for details- New in version 2.22. 
 - 
do_changed() virtual¶
 - 
do_event(event, socket) virtual¶
- Parameters: - event (Gio.SocketListenerEvent) –
- socket (Gio.Socket) –
 
- event (
 
- 
classmethod 
Signal Details¶
- 
Gio.SocketListener.signals.event(socket_listener, event, socket)¶
- Signal Name: - event- Flags: - Parameters: - socket_listener (Gio.SocketListener) – The object which received the signal
- event (Gio.SocketListenerEvent) – the event that is occurring
- socket (Gio.Socket) – theGio.Socketthe event is occurring on
 - 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. - New in version 2.46. 
- socket_listener (