Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(http3): always qlog on send_buffer() #1876

Merged
merged 6 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 28 additions & 23 deletions neqo-http3/src/buffered_send_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use neqo_common::qtrace;
use neqo_transport::{Connection, StreamId};

use crate::Res;
use crate::{qlog, Res};

#[derive(Debug, PartialEq, Eq)]
pub enum BufferedStream {
Expand Down Expand Up @@ -38,7 +38,7 @@ impl BufferedStream {

/// # Panics
///
/// If the `BufferedStream` is initialized more than one it will panic.
/// If the `BufferedStream` is initialized more than once, it will panic.
pub fn init(&mut self, stream_id: StreamId) {
debug_assert!(&Self::Uninitialized == self);
*self = Self::Initialized {
Expand All @@ -63,19 +63,23 @@ impl BufferedStream {
/// Returns `neqo_transport` errors.
pub fn send_buffer(&mut self, conn: &mut Connection) -> Res<usize> {
let label = ::neqo_common::log_subject!(::log::Level::Debug, self);
let mut sent = 0;
if let Self::Initialized { stream_id, buf } = self {
if !buf.is_empty() {
qtrace!([label], "sending data.");
sent = conn.stream_send(*stream_id, &buf[..])?;
if sent == buf.len() {
buf.clear();
} else {
let b = buf.split_off(sent);
*buf = b;
}
}
let Self::Initialized { stream_id, buf } = self else {
return Ok(0);
};
if buf.is_empty() {
return Ok(0);
}
qtrace!([label], "sending data.");
let sent = conn.stream_send(*stream_id, &buf[..])?;
if sent == 0 {
return Ok(0);
} else if sent == buf.len() {
buf.clear();
} else {
let b = buf.split_off(sent);
*buf = b;
}
qlog::h3_data_moved_down(conn.qlog_mut(), *stream_id, sent);
Ok(sent)
}

Expand All @@ -85,16 +89,17 @@ impl BufferedStream {
pub fn send_atomic(&mut self, conn: &mut Connection, to_send: &[u8]) -> Res<bool> {
// First try to send anything that is in the buffer.
self.send_buffer(conn)?;
if let Self::Initialized { stream_id, buf } = self {
if buf.is_empty() {
let res = conn.stream_send_atomic(*stream_id, to_send)?;
Ok(res)
} else {
Ok(false)
}
} else {
Ok(false)
let Self::Initialized { stream_id, buf } = self else {
return Ok(false);
};
if !buf.is_empty() {
return Ok(false);
}
let res = conn.stream_send_atomic(*stream_id, to_send)?;
if res {
qlog::h3_data_moved_down(conn.qlog_mut(), *stream_id, to_send.len());
}
Ok(res)
}

#[must_use]
Expand Down
4 changes: 1 addition & 3 deletions neqo-http3/src/send_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use neqo_transport::{Connection, StreamId};
use crate::{
frames::HFrame,
headers_checks::{headers_valid, is_interim, trailers_valid},
qlog, BufferedStream, CloseType, Error, Http3StreamInfo, Http3StreamType, HttpSendStream, Res,
BufferedStream, CloseType, Error, Http3StreamInfo, Http3StreamType, HttpSendStream, Res,
SendStream, SendStreamEvents, Stream,
};

Expand Down Expand Up @@ -216,7 +216,6 @@ impl SendStream for SendMessage {
.send_atomic(conn, &buf[..to_send])
.map_err(|e| Error::map_stream_send_errors(&e))?;
debug_assert!(sent);
qlog::h3_data_moved_down(conn.qlog_mut(), self.stream_id(), to_send);
Ok(to_send)
}

Expand All @@ -243,7 +242,6 @@ impl SendStream for SendMessage {
/// info that the stream has been closed.)
fn send(&mut self, conn: &mut Connection) -> Res<()> {
let sent = Error::map_error(self.stream.send_buffer(conn), Error::HttpInternal(5))?;
qlog::h3_data_moved_down(conn.qlog_mut(), self.stream_id(), sent);

qtrace!([self], "{} bytes sent", sent);
if !self.stream.has_buffered_data() {
Expand Down
Loading