pub fn setsockopt<O>(
    fd: i32,
    opt: O,
    val: &<O as SetSockOpt>::Val
) -> Result<(), Errno> where
    O: SetSockOpt
Expand description

Sets the value for the requested socket option

Further reading

Examples

use nix::sys::socket::setsockopt;
use nix::sys::socket::sockopt::KeepAlive;
use std::net::TcpListener;
use std::os::unix::io::AsRawFd;

let listener = TcpListener::bind("0.0.0.0:0").unwrap();
let fd = listener.as_raw_fd();
let res = setsockopt(fd, KeepAlive, &true);
assert!(res.is_ok());