nix::sys::socket

Function setsockopt

source
pub fn setsockopt<F: AsFd, O: SetSockOpt>(
    fd: &F,
    opt: O,
    val: &O::Val,
) -> Result<()>
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());