fn poll_finish()

in netbench/src/multiplex.rs [463:493]


    fn poll_finish(&mut self, cx: &mut Context) -> Poll<Result<()>> {
        if self.tx_open {
            self.flush_write_buffer(cx)?;

            // wait to shutdown the socket until we have written everything
            if !self.write_buf.is_empty() {
                return Poll::Pending;
            }

            // notify the peer we're not writing anything anymore
            // https://docs.rs/tokio/latest/tokio/io/trait.AsyncWrite.html#tymethod.poll_shutdown
            // > Invocation of a shutdown implies an invocation of flush. Once
            // > this method returns Ready it implies that a flush successfully
            // > happened before the shutdown happened. That is, callers don’t need
            // > to call flush before calling shutdown. They can rely that by
            // > calling shutdown any pending buffered data will be written out.
            ready!(self.inner.as_mut().poll_shutdown(cx))?;
            self.tx_open = false;
        }

        loop {
            // work to read all of the remaining data
            self.flush_read_buffer(cx)?;
            ready!(self.fill_read_buffer(cx))?;

            // the connection is done
            if !self.rx_open && self.frame.is_none() {
                return Ok(()).into();
            }
        }
    }