New send flow control (#25)
Restructure send flow control such that sending data is always accepted by `Stream`. Data frames will be buffered until there is available window to send them. Producers can monitor the available window capacity to decide if data should be produced.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
use {frame, ConnectionError, StreamId};
|
||||
use {Body, Chunk};
|
||||
use proto::{self, Connection};
|
||||
use proto::{self, Connection, WindowSize};
|
||||
use error::Reason::*;
|
||||
|
||||
use http::{self, Request, Response};
|
||||
use futures::{self, Future, Poll, Sink, AsyncSink};
|
||||
use futures::{self, Future, Poll, Sink, Async, AsyncSink};
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use bytes::{Bytes, IntoBuf};
|
||||
|
||||
@@ -147,6 +147,25 @@ impl<B: IntoBuf> Stream<B> {
|
||||
Ok(Response::from_parts(parts, body).into())
|
||||
}
|
||||
|
||||
/// Request capacity to send data
|
||||
pub fn reserve_capacity(&mut self, capacity: usize)
|
||||
-> Result<(), ConnectionError>
|
||||
{
|
||||
// TODO: Check for overflow
|
||||
self.inner.reserve_capacity(capacity as WindowSize)
|
||||
}
|
||||
|
||||
/// Returns the stream's current send capacity.
|
||||
pub fn capacity(&self) -> usize {
|
||||
self.inner.capacity() as usize
|
||||
}
|
||||
|
||||
/// Request to be notified when the stream's capacity increases
|
||||
pub fn poll_capacity(&mut self) -> Poll<Option<usize>, ConnectionError> {
|
||||
let res = try_ready!(self.inner.poll_capacity());
|
||||
Ok(Async::Ready(res.map(|v| v as usize)))
|
||||
}
|
||||
|
||||
/// Send data
|
||||
pub fn send_data(&mut self, data: B, end_of_stream: bool)
|
||||
-> Result<(), ConnectionError>
|
||||
|
||||
Reference in New Issue
Block a user