gio::prelude

Trait SocketListenerExt

Source
pub trait SocketListenerExt: IsA<SocketListener> + 'static {
Show 16 methods // Provided methods fn accept( &self, cancellable: Option<&impl IsA<Cancellable>>, ) -> Result<(SocketConnection, Option<Object>), Error> { ... } fn accept_async<P: FnOnce(Result<(SocketConnection, Option<Object>), Error>) + 'static>( &self, cancellable: Option<&impl IsA<Cancellable>>, callback: P, ) { ... } fn accept_future( &self, ) -> Pin<Box_<dyn Future<Output = Result<(SocketConnection, Option<Object>), Error>> + 'static>> { ... } fn accept_socket( &self, cancellable: Option<&impl IsA<Cancellable>>, ) -> Result<(Socket, Option<Object>), Error> { ... } fn accept_socket_async<P: FnOnce(Result<(Socket, Option<Object>), Error>) + 'static>( &self, cancellable: Option<&impl IsA<Cancellable>>, callback: P, ) { ... } fn accept_socket_future( &self, ) -> Pin<Box_<dyn Future<Output = Result<(Socket, Option<Object>), Error>> + 'static>> { ... } fn add_address( &self, address: &impl IsA<SocketAddress>, type_: SocketType, protocol: SocketProtocol, source_object: Option<&impl IsA<Object>>, ) -> Result<SocketAddress, Error> { ... } fn add_any_inet_port( &self, source_object: Option<&impl IsA<Object>>, ) -> Result<u16, Error> { ... } fn add_inet_port( &self, port: u16, source_object: Option<&impl IsA<Object>>, ) -> Result<(), Error> { ... } fn add_socket( &self, socket: &impl IsA<Socket>, source_object: Option<&impl IsA<Object>>, ) -> Result<(), Error> { ... } fn close(&self) { ... } fn set_backlog(&self, listen_backlog: i32) { ... } fn listen_backlog(&self) -> i32 { ... } fn set_listen_backlog(&self, listen_backlog: i32) { ... } fn connect_event<F: Fn(&Self, SocketListenerEvent, &Socket) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_listen_backlog_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... }
}
Expand description

Trait containing all SocketListener methods.

§Implementors

SocketListener, SocketService

Provided Methods§

Source

fn accept( &self, cancellable: Option<&impl IsA<Cancellable>>, ) -> Result<(SocketConnection, Option<Object>), Error>

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.

If @source_object is not None it 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 IOErrorEnum::Cancelled will be returned.

§cancellable

optional #GCancellable object, None to ignore.

§Returns

a #GSocketConnection on success, None on error.

§source_object

location where #GObject pointer will be stored, or None

Source

fn accept_async<P: FnOnce(Result<(SocketConnection, Option<Object>), Error>) + 'static>( &self, cancellable: Option<&impl IsA<Cancellable>>, callback: P, )

This is the asynchronous version of g_socket_listener_accept().

When the operation is finished @callback will be called. You can then call g_socket_listener_accept_finish() to get the result of the operation.

§cancellable

a #GCancellable, or None

§callback

a #GAsyncReadyCallback

Source

fn accept_future( &self, ) -> Pin<Box_<dyn Future<Output = Result<(SocketConnection, Option<Object>), Error>> + 'static>>

Source

fn accept_socket( &self, cancellable: Option<&impl IsA<Cancellable>>, ) -> Result<(Socket, Option<Object>), Error>

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

If you want to accept the high-level #GSocketConnection, not a #GSocket, which is often the case, then you should use g_socket_listener_accept() instead.

If @source_object is not None it 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 IOErrorEnum::Cancelled will be returned.

§cancellable

optional #GCancellable object, None to ignore.

§Returns

a #GSocket on success, None on error.

§source_object

location where #GObject pointer will be stored, or None.

Source

fn accept_socket_async<P: FnOnce(Result<(Socket, Option<Object>), Error>) + 'static>( &self, cancellable: Option<&impl IsA<Cancellable>>, callback: P, )

This is the asynchronous version of g_socket_listener_accept_socket().

When the operation is finished @callback will be called. You can then call g_socket_listener_accept_socket_finish() to get the result of the operation.

§cancellable

a #GCancellable, or None

§callback

a #GAsyncReadyCallback

Source

fn accept_socket_future( &self, ) -> Pin<Box_<dyn Future<Output = Result<(Socket, Option<Object>), Error>> + 'static>>

Source

fn add_address( &self, address: &impl IsA<SocketAddress>, type_: SocketType, protocol: SocketProtocol, source_object: Option<&impl IsA<Object>>, ) -> Result<SocketAddress, Error>

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 g_socket_listener_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-None then 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 g_socket_listener_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.

§address

a #GSocketAddress

§type_

a #GSocketType

§protocol

a #GSocketProtocol

§source_object

Optional #GObject identifying this source

§Returns

true on success, false on error.

§effective_address

location to store the address that was bound to, or None.

Source

fn add_any_inet_port( &self, source_object: Option<&impl IsA<Object>>, ) -> Result<u16, Error>

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.

§source_object

Optional #GObject identifying this source

§Returns

the port number, or 0 in case of failure.

Source

fn add_inet_port( &self, port: u16, source_object: Option<&impl IsA<Object>>, ) -> Result<(), Error>

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.

@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 g_socket_listener_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.

§port

an IP port number (non-zero)

§source_object

Optional #GObject identifying this source

§Returns

true on success, false on error.

Source

fn add_socket( &self, socket: &impl IsA<Socket>, source_object: Option<&impl IsA<Object>>, ) -> Result<(), Error>

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.

§socket

a listening #GSocket

§source_object

Optional #GObject identifying this source

§Returns

true on success, false on error.

Source

fn close(&self)

Closes all the sockets in the listener.

Source

fn set_backlog(&self, listen_backlog: i32)

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.

See g_socket_set_listen_backlog() for details

§listen_backlog

an integer

Source

fn listen_backlog(&self) -> i32

The number of outstanding connections in the listen queue.

Source

fn set_listen_backlog(&self, listen_backlog: i32)

The number of outstanding connections in the listen queue.

Source

fn connect_event<F: Fn(&Self, SocketListenerEvent, &Socket) + 'static>( &self, f: F, ) -> SignalHandlerId

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.

§event

the event that is occurring

§socket

the #GSocket the event is occurring on

Source

fn connect_listen_backlog_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§