[][src]Function nix::sys::socket::setsockopt

pub fn setsockopt<O: SetSockOpt>(fd: RawFd, opt: O, val: &O::Val) -> Result<()>

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());