Skip to content

Commit 7888451

Browse files
committed
refactor(proto): return Error::Incomplete instead of UnexpectedEof
1 parent 30f7f1d commit 7888451

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

src/proto/conn.rs

+18
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ where I: AsyncRead + AsyncWrite,
5858
fn poll_incoming(&mut self) -> Poll<Option<Frame<super::MessageHead<T::Incoming>, super::Chunk, ::Error>>, io::Error> {
5959
trace!("Conn::poll_incoming()");
6060

61+
#[derive(Debug)]
62+
struct ParseEof;
63+
64+
impl fmt::Display for ParseEof {
65+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
66+
f.write_str(::std::error::Error::description(self))
67+
}
68+
}
69+
70+
impl ::std::error::Error for ParseEof {
71+
fn description(&self) -> &str {
72+
"end of file reached before parsing could complete"
73+
}
74+
}
75+
6176
loop {
6277
if self.is_read_closed() {
6378
trace!("Conn::poll when closed");
@@ -73,6 +88,9 @@ where I: AsyncRead + AsyncWrite,
7388
Ok(Async::Ready(None)) => Ok(Async::Ready(None)),
7489
Ok(Async::NotReady) => Ok(Async::NotReady),
7590
Err(::Error::Io(err)) => Err(err),
91+
Err(::Error::Incomplete) => {
92+
Err(io::Error::new(io::ErrorKind::UnexpectedEof, ParseEof))
93+
},
7694
Err(err) => Ok(Async::Ready(Some(Frame::Error {
7795
error: err,
7896
}))),

src/proto/io.rs

+1-17
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ impl<T: AsyncRead + AsyncWrite> Buffered<T> {
8484
match try_ready!(self.read_from_io()) {
8585
0 => {
8686
trace!("parse eof");
87-
//TODO: utilize Error::Incomplete when Error type is redesigned
88-
return Err(io::Error::new(io::ErrorKind::UnexpectedEof, ParseEof).into());
87+
return Err(::Error::Incomplete);
8988
}
9089
_ => {},
9190
}
@@ -333,21 +332,6 @@ impl WriteBuf {
333332
}
334333
}
335334

336-
#[derive(Debug)]
337-
struct ParseEof;
338-
339-
impl fmt::Display for ParseEof {
340-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
341-
f.write_str(::std::error::Error::description(self))
342-
}
343-
}
344-
345-
impl ::std::error::Error for ParseEof {
346-
fn description(&self) -> &str {
347-
"end of file reached before parsing could complete"
348-
}
349-
}
350-
351335
// TODO: Move tests to their own mod
352336
#[cfg(test)]
353337
use std::io::Read;

tests/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ test! {
425425
body: None,
426426
proxy: false,
427427
error: |err| match err {
428-
&hyper::Error::Io(_) => true,
428+
&hyper::Error::Incomplete => true,
429429
_ => false,
430430
},
431431
}

0 commit comments

Comments
 (0)