Skip to content

Commit

Permalink
Move the openbsd-specific case after the general unix code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozef Hatala committed May 19, 2020
1 parent f061e5e commit f98618d
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,24 +738,6 @@ impl TcpStreamExt for TcpStream {
Ok(Some((secs as u32) * 1000))
}

#[cfg(target_os = "openbsd")]
fn set_keepalive_ms(&self, keepalive: Option<u32>) -> io::Result<()> {
set_opt(self.as_sock(), SOL_SOCKET, SO_KEEPALIVE,
keepalive.is_some() as c_int)?;
Ok(())
}

#[cfg(target_os = "openbsd")]
fn keepalive_ms(&self) -> io::Result<Option<u32>> {
let keepalive = get_opt::<c_int>(self.as_sock(), SOL_SOCKET,
SO_KEEPALIVE)?;
if keepalive == 0 {
return Ok(None)
} else {
return Ok(Some(1u32))
}
}

#[cfg(all(unix, not(target_os = "openbsd")))]
fn set_keepalive_ms(&self, keepalive: Option<u32>) -> io::Result<()> {
try!(set_opt(self.as_sock(), SOL_SOCKET, SO_KEEPALIVE,
Expand All @@ -779,6 +761,24 @@ impl TcpStreamExt for TcpStream {
Ok(Some((secs as u32) * 1000))
}

#[cfg(target_os = "openbsd")]
fn set_keepalive_ms(&self, keepalive: Option<u32>) -> io::Result<()> {
set_opt(self.as_sock(), SOL_SOCKET, SO_KEEPALIVE,
keepalive.is_some() as c_int)?;
Ok(())
}

#[cfg(target_os = "openbsd")]
fn keepalive_ms(&self) -> io::Result<Option<u32>> {
let keepalive = get_opt::<c_int>(self.as_sock(), SOL_SOCKET,
SO_KEEPALIVE)?;
if keepalive == 0 {
return Ok(None)
} else {
return Ok(Some(1u32))
}
}

#[cfg(target_os = "wasi")]
fn set_keepalive_ms(&self, _keepalive: Option<u32>) -> io::Result<()> {
unimplemented!()
Expand Down

0 comments on commit f98618d

Please sign in to comment.