Skip to content

Commit

Permalink
Add capacity methods to all sockets.
Browse files Browse the repository at this point in the history
  • Loading branch information
MabezDev authored and whitequark committed Nov 5, 2019
1 parent 2b92dfc commit a67ee07
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/socket/icmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,30 @@ impl<'a, 'b> IcmpSocket<'a, 'b> {
!self.rx_buffer.is_empty()
}

/// Return the maximum number packets the socket can receive.
#[inline]
pub fn packet_recv_capacity(&self) -> usize {
self.rx_buffer.packet_capacity()
}

/// Return the maximum number packets the socket can transmit.
#[inline]
pub fn packet_send_capacity(&self) -> usize {
self.tx_buffer.packet_capacity()
}

/// Return the maximum number of bytes inside the recv buffer.
#[inline]
pub fn payload_recv_capacity(&self) -> usize {
self.rx_buffer.payload_capacity()
}

/// Return the maximum number of bytes inside the transmit buffer.
#[inline]
pub fn payload_send_capacity(&self) -> usize {
self.tx_buffer.payload_capacity()
}

/// Check whether the socket is open.
#[inline]
pub fn is_open(&self) -> bool {
Expand Down
24 changes: 24 additions & 0 deletions src/socket/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ impl<'a, 'b> RawSocket<'a, 'b> {
!self.rx_buffer.is_empty()
}

/// Return the maximum number packets the socket can receive.
#[inline]
pub fn packet_recv_capacity(&self) -> usize {
self.rx_buffer.packet_capacity()
}

/// Return the maximum number packets the socket can transmit.
#[inline]
pub fn packet_send_capacity(&self) -> usize {
self.tx_buffer.packet_capacity()
}

/// Return the maximum number of bytes inside the recv buffer.
#[inline]
pub fn payload_recv_capacity(&self) -> usize {
self.rx_buffer.payload_capacity()
}

/// Return the maximum number of bytes inside the transmit buffer.
#[inline]
pub fn payload_send_capacity(&self) -> usize {
self.tx_buffer.payload_capacity()
}

/// Enqueue a packet to send, and return a pointer to its payload.
///
/// This function returns `Err(Error::Exhausted)` if the transmit buffer is full,
Expand Down
12 changes: 12 additions & 0 deletions src/socket/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,18 @@ impl<'a> TcpSocket<'a> {
!self.tx_buffer.is_full()
}

/// Return the maximum number of bytes inside the recv buffer.
#[inline]
pub fn recv_capacity(&self) -> usize {
self.rx_buffer.capacity()
}

/// Return the maximum number of bytes inside the transmit buffer.
#[inline]
pub fn send_capacity(&self) -> usize {
self.tx_buffer.capacity()
}

/// Check whether the receive half of the full-duplex connection buffer is open
/// (see [may_recv](#method.may_recv), and the receive buffer is not empty.
#[inline]
Expand Down
24 changes: 24 additions & 0 deletions src/socket/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,30 @@ impl<'a, 'b> UdpSocket<'a, 'b> {
!self.rx_buffer.is_empty()
}

/// Return the maximum number packets the socket can receive.
#[inline]
pub fn packet_recv_capacity(&self) -> usize {
self.rx_buffer.packet_capacity()
}

/// Return the maximum number packets the socket can transmit.
#[inline]
pub fn packet_send_capacity(&self) -> usize {
self.tx_buffer.packet_capacity()
}

/// Return the maximum number of bytes inside the recv buffer.
#[inline]
pub fn payload_recv_capacity(&self) -> usize {
self.rx_buffer.payload_capacity()
}

/// Return the maximum number of bytes inside the transmit buffer.
#[inline]
pub fn payload_send_capacity(&self) -> usize {
self.tx_buffer.payload_capacity()
}

/// Enqueue a packet to be sent to a given remote endpoint, and return a pointer
/// to its payload.
///
Expand Down
10 changes: 10 additions & 0 deletions src/storage/packet_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ impl<'a, 'b, H> PacketBuffer<'a, 'b, H> {
Err(Error::Exhausted)
}
}

/// Return the maximum number packets that can be stored.
pub fn packet_capacity(&self) -> usize {
self.metadata_ring.capacity()
}

/// Return the maximum number of bytes in the payload ring buffer.
pub fn payload_capacity(&self) -> usize {
self.payload_ring.capacity()
}
}

#[cfg(test)]
Expand Down

0 comments on commit a67ee07

Please sign in to comment.