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

Issue: #523 #524

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
62 changes: 62 additions & 0 deletions src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,68 @@ impl crate::Socket {
}
}
Kleinmarb marked this conversation as resolved.
Show resolved Hide resolved

/// Get the value of the `SO_RCVLOWAT` option on this socket.
///
/// For more information about this option, see [`set_rcv_lowat`].
///
/// [`set_rcv_lowat`]: crate::Socket::set_rcv_lowat
// TODO: add Redox support, but I'm not sure if Redox supports SO_RCVLOWAT
Kleinmarb marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(all(feature = "all", not(target_os = "redox")))]
pub fn rcv_lowat(&self) -> io::Result<u32> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we come up with more descriptive names for these functions?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe receive_lowat and send_lowat? Lowat stands for low water mark. maybe something with that?
Or we could add a get_ prefix which would not align with the naming conventions of these socket option getter functions, but would be more descriptive. You tell me, since I don't know how bad it is to break naming conventions in this repo.

unsafe {
getsockopt::<c_int>(self.as_raw(), libc::SOL_SOCKET, libc::SO_RCVLOWAT)
.map(|rcv_lowat| { rcv_lowat as u32})
}
}

/// Set the value of the `SO_RCVLOWAT` option on this socket.
///
/// This option sets the minimum number of bytes that must be available in the
/// receive buffer before a recv() or read() call will return.
// TODO: add Redox support, but I'm not sure if Redox supports SO_RCVLOWAT
#[cfg(all(feature = "all", not(target_os = "redox")))]
pub fn set_rcv_lowat(&self, rcv_lowat: u32) -> io::Result<()> {
unsafe {
setsockopt::<c_int>(
self.as_raw(),
libc::SOL_SOCKET,
libc::SO_RCVLOWAT,
rcv_lowat as c_int,
)
}
}

/// Get the value of the `SO_SNDLOWAT` option on this socket.
///
/// For more information about this option, see [`set_snd_lowat`].
///
/// [`set_snd_lowat`]: crate::Socket::set_snd_lowat
// TODO: add Redox support, but I'm not sure if Redox supports SO_SNDLOWAT
#[cfg(all(feature = "all", not(target_os = "redox")))]
pub fn snd_lowat(&self) -> io::Result<u32> {
unsafe {
getsockopt::<c_int>(self.as_raw(), libc::SOL_SOCKET, libc::SO_RCVLOWAT)
Kleinmarb marked this conversation as resolved.
Show resolved Hide resolved
.map(|snd_lowat| { snd_lowat as u32})
}
}

/// Set the value of the `SO_SNDLOWAT` option on this socket.
///
/// This option sets the minimum number of bytes that must be available in the send buffer
/// before a send() or write() call will return.
// TODO: add Redox support, but I'm not sure if Redox supports SO_SNDLOWAT
#[cfg(all(feature = "all", not(target_os = "redox")))]
pub fn set_snd_lowat(&self, snd_lowat: u32) -> io::Result<()> {
unsafe {
setsockopt::<c_int>(
self.as_raw(),
libc::SOL_SOCKET,
libc::SO_RCVLOWAT,
Kleinmarb marked this conversation as resolved.
Show resolved Hide resolved
snd_lowat as c_int,
)
}
}

/// Gets the value of the `TCP_MAXSEG` option on this socket.
///
/// For more information about this option, see [`set_mss`].
Expand Down