Skip to content

Commit

Permalink
Disable the native system timeout for socket
Browse files Browse the repository at this point in the history
  • Loading branch information
RazvanRotari authored and lolgesten committed Jan 17, 2020
1 parent daaf84a commit 09dabbd
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/stream.rs
Expand Up @@ -181,15 +181,25 @@ pub(crate) fn connect_host(unit: &Unit, hostname: &str, port: u16) -> Result<Tcp
.map_err(|err| Error::ConnectionFailed(format!("{}", err)))?;

// rust's absurd api returns Err if we set 0.
// Setting it to None will disable the native system timeout
if unit.timeout_read > 0 {
stream
.set_read_timeout(Some(Duration::from_millis(unit.timeout_read as u64)))
.ok();
} else {
stream
.set_read_timeout(None)
.ok();
}

if unit.timeout_write > 0 {
stream
.set_write_timeout(Some(Duration::from_millis(unit.timeout_write as u64)))
.ok();
} else {
stream
.set_write_timeout(None)
.ok();
}

Ok(stream)
Expand Down

0 comments on commit 09dabbd

Please sign in to comment.