From 7a5eea3f851225deb85e9cc6c800e0f8ad4f27c5 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Tue, 18 May 2021 20:03:39 +0200 Subject: [PATCH] UPdated http::Stream --- src/http/mod.rs | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/http/mod.rs b/src/http/mod.rs index 72871ec..ab56729 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -289,7 +289,26 @@ impl Stream { pub fn read(&mut self, buf: &mut [u8]) -> Result { match self { Stream::Tcp(stream) => stream.read(buf), - Stream::Ssl(stream) => stream.read(buf), + Stream::Ssl(stream) => loop { + match stream.ssl_read(buf) { + Ok(n) => return Ok(n), + Err(ref e) if e.code() == openssl::ssl::ErrorCode::ZERO_RETURN => return Ok(0), + Err(ref e) + if e.code() == openssl::ssl::ErrorCode::SYSCALL + && e.io_error().is_none() => + { + return Ok(0); + } + Err(ref e) + if e.code() == openssl::ssl::ErrorCode::WANT_READ + && e.io_error().is_none() => {} + Err(e) => { + return Err(e.into_io_error().unwrap_or_else(|e| { + std::io::Error::new(std::io::ErrorKind::Other, e) + })); + } + } + }, } } @@ -310,7 +329,19 @@ impl Stream { pub fn write(&mut self, buf: &[u8]) -> Result { match self { Stream::Tcp(stream) => stream.write(buf), - Stream::Ssl(stream) => stream.write(buf), + Stream::Ssl(stream) => loop { + match stream.ssl_write(buf) { + Ok(n) => return Ok(n), + Err(ref e) + if e.code() == openssl::ssl::ErrorCode::WANT_READ + && e.io_error().is_none() => {} + Err(e) => { + return Err(e.into_io_error().unwrap_or_else(|e| { + std::io::Error::new(std::io::ErrorKind::Other, e) + })); + } + } + }, } }