Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add send_queue/recv_queue to UDP/ICMP/Raw Socket #1003

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/socket/icmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,16 @@ impl<'a> Socket<'a> {
Ok((length, endpoint))
}

/// Return the amount of octets queued in the transmit buffer.
pub fn send_queue(&self) -> usize {
self.tx_buffer.payload_bytes_count()
}

/// Return the amount of octets queued in the receive buffer.
pub fn recv_queue(&self) -> usize {
self.rx_buffer.payload_bytes_count()
}

/// Fitler determining whether the socket accepts a given ICMPv4 packet.
/// Accepted packets are enqueued into the socket's receive buffer.
#[cfg(feature = "proto-ipv4")]
Expand Down
10 changes: 10 additions & 0 deletions src/socket/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,16 @@ impl<'a> Socket<'a> {
Ok(length)
}

/// Return the amount of octets queued in the transmit buffer.
pub fn send_queue(&self) -> usize {
self.tx_buffer.payload_bytes_count()
}

/// Return the amount of octets queued in the receive buffer.
pub fn recv_queue(&self) -> usize {
self.rx_buffer.payload_bytes_count()
}

pub(crate) fn accepts(&self, ip_repr: &IpRepr) -> bool {
if ip_repr.version() != self.ip_version {
return false;
Expand Down
16 changes: 16 additions & 0 deletions src/socket/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,22 @@ impl<'a> Socket<'a> {
Ok((length, endpoint))
}

/// 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.payload_bytes_count()
}

/// Return the amount of octets queued in the receive buffer. This value can be larger than
/// the slice read by the next `recv` or `peek` call because it includes all queued octets,
/// and not only the octets that may be returned as a contiguous slice.
///
/// Note that the Berkeley sockets interface does not have an equivalent of this API.
pub fn recv_queue(&self) -> usize {
self.rx_buffer.payload_bytes_count()
}

pub(crate) fn accepts(&self, cx: &mut Context, ip_repr: &IpRepr, repr: &UdpRepr) -> bool {
if self.endpoint.port != repr.dst_port {
return false;
Expand Down
5 changes: 5 additions & 0 deletions src/storage/packet_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ impl<'a, H> PacketBuffer<'a, H> {
self.payload_ring.capacity()
}

/// Return the current number of bytes in the payload ring buffer.
pub fn payload_bytes_count(&self) -> usize {
self.payload_ring.len()
}

/// Reset the packet buffer and clear any staged.
#[allow(unused)]
pub(crate) fn reset(&mut self) {
Expand Down
Loading