diff --git a/neqo-http3/src/connection.rs b/neqo-http3/src/connection.rs index cfa78df787..24c9937dca 100644 --- a/neqo-http3/src/connection.rs +++ b/neqo-http3/src/connection.rs @@ -386,10 +386,16 @@ impl Http3Connection { Ok(()) } - /// Inform a `HttpConnection` that a stream has data to send and that `send` should be called - /// for the stream. - pub fn stream_has_pending_data(&mut self, stream_id: StreamId) { - self.streams_with_pending_data.insert(stream_id); + /// Inform a [`Http3Connection`] that a stream might have data to send in + /// case `send` should be called for the stream. + pub fn stream_might_have_pending_data(&mut self, stream_id: StreamId) { + if self + .send_streams + .get(&stream_id) + .map_or(false, |s| s.has_data_to_send()) + { + self.streams_with_pending_data.insert(stream_id); + } } /// Return true if there is a stream that needs to send data. diff --git a/neqo-http3/src/connection_server.rs b/neqo-http3/src/connection_server.rs index dcf759f177..1f1bf5923c 100644 --- a/neqo-http3/src/connection_server.rs +++ b/neqo-http3/src/connection_server.rs @@ -64,13 +64,15 @@ impl Http3ServerHandler { data: &[u8], conn: &mut Connection, ) -> Res { - self.base_handler.stream_has_pending_data(stream_id); - self.needs_processing = true; - self.base_handler + let n = self + .base_handler .send_streams .get_mut(&stream_id) .ok_or(Error::InvalidStreamId)? - .send_data(conn, data) + .send_data(conn, data)?; + self.base_handler.stream_might_have_pending_data(stream_id); + self.needs_processing = true; + Ok(n) } /// Supply response heeaders for a request. @@ -87,7 +89,7 @@ impl Http3ServerHandler { .http_stream() .ok_or(Error::InvalidStreamId)? .send_headers(headers, conn)?; - self.base_handler.stream_has_pending_data(stream_id); + self.base_handler.stream_might_have_pending_data(stream_id); self.needs_processing = true; Ok(()) } @@ -100,7 +102,7 @@ impl Http3ServerHandler { pub fn stream_close_send(&mut self, stream_id: StreamId, conn: &mut Connection) -> Res<()> { qdebug!([self], "Close sending side stream={}.", stream_id); self.base_handler.stream_close_send(conn, stream_id)?; - self.base_handler.stream_has_pending_data(stream_id); + self.base_handler.stream_might_have_pending_data(stream_id); self.needs_processing = true; Ok(()) }