mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +00:00
implement close method, add comments
This commit is contained in:
parent
1c50fadfde
commit
16ed3efef0
1 changed files with 20 additions and 1 deletions
|
|
@ -3,7 +3,7 @@ pub use error::Error;
|
||||||
|
|
||||||
use gio::{
|
use gio::{
|
||||||
prelude::{IOStreamExt, TlsConnectionExt},
|
prelude::{IOStreamExt, TlsConnectionExt},
|
||||||
IOStream, NetworkAddress, SocketConnection, TlsCertificate, TlsClientConnection,
|
Cancellable, IOStream, NetworkAddress, SocketConnection, TlsCertificate, TlsClientConnection,
|
||||||
};
|
};
|
||||||
use glib::object::{Cast, IsA};
|
use glib::object::{Cast, IsA};
|
||||||
|
|
||||||
|
|
@ -43,8 +43,27 @@ impl Connection {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
|
||||||
|
/// Close owned [SocketConnection](https://docs.gtk.org/gio/class.SocketConnection.html)
|
||||||
|
/// and [TlsClientConnection](https://docs.gtk.org/gio/iface.TlsClientConnection.html) if active
|
||||||
|
pub fn close(&self, cancellable: Option<&Cancellable>) {
|
||||||
|
if let Some(ref tls_client_connection) = self.tls_client_connection {
|
||||||
|
if !tls_client_connection.is_closed() {
|
||||||
|
tls_client_connection.close(cancellable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !self.socket_connection.is_closed() {
|
||||||
|
self.socket_connection.close(cancellable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
|
||||||
|
/// Upcast [IOStream](https://docs.gtk.org/gio/class.IOStream.html)
|
||||||
|
/// for [SocketConnection](https://docs.gtk.org/gio/class.SocketConnection.html)
|
||||||
|
/// or [TlsClientConnection](https://docs.gtk.org/gio/iface.TlsClientConnection.html) (if available)
|
||||||
|
/// * wanted to keep `Connection` active in async I/O context
|
||||||
pub fn stream(&self) -> impl IsA<IOStream> {
|
pub fn stream(&self) -> impl IsA<IOStream> {
|
||||||
match self.tls_client_connection.clone() {
|
match self.tls_client_connection.clone() {
|
||||||
Some(tls_client_connection) => tls_client_connection.upcast::<IOStream>(),
|
Some(tls_client_connection) => tls_client_connection.upcast::<IOStream>(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue