From a71542b2f220a01aa0a66819b7fea1caaca37b49 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 31 Aug 2017 13:22:20 +0000 Subject: [PATCH] Allow querying the size of the TCP transmit and receive buffers. This may be useful to e.g. ensure the complete transmit buffer is flushed before proceeding. --- src/socket/tcp.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/socket/tcp.rs b/src/socket/tcp.rs index 91de8f5..698e271 100644 --- a/src/socket/tcp.rs +++ b/src/socket/tcp.rs @@ -683,6 +683,20 @@ impl<'a> TcpSocket<'a> { Ok(buffer.len()) } + /// Return the amount of octets queued in the transmit buffer. + /// + /// Note that the Berkeley sockets interface does not have an equivalent of this API. + pub fn send_queue(&self) -> usize { + self.tx_buffer.len() + } + + /// Return the amount of octets queued in the receive buffer. + /// + /// Note that the Berkeley sockets interface does not have an equivalent of this API. + pub fn recv_queue(&self) -> usize { + self.rx_buffer.len() + } + fn set_state(&mut self, state: State) { if self.state != state { if self.remote_endpoint.addr.is_unspecified() {