Skip to content

Commit

Permalink
Remove public Error constructor from io::Error (hyperium#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar authored Oct 7, 2019
1 parent 4c1d797 commit 3cfcab0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ where
log::debug!("binding client connection");

let msg: &'static [u8] = b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n";
io.write_all(msg).await?;
io.write_all(msg).await.map_err(crate::Error::from_io)?;

log::debug!("client connection bound");

Expand Down
16 changes: 7 additions & 9 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ impl Error {
_ => None,
}
}

pub(crate) fn from_io(err: io::Error) -> Self {
Error {
kind: Kind::Io(err),
}
}
}

impl From<proto::Error> for Error {
Expand All @@ -88,14 +94,6 @@ impl From<proto::Error> for Error {
}
}

impl From<io::Error> for Error {
fn from(src: io::Error) -> Error {
Error {
kind: Kind::Io(src),
}
}
}

impl From<Reason> for Error {
fn from(src: Reason) -> Error {
Error {
Expand All @@ -109,7 +107,7 @@ impl From<SendError> for Error {
match src {
SendError::User(e) => e.into(),
SendError::Connection(reason) => reason.into(),
SendError::Io(e) => e.into(),
SendError::Io(e) => Error::from_io(e),
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ where

fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
// Flush the codec
ready!(self.codec.as_mut().unwrap().flush(cx))?;
ready!(self.codec.as_mut().unwrap().flush(cx)).map_err(crate::Error::from_io)?;

// Return the codec
Poll::Ready(Ok(self.codec.take().unwrap()))
Expand Down Expand Up @@ -1153,13 +1153,13 @@ where
let mut rem = PREFACE.len() - self.pos;

while rem > 0 {
let n = ready!(Pin::new(self.inner_mut()).poll_read(cx, &mut buf[..rem]))?;
let n = ready!(Pin::new(self.inner_mut()).poll_read(cx, &mut buf[..rem]))
.map_err(crate::Error::from_io)?;
if n == 0 {
return Poll::Ready(Err(io::Error::new(
io::ErrorKind::ConnectionReset,
"connection closed unexpectedly",
)
.into()));
return Poll::Ready(Err(crate::Error::from_io(io::Error::new(
io::ErrorKind::UnexpectedEof,
"connection closed before reading preface",
))));
}

if PREFACE[self.pos..self.pos + n] != buf[..n] {
Expand Down

0 comments on commit 3cfcab0

Please sign in to comment.