|
|
@ -6,6 +6,7 @@ use error::{Error, Result}; |
|
|
|
use util::NonBlockingResult; |
|
|
|
use util::NonBlockingResult; |
|
|
|
|
|
|
|
|
|
|
|
/// A generic handshake state machine.
|
|
|
|
/// A generic handshake state machine.
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
pub struct HandshakeMachine<Stream> { |
|
|
|
pub struct HandshakeMachine<Stream> { |
|
|
|
stream: Stream, |
|
|
|
stream: Stream, |
|
|
|
state: HandshakeState, |
|
|
|
state: HandshakeState, |
|
|
@ -98,6 +99,7 @@ impl<Stream: Read + Write> HandshakeMachine<Stream> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// The result of the round.
|
|
|
|
/// The result of the round.
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
pub enum RoundResult<Obj, Stream> { |
|
|
|
pub enum RoundResult<Obj, Stream> { |
|
|
|
/// Round not done, I/O would block.
|
|
|
|
/// Round not done, I/O would block.
|
|
|
|
WouldBlock(HandshakeMachine<Stream>), |
|
|
|
WouldBlock(HandshakeMachine<Stream>), |
|
|
@ -108,6 +110,7 @@ pub enum RoundResult<Obj, Stream> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// The result of the stage.
|
|
|
|
/// The result of the stage.
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
pub enum StageResult<Obj, Stream> { |
|
|
|
pub enum StageResult<Obj, Stream> { |
|
|
|
/// Reading round finished.
|
|
|
|
/// Reading round finished.
|
|
|
|
DoneReading { result: Obj, stream: Stream, tail: Vec<u8> }, |
|
|
|
DoneReading { result: Obj, stream: Stream, tail: Vec<u8> }, |
|
|
@ -122,6 +125,7 @@ pub trait TryParse: Sized { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// The handshake state.
|
|
|
|
/// The handshake state.
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
enum HandshakeState { |
|
|
|
enum HandshakeState { |
|
|
|
/// Reading data from the peer.
|
|
|
|
/// Reading data from the peer.
|
|
|
|
Reading(InputBuffer), |
|
|
|
Reading(InputBuffer), |
|
|
|