diff options
author | 2021-05-29 03:49:12 +0100 | |
---|---|---|
committer | 2021-06-03 13:10:52 +0100 | |
commit | c9e7ab567f95d19b67bf0940833f3c66d478242c (patch) | |
tree | c6bb72fb3040bb70b9f222f59e594258bc0e9650 | |
parent | 52696e04f421c718f0ad7ab4adcda604358b0eee (diff) | |
download | quiche-c9e7ab567f95d19b67bf0940833f3c66d478242c.tar.gz quiche-c9e7ab567f95d19b67bf0940833f3c66d478242c.tar.zst quiche-c9e7ab567f95d19b67bf0940833f3c66d478242c.zip |
lib: expose functions to read DATAGRAM frame queue length and size
-rw-r--r-- | include/quiche.h | 12 | ||||
-rw-r--r-- | src/dgram.rs | 4 | ||||
-rw-r--r-- | src/ffi.rs | 24 | ||||
-rw-r--r-- | src/lib.rs | 45 |
4 files changed, 85 insertions, 0 deletions
diff --git a/include/quiche.h b/include/quiche.h index b3dbd37f..ba0f04a6 100644 --- a/include/quiche.h +++ b/include/quiche.h @@ -434,6 +434,18 @@ ssize_t quiche_conn_dgram_max_writable_len(quiche_conn *conn); // Returns the length of the first stored DATAGRAM. ssize_t quiche_conn_dgram_recv_front_len(quiche_conn *conn); +// Returns the number of items in the DATAGRAM receive queue. +ssize_t quiche_conn_dgram_recv_queue_len(quiche_conn *conn); + +///Returns the total size of all items in the DATAGRAM receive queue. +ssize_t quiche_conn_dgram_recv_queue_byte_size(quiche_conn *conn); + +// Returns the number of items in the DATAGRAM send queue. +ssize_t quiche_conn_dgram_send_queue_len(quiche_conn *conn); + +// Returns the total size of all items in the DATAGRAM send queue. +ssize_t quiche_conn_dgram_send_queue_byte_size(quiche_conn *conn); + // Reads the first received DATAGRAM. ssize_t quiche_conn_dgram_recv(quiche_conn *conn, uint8_t *buf, size_t buf_len); diff --git a/src/dgram.rs b/src/dgram.rs index 755d95f2..023df5f4 100644 --- a/src/dgram.rs +++ b/src/dgram.rs @@ -99,6 +99,10 @@ impl DatagramQueue { self.queue.len() == self.queue_max_len } + pub fn len(&self) -> usize { + self.queue.len() + } + pub fn byte_size(&self) -> usize { self.queue_bytes_size } @@ -984,6 +984,30 @@ pub extern fn quiche_conn_dgram_recv_front_len(conn: &Connection) -> ssize_t { } #[no_mangle] +pub extern fn quiche_conn_dgram_recv_queue_len(conn: &Connection) -> ssize_t { + conn.dgram_recv_queue_len() as ssize_t +} + +#[no_mangle] +pub extern fn quiche_conn_dgram_recv_queue_byte_size( + conn: &Connection, +) -> ssize_t { + conn.dgram_recv_queue_byte_size() as ssize_t +} + +#[no_mangle] +pub extern fn quiche_conn_dgram_send_queue_len(conn: &Connection) -> ssize_t { + conn.dgram_send_queue_len() as ssize_t +} + +#[no_mangle] +pub extern fn quiche_conn_dgram_send_queue_byte_size( + conn: &Connection, +) -> ssize_t { + conn.dgram_send_queue_byte_size() as ssize_t +} + +#[no_mangle] pub extern fn quiche_conn_dgram_send( conn: &mut Connection, buf: *const u8, buf_len: size_t, ) -> ssize_t { @@ -3807,6 +3807,30 @@ impl Connection { self.dgram_recv_queue.peek_front_len() } + /// Returns the number of items in the DATAGRAM receive queue. + #[inline] + pub fn dgram_recv_queue_len(&self) -> usize { + self.dgram_recv_queue.len() + } + + /// Returns the total size of all items in the DATAGRAM receive queue. + #[inline] + pub fn dgram_recv_queue_byte_size(&self) -> usize { + self.dgram_recv_queue.byte_size() + } + + /// Returns the number of items in the DATAGRAM send queue. + #[inline] + pub fn dgram_send_queue_len(&self) -> usize { + self.dgram_send_queue.len() + } + + /// Returns the total size of all items in the DATAGRAM send queue. + #[inline] + pub fn dgram_send_queue_byte_size(&self) -> usize { + self.dgram_send_queue.byte_size() + } + /// Sends data in a DATAGRAM frame. /// /// [`Done`] is returned if no data was written. @@ -9527,15 +9551,33 @@ mod tests { let mut pipe = testing::Pipe::with_config(&mut config).unwrap(); assert_eq!(pipe.handshake(), Ok(())); + assert_eq!(pipe.client.dgram_send_queue_len(), 0); + assert_eq!(pipe.client.dgram_send_queue_byte_size(), 0); + assert_eq!(pipe.client.dgram_send(b"hello, world"), Ok(())); assert_eq!(pipe.client.dgram_send(b"ciao, mondo"), Ok(())); assert_eq!(pipe.client.dgram_send(b"hola, mundo"), Ok(())); + assert_eq!(pipe.client.dgram_send_queue_byte_size(), 34); + pipe.client .dgram_purge_outgoing(|d: &[u8]| -> bool { d[0] == b'c' }); + assert_eq!(pipe.client.dgram_send_queue_len(), 2); + assert_eq!(pipe.client.dgram_send_queue_byte_size(), 23); + + // Before packets exchanged, no dgrams on server receive side. + assert_eq!(pipe.server.dgram_recv_queue_len(), 0); + assert_eq!(pipe.advance(), Ok(())); + // After packets exchanged, no dgrams on client send side. + assert_eq!(pipe.client.dgram_send_queue_len(), 0); + assert_eq!(pipe.client.dgram_send_queue_byte_size(), 0); + + assert_eq!(pipe.server.dgram_recv_queue_len(), 2); + assert_eq!(pipe.server.dgram_recv_queue_byte_size(), 23); + let result1 = pipe.server.dgram_recv(&mut buf); assert_eq!(result1, Ok(12)); assert_eq!(buf[0], b'h'); @@ -9548,6 +9590,9 @@ mod tests { let result3 = pipe.server.dgram_recv(&mut buf); assert_eq!(result3, Err(Error::Done)); + + assert_eq!(pipe.server.dgram_recv_queue_len(), 0); + assert_eq!(pipe.server.dgram_recv_queue_byte_size(), 0); } #[test] |