Add GoAway support

This commit is contained in:
Carl Lerche
2017-08-10 14:19:46 -07:00
parent 1974780504
commit a61562f6b8
6 changed files with 36 additions and 9 deletions

View File

@@ -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)
}
}

View File

@@ -62,6 +62,7 @@ pub enum Frame<T = Bytes> {
PushPromise(PushPromise),
Settings(Settings),
Ping(Ping),
GoAway(GoAway),
WindowUpdate(WindowUpdate),
Reset(Reset)
}
@@ -100,6 +101,7 @@ impl<T> fmt::Debug for Frame<T> {
PushPromise(ref frame) => write!(fmt, "Frame::PushPromise({:?})", frame),
Settings(ref frame) => write!(fmt, "Frame::Settings({:?})", frame),
Ping(ref frame) => write!(fmt, "Frame::Ping({:?})", frame),
GoAway(ref frame) => write!(fmt, "Frame::GoAway({:?})", frame),
WindowUpdate(ref frame) => write!(fmt, "Frame::WindowUpdate({:?})", frame),
Reset(ref frame) => write!(fmt, "Frame::Reset({:?})", frame),
}

View File

@@ -48,7 +48,7 @@ impl WindowUpdate {
pub fn encode<B: BufMut>(&self, dst: &mut B) {
trace!("encoding WINDOW_UPDATE; id={:?}", self.stream_id);
let head = Head::new(Kind::Ping, 0, self.stream_id);
let head = Head::new(Kind::WindowUpdate, 0, self.stream_id);
head.encode(4, dst);
dst.put_u32::<BigEndian>(self.size_increment);
}