diff --git a/qlog/src/streamer.rs b/qlog/src/streamer.rs index e0ef324c08..cb13fd3765 100644 --- a/qlog/src/streamer.rs +++ b/qlog/src/streamer.rs @@ -229,6 +229,12 @@ impl QlogStreamer { } } +impl Drop for QlogStreamer { + fn drop(&mut self) { + let _ = self.finish_log(); + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/quiche/src/lib.rs b/quiche/src/lib.rs index 9117812573..0b52a769f2 100644 --- a/quiche/src/lib.rs +++ b/quiche/src/lib.rs @@ -1649,21 +1649,6 @@ macro_rules! push_frame_to_pkt { }}; } -/// Conditional qlog actions. -/// -/// Executes the provided body if the qlog feature is enabled and quiche -/// has been configured with a log writer. -macro_rules! qlog_with { - ($qlog:expr, $qlog_streamer_ref:ident, $body:block) => {{ - #[cfg(feature = "qlog")] - { - if let Some($qlog_streamer_ref) = &mut $qlog.streamer { - $body - } - } - }}; -} - /// Executes the provided body if the qlog feature is enabled, quiche has been /// configured with a log writer, the event's importance is within the /// configured level. @@ -2188,7 +2173,7 @@ impl Connection { if self.is_stateless_reset(&buf[len - left..len]) { trace!("{} packet is a stateless reset", self.trace_id); - self.closed = true; + self.mark_closed(); } left @@ -5588,11 +5573,7 @@ impl Connection { if draining_timer <= now { trace!("{} draining timeout expired", self.trace_id); - qlog_with!(self.qlog, q, { - q.finish_log().ok(); - }); - - self.closed = true; + self.mark_closed(); } // Draining timer takes precedence over all other timers. If it is @@ -5605,11 +5586,7 @@ impl Connection { if timer <= now { trace!("{} idle timeout expired", self.trace_id); - qlog_with!(self.qlog, q, { - q.finish_log().ok(); - }); - - self.closed = true; + self.mark_closed(); self.timed_out = true; return; } @@ -5663,11 +5640,13 @@ impl Connection { Some(pid) => if self.set_active_path(pid, now).is_err() { // The connection cannot continue. - self.closed = true; + self.mark_closed(); }, // The connection cannot continue. - None => self.closed = true, + None => { + self.mark_closed(); + }, } } } @@ -6092,7 +6071,7 @@ impl Connection { // When no packet was successfully processed close connection immediately. if self.recv_count == 0 { - self.closed = true; + self.mark_closed(); } Ok(()) @@ -7482,6 +7461,15 @@ impl Connection { Ok(pid) } + + // Marks the connection as closed and does any related tidyup. + fn mark_closed(&mut self) { + #[cfg(feature = "qlog")] + { + self.qlog.streamer = None; + } + self.closed = true; + } } #[cfg(feature = "boringssl-boring-crate")]