Fix setsockopt
and getsockopt
parameter names.
Previously `level` was named `opt` and `option_name` was named `val`, then extra names of `payload` or `slot` were used for the option value. This change aligns the wrapper parameters with their names in POSIX. Winsock uses similar but more abbreviated names: `level`, `optname`, `optval`, `optlen`.
This commit is contained in:
parent
45e2c2881d
commit
3eb983ed99
@ -58,21 +58,37 @@
|
||||
// sockaddr and misc bindings
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
pub fn setsockopt<T>(sock: &Socket, opt: c_int, val: c_int, payload: T) -> io::Result<()> {
|
||||
pub fn setsockopt<T>(
|
||||
sock: &Socket,
|
||||
level: c_int,
|
||||
option_name: c_int,
|
||||
option_value: T,
|
||||
) -> io::Result<()> {
|
||||
unsafe {
|
||||
let payload = &payload as *const T as *const c_void;
|
||||
cvt(c::setsockopt(sock.as_raw(), opt, val, payload, mem::size_of::<T>() as c::socklen_t))?;
|
||||
cvt(c::setsockopt(
|
||||
sock.as_raw(),
|
||||
level,
|
||||
option_name,
|
||||
&option_value as *const T as *const _,
|
||||
mem::size_of::<T>() as c::socklen_t,
|
||||
))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getsockopt<T: Copy>(sock: &Socket, opt: c_int, val: c_int) -> io::Result<T> {
|
||||
pub fn getsockopt<T: Copy>(sock: &Socket, level: c_int, option_name: c_int) -> io::Result<T> {
|
||||
unsafe {
|
||||
let mut slot: T = mem::zeroed();
|
||||
let mut len = mem::size_of::<T>() as c::socklen_t;
|
||||
cvt(c::getsockopt(sock.as_raw(), opt, val, &mut slot as *mut _ as *mut _, &mut len))?;
|
||||
assert_eq!(len as usize, mem::size_of::<T>());
|
||||
Ok(slot)
|
||||
let mut option_value: T = mem::zeroed();
|
||||
let mut option_len = mem::size_of::<T>() as c::socklen_t;
|
||||
cvt(c::getsockopt(
|
||||
sock.as_raw(),
|
||||
level,
|
||||
option_name,
|
||||
&mut option_value as *mut T as *mut _,
|
||||
&mut option_len,
|
||||
))?;
|
||||
assert_eq!(option_len as usize, mem::size_of::<T>());
|
||||
Ok(option_value)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user