UPdated http::Stream

This commit is contained in:
2021-05-18 20:03:39 +02:00
parent ed0ad39abd
commit 7a5eea3f85

View File

@ -289,7 +289,26 @@ impl Stream {
pub fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> { pub fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> {
match self { match self {
Stream::Tcp(stream) => stream.read(buf), 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<usize, std::io::Error> { pub fn write(&mut self, buf: &[u8]) -> Result<usize, std::io::Error> {
match self { match self {
Stream::Tcp(stream) => stream.write(buf), 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)
}));
}
}
},
} }
} }