handle errors

This commit is contained in:
yggverse 2024-11-28 23:27:53 +02:00
parent 16ed3efef0
commit f4cb0c3bcc
2 changed files with 13 additions and 4 deletions

View file

@ -47,15 +47,20 @@ impl Connection {
/// 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>) {
pub fn close(&self, cancellable: Option<&Cancellable>) -> Result<(), Error> {
if let Some(ref tls_client_connection) = self.tls_client_connection {
if !tls_client_connection.is_closed() {
tls_client_connection.close(cancellable);
if let Err(reason) = tls_client_connection.close(cancellable) {
return Err(Error::TlsClientConnection(reason));
}
}
}
if !self.socket_connection.is_closed() {
self.socket_connection.close(cancellable);
if let Err(reason) = self.socket_connection.close(cancellable) {
return Err(Error::SocketConnection(reason));
}
}
Ok(())
}
// Getters