UPdated http::Stream
This commit is contained in:
@ -289,7 +289,26 @@ impl Stream {
|
||||
pub fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> {
|
||||
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<usize, std::io::Error> {
|
||||
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)
|
||||
}));
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user