Function nix::sys::socket::setsockopt

source ·
pub fn setsockopt<F: AsFd, O: SetSockOpt>(
    fd: &F,
    opt: O,
    val: &O::Val
) -> Result<()>
Available on crate feature socket only.
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;

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