gio::prelude

Trait SocketConnectionExt

Source
pub trait SocketConnectionExt:
    IsA<SocketConnection>
    + Sealed
    + 'static {
    // Provided methods
    fn connect(
        &self,
        address: &impl IsA<SocketAddress>,
        cancellable: Option<&impl IsA<Cancellable>>,
    ) -> Result<(), Error> { ... }
    fn connect_async<P: FnOnce(Result<(), Error>) + 'static>(
        &self,
        address: &impl IsA<SocketAddress>,
        cancellable: Option<&impl IsA<Cancellable>>,
        callback: P,
    ) { ... }
    fn connect_future(
        &self,
        address: &(impl IsA<SocketAddress> + Clone + 'static),
    ) -> Pin<Box_<dyn Future<Output = Result<(), Error>> + 'static>> { ... }
    fn local_address(&self) -> Result<SocketAddress, Error> { ... }
    fn remote_address(&self) -> Result<SocketAddress, Error> { ... }
    fn socket(&self) -> Socket { ... }
    fn is_connected(&self) -> bool { ... }
}
Expand description

Trait containing all SocketConnection methods.

§Implementors

SocketConnection, TcpConnection

Provided Methods§

Source

fn connect( &self, address: &impl IsA<SocketAddress>, cancellable: Option<&impl IsA<Cancellable>>, ) -> Result<(), Error>

Connect @self to the specified remote address.

§address

a #GSocketAddress specifying the remote address.

§cancellable

a GCancellable or None

§Returns

true if the connection succeeded, false on error

Source

fn connect_async<P: FnOnce(Result<(), Error>) + 'static>( &self, address: &impl IsA<SocketAddress>, cancellable: Option<&impl IsA<Cancellable>>, callback: P, )

Asynchronously connect @self to the specified remote address.

This clears the #GSocket:blocking flag on @self’s underlying socket if it is currently set.

If #GSocket:timeout is set, the operation will time out and return IOErrorEnum::TimedOut after that period. Otherwise, it will continue indefinitely until operating system timeouts (if any) are hit.

Use g_socket_connection_connect_finish() to retrieve the result.

§address

a #GSocketAddress specifying the remote address.

§cancellable

a GCancellable or None

§callback

a #GAsyncReadyCallback

Source

fn connect_future( &self, address: &(impl IsA<SocketAddress> + Clone + 'static), ) -> Pin<Box_<dyn Future<Output = Result<(), Error>> + 'static>>

Source

fn local_address(&self) -> Result<SocketAddress, Error>

Try to get the local address of a socket connection.

§Returns

a #GSocketAddress or None on error. Free the returned object with g_object_unref().

Source

fn remote_address(&self) -> Result<SocketAddress, Error>

Try to get the remote address of a socket connection.

Since GLib 2.40, when used with g_socket_client_connect() or g_socket_client_connect_async(), during emission of SocketClientEvent::Connecting, this function will return the remote address that will be used for the connection. This allows applications to print e.g. “Connecting to example.com (10.42.77.3)…”.

§Returns

a #GSocketAddress or None on error. Free the returned object with g_object_unref().

Source

fn socket(&self) -> Socket

Gets the underlying #GSocket object of the connection. This can be useful if you want to do something unusual on it not supported by the #GSocketConnection APIs.

§Returns

a #GSocket or None on error.

Source

fn is_connected(&self) -> bool

Checks if @self is connected. This is equivalent to calling g_socket_is_connected() on @self’s underlying #GSocket.

§Returns

whether @self is connected

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§