Skip to content

Commit

Permalink
Merge #970
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bors[bot] and povilasb committed Nov 9, 2018
2 parents 8c3e43c + 062ba6c commit e1a9f4b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/sys/socket/mod.rs
Expand Up @@ -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)
}
Expand Down

0 comments on commit e1a9f4b

Please sign in to comment.