From 9a43ea6fdd4b82725aaa0ed8c3f63187660e2431 Mon Sep 17 00:00:00 2001 From: Rasmus Melchior Jacobsen Date: Tue, 24 Oct 2023 07:54:35 +0200 Subject: [PATCH 1/3] Propagate the eio ErrorKind --- src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 2a13cce..010aecb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,7 +43,10 @@ pub enum Error { impl embedded_io::Error for Error { fn kind(&self) -> embedded_io::ErrorKind { - embedded_io::ErrorKind::Other + match self { + Error::Network(kind) => *kind, + _ => embedded_io::ErrorKind::Other, + } } } From eaeae5f22ad3208b8392a5110020b0ebb56dcf33 Mon Sep 17 00:00:00 2001 From: Rasmus Melchior Jacobsen Date: Tue, 24 Oct 2023 07:56:50 +0200 Subject: [PATCH 2/3] Map Error::ConnectionClosed to ErrorKind::NotConnected --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 010aecb..4af0949 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,6 +45,7 @@ impl embedded_io::Error for Error { fn kind(&self) -> embedded_io::ErrorKind { match self { Error::Network(kind) => *kind, + Error::ConnectionClosed => embedded_io::ErrorKind::NotConnected, _ => embedded_io::ErrorKind::Other, } } From 3b0b27b38cd6de807890ecf0ca788b834b8a5911 Mon Sep 17 00:00:00 2001 From: Rasmus Melchior Jacobsen Date: Tue, 24 Oct 2023 07:59:28 +0200 Subject: [PATCH 3/3] Rename ConnectionClosed to the more correct ConnectionAborted --- src/lib.rs | 8 ++++---- src/response.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4af0949..0923b60 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,15 +37,15 @@ pub enum Error { AlreadySent, /// An invalid number of bytes were written to request body IncorrectBodyWritten, - /// The underlying connection was closed - ConnectionClosed, + /// The underlying connection was closed while being used + ConnectionAborted, } impl embedded_io::Error for Error { fn kind(&self) -> embedded_io::ErrorKind { match self { Error::Network(kind) => *kind, - Error::ConnectionClosed => embedded_io::ErrorKind::NotConnected, + Error::ConnectionAborted => embedded_io::ErrorKind::ConnectionAborted, _ => embedded_io::ErrorKind::Other, } } @@ -60,7 +60,7 @@ impl From for Error { impl From> for Error { fn from(value: ReadExactError) -> Self { match value { - ReadExactError::UnexpectedEof => Error::ConnectionClosed, + ReadExactError::UnexpectedEof => Error::ConnectionAborted, ReadExactError::Other(e) => Error::Network(e.kind()), } } diff --git a/src/response.rs b/src/response.rs index 3132865..7986cdb 100644 --- a/src/response.rs +++ b/src/response.rs @@ -51,7 +51,7 @@ where })?; if n == 0 { - return Err(Error::ConnectionClosed); + return Err(Error::ConnectionAborted); } pos += n; @@ -413,7 +413,7 @@ where .map(|data| &data[..data.len().min(self.remaining)])?; if loaded.is_empty() { - return Err(Error::ConnectionClosed); + return Err(Error::ConnectionAborted); } Ok(loaded)