summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/quiche.h12
-rw-r--r--src/dgram.rs4
-rw-r--r--src/ffi.rs24
-rw-r--r--src/lib.rs45
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
}
diff --git a/src/ffi.rs b/src/ffi.rs
index b2476562..edcf7c1e 100644
--- a/src/ffi.rs
+++ b/src/ffi.rs
@@ -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 {
diff --git a/src/lib.rs b/src/lib.rs
index f1bb2e77..f546acd4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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]