StreamRef sends RST_STREAM on drop (#109)

This PR modifies the `Drop` implementation for `StreamRef` to reset the underlying stream if it is the last reference to that stream. Since both `Stream` and `Body` are internally just a `StreamRef`, this means they will both reset the stream on drop; thus, this closes #100.

The assertion that the store no longer contains the dropped stream ID at the end of the `Drop` method  had to be removed, as the stream has to be reset from inside of a `transition` block (which now manages releasing that ID for us), and the `transition` closure moves the value of `stream`, making the assertion no longer possible.

Modifications to some of the tests in `flow_control.rs` were also necessary, in order to prevent `StreamRef`s from being dropped too early.
This commit is contained in:
Eliza Weisman
2017-10-05 18:05:18 -05:00
committed by GitHub
parent ecd2764f4b
commit 2e3dcf602c
9 changed files with 177 additions and 57 deletions

View File

@@ -46,7 +46,6 @@ pub(crate) struct Prioritized<B> {
impl<B, P> Prioritize<B, P>
where
B: Buf,
P: Peer,
{
pub fn new(config: &Config) -> Prioritize<B, P> {
@@ -101,7 +100,10 @@ where
frame: frame::Data<B>,
stream: &mut store::Ptr<B, P>,
task: &mut Option<Task>,
) -> Result<(), UserError> {
) -> Result<(), UserError>
where
B: Buf,
{
let sz = frame.payload().remaining();
if sz > MAX_WINDOW_SIZE as usize {
@@ -369,6 +371,7 @@ where
) -> Poll<(), io::Error>
where
T: AsyncWrite,
B: Buf,
{
// Ensure codec is ready
try_ready!(dst.poll_ready());
@@ -422,7 +425,10 @@ where
&mut self,
store: &mut Store<B, P>,
dst: &mut Codec<T, Prioritized<B>>,
) -> bool {
) -> bool
where
B: Buf,
{
trace!("try reclaim frame");
// First check if there are any data chunks to take back
@@ -485,7 +491,10 @@ where
store: &mut Store<B, P>,
max_len: usize,
counts: &mut Counts<P>,
) -> Option<Frame<Prioritized<B>>> {
) -> Option<Frame<Prioritized<B>>>
where
B: Buf,
{
trace!("pop_frame");
loop {