diff options
author | Povilas Balciunas <balciunas90@gmail.com> | 2018-11-09 10:34:01 +0200 |
---|---|---|
committer | Povilas Balciunas <balciunas90@gmail.com> | 2018-11-09 10:34:01 +0200 |
commit | 062ba6c0078958d927ff3ac632313bce009b682a (patch) | |
tree | 14f8b8f7f1e6c457ca303b5cd0bd00887a6357ab /src | |
parent | 8c3e43ccd4fc83583c16848a35410022f5a8efc9 (diff) | |
download | nix-062ba6c0078958d927ff3ac632313bce009b682a.zip |
Add example for setsockopt
Makes it easier for newcomers :)
Diffstat (limited to 'src')
-rw-r--r-- | src/sys/socket/mod.rs | 14 |
1 files changed, 14 insertions, 0 deletions
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<O: GetSockOpt>(fd: RawFd, opt: O) -> Result<O::Val> { /// 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<O: SetSockOpt>(fd: RawFd, opt: O, val: &O::Val) -> Result<()> { opt.set(fd, val) } |