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