Client::poll_ready and send_request may return Connection Errors (#132)

Closes #131
This commit is contained in:
Sean McArthur
2017-10-04 15:22:10 -07:00
committed by GitHub
parent 9e1a0c63cf
commit c4ca8f7def
6 changed files with 108 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
use codec::RecvError;
use codec::{RecvError, SendError};
use frame::Reason;
use std::io;
@@ -11,12 +11,13 @@ pub enum Error {
}
impl Error {
pub fn into_connection_recv_error(self) -> RecvError {
use self::Error::*;
match self {
Proto(reason) => RecvError::Connection(reason),
Io(e) => RecvError::Io(e),
/// Clone the error for internal purposes.
///
/// `io::Error` is not `Clone`, so we only copy the `ErrorKind`.
pub(super) fn shallow_clone(&self) -> Error {
match *self {
Error::Proto(reason) => Error::Proto(reason),
Error::Io(ref io) => Error::Io(io::Error::from(io.kind())),
}
}
}
@@ -32,3 +33,21 @@ impl From<io::Error> for Error {
Error::Io(src)
}
}
impl From<Error> for RecvError {
fn from(src: Error) -> RecvError {
match src {
Error::Proto(reason) => RecvError::Connection(reason),
Error::Io(e) => RecvError::Io(e),
}
}
}
impl From<Error> for SendError {
fn from(src: Error) -> SendError {
match src {
Error::Proto(reason) => SendError::Connection(reason),
Error::Io(e) => SendError::Io(e),
}
}
}