Skip to content
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
53 changes: 53 additions & 0 deletions src/proto/streams/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,56 @@ pub struct Config {
/// When this gets exceeded, we issue GOAWAYs.
pub local_max_error_reset_streams: Option<usize>,
}

trait DebugStructExt<'a, 'b> {
// h2_ prefixes to protect against possible future name collisions
fn h2_field_if(&mut self, name: &str, val: &bool) -> &mut std::fmt::DebugStruct<'a, 'b>;

fn h2_field_if_then<T: std::fmt::Debug>(
&mut self,
name: &str,
cond: bool,
val: &T,
) -> &mut std::fmt::DebugStruct<'a, 'b>;

fn h2_field_some<T: std::fmt::Debug>(
&mut self,
name: &str,
val: &Option<T>,
) -> &mut std::fmt::DebugStruct<'a, 'b>;
}

impl<'a, 'b> DebugStructExt<'a, 'b> for std::fmt::DebugStruct<'a, 'b> {
fn h2_field_if(&mut self, name: &str, val: &bool) -> &mut std::fmt::DebugStruct<'a, 'b> {
if *val {
self.field(name, val)
} else {
self
}
}

fn h2_field_if_then<T: std::fmt::Debug>(
&mut self,
name: &str,
cond: bool,
val: &T,
) -> &mut std::fmt::DebugStruct<'a, 'b> {
if cond {
self.field(name, val)
} else {
self
}
}

fn h2_field_some<T: std::fmt::Debug>(
&mut self,
name: &str,
val: &Option<T>,
) -> &mut std::fmt::DebugStruct<'a, 'b> {
if val.is_some() {
self.field(name, val)
} else {
self
}
}
}
10 changes: 9 additions & 1 deletion src/proto/streams/state.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt;
use std::io;

use crate::codec::UserError;
Expand Down Expand Up @@ -47,7 +48,7 @@ use self::Peer::*;
/// ES: END_STREAM flag
/// R: RST_STREAM frame
/// ```
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct State {
inner: Inner,
}
Expand Down Expand Up @@ -465,3 +466,10 @@ impl Default for State {
State { inner: Inner::Idle }
}
}

// remove some noise for debug output
impl fmt::Debug for State {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.inner.fmt(f)
}
}
10 changes: 9 additions & 1 deletion src/proto/streams/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub(crate) struct Key {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct SlabIndex(u32);

#[derive(Debug)]
pub(super) struct Queue<N> {
indices: Option<store::Indices>,
_p: PhantomData<N>,
Expand Down Expand Up @@ -378,6 +377,15 @@ where
}
}

impl<N> fmt::Debug for Queue<N> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Queue")
.field("indices", &self.indices)
// skip phantom data
.finish()
}
}

// ===== impl Ptr =====

impl<'a> Ptr<'a> {
Expand Down
54 changes: 33 additions & 21 deletions src/proto/streams/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,35 +398,47 @@ impl fmt::Debug for Stream {
.field("state", &self.state)
.field("is_counted", &self.is_counted)
.field("ref_count", &self.ref_count)
.field("next_pending_send", &self.next_pending_send)
.field("is_pending_send", &self.is_pending_send)
.h2_field_some("next_pending_send", &self.next_pending_send)
.h2_field_if("is_pending_send", &self.is_pending_send)
.field("send_flow", &self.send_flow)
.field("requested_send_capacity", &self.requested_send_capacity)
.field("buffered_send_data", &self.buffered_send_data)
.field("send_task", &self.send_task.as_ref().map(|_| ()))
.field("pending_send", &self.pending_send)
.field(
.h2_field_some("send_task", &self.send_task.as_ref().map(|_| ()))
.h2_field_if_then(
"pending_send",
!self.pending_send.is_empty(),
&self.pending_send,
)
.h2_field_some(
"next_pending_send_capacity",
&self.next_pending_send_capacity,
)
.field("is_pending_send_capacity", &self.is_pending_send_capacity)
.field("send_capacity_inc", &self.send_capacity_inc)
.field("next_open", &self.next_open)
.field("is_pending_open", &self.is_pending_open)
.field("is_pending_push", &self.is_pending_push)
.field("next_pending_accept", &self.next_pending_accept)
.field("is_pending_accept", &self.is_pending_accept)
.h2_field_if("is_pending_send_capacity", &self.is_pending_send_capacity)
.h2_field_if("send_capacity_inc", &self.send_capacity_inc)
.h2_field_some("next_open", &self.next_open)
.h2_field_if("is_pending_open", &self.is_pending_open)
.h2_field_if("is_pending_push", &self.is_pending_push)
.h2_field_some("next_pending_accept", &self.next_pending_accept)
.h2_field_if("is_pending_accept", &self.is_pending_accept)
.field("recv_flow", &self.recv_flow)
.field("in_flight_recv_data", &self.in_flight_recv_data)
.field("next_window_update", &self.next_window_update)
.field("is_pending_window_update", &self.is_pending_window_update)
.field("reset_at", &self.reset_at)
.field("next_reset_expire", &self.next_reset_expire)
.field("pending_recv", &self.pending_recv)
.field("is_recv", &self.is_recv)
.field("recv_task", &self.recv_task.as_ref().map(|_| ()))
.field("push_task", &self.push_task.as_ref().map(|_| ()))
.field("pending_push_promises", &self.pending_push_promises)
.h2_field_some("next_window_update", &self.next_window_update)
.h2_field_if("is_pending_window_update", &self.is_pending_window_update)
.h2_field_some("reset_at", &self.reset_at)
.h2_field_some("next_reset_expire", &self.next_reset_expire)
.h2_field_if_then(
"pending_recv",
!self.pending_recv.is_empty(),
&self.pending_recv,
)
.h2_field_if("is_recv", &self.is_recv)
.h2_field_some("recv_task", &self.recv_task.as_ref().map(|_| ()))
.h2_field_some("push_task", &self.push_task.as_ref().map(|_| ()))
.h2_field_if_then(
"pending_push_promises",
!self.pending_push_promises.is_empty(),
&self.pending_push_promises,
)
.field("content_length", &self.content_length)
.finish()
}
Expand Down