Add GoAway support
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
use frame::{Error, StreamId};
|
||||
use error::Reason;
|
||||
use frame::{self, Head, Error, Kind, StreamId};
|
||||
|
||||
use bytes::{BufMut, BigEndian};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GoAway {
|
||||
@@ -7,6 +10,10 @@ pub struct GoAway {
|
||||
}
|
||||
|
||||
impl GoAway {
|
||||
pub fn reason(&self) -> Reason {
|
||||
self.error_code.into()
|
||||
}
|
||||
|
||||
pub fn load(payload: &[u8]) -> Result<GoAway, Error> {
|
||||
if payload.len() < 8 {
|
||||
// Invalid payload len
|
||||
@@ -22,4 +29,18 @@ impl GoAway {
|
||||
error_code: error_code,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn encode<B: BufMut>(&self, dst: &mut B) {
|
||||
trace!("encoding GO_AWAY; code={}", self.error_code);
|
||||
let head = Head::new(Kind::GoAway, 0, StreamId::zero());
|
||||
head.encode(8, dst);
|
||||
dst.put_u32::<BigEndian>(self.last_stream_id.into());
|
||||
dst.put_u32::<BigEndian>(self.error_code);
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> From<GoAway> for frame::Frame<B> {
|
||||
fn from(src: GoAway) -> Self {
|
||||
frame::Frame::GoAway(src)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user