Skip to content

Commit

Permalink
Return error if timeout is zero-Duration on Redox.
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Feb 19, 2018
1 parent d17d645 commit 0755825
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/libstd/sys/redox/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ impl TcpStream {
pub fn set_read_timeout(&self, duration_option: Option<Duration>) -> Result<()> {
let file = self.0.dup(b"read_timeout")?;
if let Some(duration) = duration_option {
if dur.as_secs() == 0 && dur.subsec_nanos() == 0 {
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"cannot set a 0 duration timeout"));
}
file.write(&TimeSpec {
tv_sec: duration.as_secs() as i64,
tv_nsec: duration.subsec_nanos() as i32
Expand All @@ -143,6 +147,10 @@ impl TcpStream {
pub fn set_write_timeout(&self, duration_option: Option<Duration>) -> Result<()> {
let file = self.0.dup(b"write_timeout")?;
if let Some(duration) = duration_option {
if dur.as_secs() == 0 && dur.subsec_nanos() == 0 {
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"cannot set a 0 duration timeout"));
}
file.write(&TimeSpec {
tv_sec: duration.as_secs() as i64,
tv_nsec: duration.subsec_nanos() as i32
Expand Down
8 changes: 8 additions & 0 deletions src/libstd/sys/redox/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ impl UdpSocket {
pub fn set_read_timeout(&self, duration_option: Option<Duration>) -> Result<()> {
let file = self.0.dup(b"read_timeout")?;
if let Some(duration) = duration_option {
if dur.as_secs() == 0 && dur.subsec_nanos() == 0 {
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"cannot set a 0 duration timeout"));
}
file.write(&TimeSpec {
tv_sec: duration.as_secs() as i64,
tv_nsec: duration.subsec_nanos() as i32
Expand All @@ -192,6 +196,10 @@ impl UdpSocket {
pub fn set_write_timeout(&self, duration_option: Option<Duration>) -> Result<()> {
let file = self.0.dup(b"write_timeout")?;
if let Some(duration) = duration_option {
if dur.as_secs() == 0 && dur.subsec_nanos() == 0 {
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"cannot set a 0 duration timeout"));
}
file.write(&TimeSpec {
tv_sec: duration.as_secs() as i64,
tv_nsec: duration.subsec_nanos() as i32
Expand Down

0 comments on commit 0755825

Please sign in to comment.