h3: avoid needless copy when checking dgram queue In an old version of the DATAGRAM poll event, it returned an HTTP/3 datagram flow ID, which required peeking at the first 8 bytes of the QUIC frame payload at the front of the queue. When we changed to edge-triggered events, we changed the logic to always return the placeholder value 0. However, we didn't change the logic to avoid peeking at the data, which meant we left a needless 8-byte allocation and copy. This change removes the needless copy, replacing it instead with a check of the queue length to determine if the edge-trigger should fire or not.
diff --git a/quiche/src/h3/mod.rs b/quiche/src/h3/mod.rs index 0af162f..1cec93e 100644 --- a/quiche/src/h3/mod.rs +++ b/quiche/src/h3/mod.rs
@@ -1337,29 +1337,19 @@ fn process_dgrams( &mut self, conn: &mut super::Connection, ) -> Result<(u64, Event)> { - let mut d = [0; 8]; + if conn.dgram_recv_queue_len() > 0 { + if self.dgram_event_triggered { + return Err(Error::Done); + } - match conn.dgram_recv_peek(&mut d, 8) { - Ok(_) => { - if self.dgram_event_triggered { - return Err(Error::Done); - } + self.dgram_event_triggered = true; - self.dgram_event_triggered = true; - - Ok((0, Event::Datagram)) - }, - - Err(crate::Error::Done) => { - // The dgram recv queue is empty, so re-arm the Datagram event - // so it is issued next time a DATAGRAM is received. - self.dgram_event_triggered = false; - - Err(Error::Done) - }, - - Err(e) => Err(Error::TransportError(e)), + return Ok((0, Event::Datagram)); } + + self.dgram_event_triggered = false; + + Err(Error::Done) } /// Reads request or response body data into the provided buffer.