Add tcp capacity impls

This commit is contained in:
Scott Mabin 2023-08-14 20:58:44 +01:00
parent b6b4448045
commit b1ef009c6b

View File

@ -93,6 +93,11 @@ impl<'a> TcpReader<'a> {
{ {
self.io.read_with(f).await self.io.read_with(f).await
} }
/// Return the maximum number of bytes inside the transmit buffer.
pub fn recv_capacity(&self) -> usize {
self.io.recv_capacity()
}
} }
impl<'a> TcpWriter<'a> { impl<'a> TcpWriter<'a> {
@ -122,6 +127,11 @@ impl<'a> TcpWriter<'a> {
{ {
self.io.write_with(f).await self.io.write_with(f).await
} }
/// Return the maximum number of bytes inside the transmit buffer.
pub fn send_capacity(&self) -> usize {
self.io.send_capacity()
}
} }
impl<'a> TcpSocket<'a> { impl<'a> TcpSocket<'a> {
@ -143,6 +153,16 @@ impl<'a> TcpSocket<'a> {
} }
} }
/// Return the maximum number of bytes inside the recv buffer.
pub fn recv_capacity(&self) -> usize {
self.io.recv_capacity()
}
/// Return the maximum number of bytes inside the transmit buffer.
pub fn send_capacity(&self) -> usize {
self.io.send_capacity()
}
/// Call `f` with the largest contiguous slice of octets in the transmit buffer, /// Call `f` with the largest contiguous slice of octets in the transmit buffer,
/// and enqueue the amount of elements returned by `f`. /// and enqueue the amount of elements returned by `f`.
/// ///
@ -478,6 +498,14 @@ impl<'d> TcpIo<'d> {
}) })
.await .await
} }
fn recv_capacity(&self) -> usize {
self.with(|s, _| s.recv_capacity())
}
fn send_capacity(&self) -> usize {
self.with(|s, _| s.send_capacity())
}
} }
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]