Split ConnectionUpgrade. (#642)

Introduce `InboundUpgrade` and `OutboundUpgrade`.
This commit is contained in:
Toralf Wittner
2018-11-15 17:41:11 +01:00
committed by Pierre Krieger
parent 466385a58a
commit 2e549884ef
52 changed files with 2010 additions and 1658 deletions

View File

@ -18,11 +18,42 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
use crate::{muxing::{Shutdown, StreamMuxer}, Multiaddr};
use futures::prelude::*;
use muxing::{Shutdown, StreamMuxer};
use std::io::{Error as IoError, Read, Write};
use std::{fmt, io::{Error as IoError, Read, Write}};
use tokio_io::{AsyncRead, AsyncWrite};
use Multiaddr;
#[derive(Debug, Copy, Clone)]
pub enum EitherError<A, B> {
A(A),
B(B)
}
impl<A, B> fmt::Display for EitherError<A, B>
where
A: fmt::Display,
B: fmt::Display
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
EitherError::A(a) => a.fmt(f),
EitherError::B(b) => b.fmt(f)
}
}
}
impl<A, B> std::error::Error for EitherError<A, B>
where
A: fmt::Debug + std::error::Error,
B: fmt::Debug + std::error::Error
{
fn cause(&self) -> Option<&dyn std::error::Error> {
match self {
EitherError::A(a) => a.cause(),
EitherError::B(b) => b.cause()
}
}
}
/// Implements `AsyncRead` and `AsyncWrite` and dispatches all method calls to
/// either `First` or `Second`.