diff --git a/gemini/src/client.rs b/gemini/src/client.rs index 707b001..8e39c96 100644 --- a/gemini/src/client.rs +++ b/gemini/src/client.rs @@ -89,7 +89,30 @@ pub struct ConnectionAsyncRead { pub connection: gio::SocketConnection, pub readable: T, } - +fn suppress_tls_connection_closed_error( + res: Result, +) -> Result { + res.or_else(|e| { + if e.kind() == std::io::ErrorKind::Other { + let inner = e.into_inner().map(|e| e.downcast()).unwrap(); + inner + .and_then(|gio_err: Box| { + match gio_err.kind::() { + // map the error to an equivalent read of 0 bytes, which will signal the end of the + // connection + Some(gio::TlsError::Eof) => { + debug!("suppressed gio tls eof error"); + Ok(0) + } + _ => Err(gio_err.into()), + } + }) + .or_else(|e| Err(std::io::Error::other(e))) + } else { + Err(e) + } + }) +} impl AsyncRead for ConnectionAsyncRead { // Required method fn poll_read( @@ -100,7 +123,8 @@ impl AsyncRead for ConnectionAsyncRead { let readable = &mut self.as_mut().readable; futures::pin_mut!(readable); let readable: std::pin::Pin<_> = readable.as_mut(); - AsyncRead::poll_read(readable, cx, buf) + let res = AsyncRead::poll_read(readable, cx, buf); + res.map(|ready| suppress_tls_connection_closed_error(ready)) } }