Restructure proto
The existing code has been moved out and is being copied back piece / by piece while restructuring the code to (hopefully) be more manageable.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
use {hpack, ConnectionError, FrameSize};
|
||||
use frame::{self, Frame};
|
||||
use proto::{ApplySettings, ReadySink};
|
||||
|
||||
use futures::*;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
@@ -65,6 +64,19 @@ impl<T, B> FramedWrite<T, B>
|
||||
}
|
||||
}
|
||||
|
||||
pub fn poll_ready(&mut self) -> Poll<(), ConnectionError> {
|
||||
if !self.has_capacity() {
|
||||
// Try flushing
|
||||
try!(self.poll_complete());
|
||||
|
||||
if !self.has_capacity() {
|
||||
return Ok(Async::NotReady);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Async::Ready(()))
|
||||
}
|
||||
|
||||
fn has_capacity(&self) -> bool {
|
||||
self.next.is_none() && self.buf.get_ref().remaining_mut() >= MIN_BUFFER_CAPACITY
|
||||
}
|
||||
@@ -78,16 +90,6 @@ impl<T, B> FramedWrite<T, B>
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, B> ApplySettings for FramedWrite<T, B> {
|
||||
fn apply_local_settings(&mut self, _set: &frame::SettingSet) -> Result<(), ConnectionError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn apply_remote_settings(&mut self, _set: &frame::SettingSet) -> Result<(), ConnectionError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, B> Sink for FramedWrite<T, B>
|
||||
where T: AsyncWrite,
|
||||
B: Buf,
|
||||
@@ -102,6 +104,8 @@ impl<T, B> Sink for FramedWrite<T, B>
|
||||
return Ok(AsyncSink::NotReady(item));
|
||||
}
|
||||
|
||||
trace!("send; frame={:?}", item);
|
||||
|
||||
match item {
|
||||
Frame::Data(mut v) => {
|
||||
if v.payload().remaining() >= CHAIN_THRESHOLD {
|
||||
@@ -186,24 +190,6 @@ impl<T, B> Sink for FramedWrite<T, B>
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, B> ReadySink for FramedWrite<T, B>
|
||||
where T: AsyncWrite,
|
||||
B: Buf,
|
||||
{
|
||||
fn poll_ready(&mut self) -> Poll<(), Self::SinkError> {
|
||||
if !self.has_capacity() {
|
||||
// Try flushing
|
||||
try!(self.poll_complete());
|
||||
|
||||
if !self.has_capacity() {
|
||||
return Ok(Async::NotReady);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Async::Ready(()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Stream, B> Stream for FramedWrite<T, B> {
|
||||
type Item = T::Item;
|
||||
type Error = T::Error;
|
||||
|
||||
Reference in New Issue
Block a user