From 062ba6c0078958d927ff3ac632313bce009b682a Mon Sep 17 00:00:00 2001 From: Povilas Balciunas Date: Fri, 9 Nov 2018 10:34:01 +0200 Subject: Add example for setsockopt Makes it easier for newcomers :) --- src/sys/socket/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 4ee1acee..85acaf4c 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -976,6 +976,20 @@ pub fn getsockopt(fd: RawFd, opt: O) -> Result { /// Sets the value for the requested socket option /// /// [Further reading](http://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html) +/// +/// # 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()); +/// ``` pub fn setsockopt(fd: RawFd, opt: O, val: &O::Val) -> Result<()> { opt.set(fd, val) } -- cgit v1.2.3