Skip to content

Commit

Permalink
Add 'get/set SO_RCVBUF' methods to the pub interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Byckevich committed Mar 27, 2024
1 parent ea7eb74 commit 025d8b4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,26 @@ impl Socket {
)?;
Ok(res == 1)
}

/// Sets socket receive buffer in bytes.
/// The kernel doubles this value (to allow space for bookkeeping overhead),
/// and this doubled value is returned by [get_rx_buf_sz].(see socket(7)
/// The default value is set by the proc/sys/net/core/rmem_default file, and the maximum
/// allowed value is set by the /proc/sys/net/core/rmem_max
/// file. The minimum (doubled) value for this option is 256.
pub fn set_rx_buf_sz<T>(&self, size: T) -> Result<()> {
setsockopt(self.0, libc::SOL_SOCKET, libc::SO_RCVBUF, size)
}

/// Gets socket receive buffer in bytes
pub fn get_rx_buf_sz(&self) -> Result<usize> {
let res = getsockopt::<libc::c_int>(
self.0,
libc::SOL_SOCKET,
libc::SO_RCVBUF,
)?;
Ok(res as usize)
}
}

/// Wrapper around `getsockopt`:
Expand Down

0 comments on commit 025d8b4

Please sign in to comment.