summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-11-09 15:43:50 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-11-09 15:43:50 +0000
commite1a9f4b4eb7642ecbadf189cd0cf8038400d39a8 (patch)
tree14f8b8f7f1e6c457ca303b5cd0bd00887a6357ab /src/sys
parent8c3e43ccd4fc83583c16848a35410022f5a8efc9 (diff)
parent062ba6c0078958d927ff3ac632313bce009b682a (diff)
downloadnix-e1a9f4b4eb7642ecbadf189cd0cf8038400d39a8.zip
Merge #970
970: Add example for setsockopt r=asomers a=povilasb > Every great project needs great documentation ...one step at a time though :) Co-authored-by: Povilas Balciunas <balciunas90@gmail.com>
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/socket/mod.rs14
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)
}