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 25, 2018
1 parent d17d645 commit a554a2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/libstd/sys/redox/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

use cmp;
use io::{Error, ErrorKind, Result};
use io::{self, Error, ErrorKind, Result};
use mem;
use net::{SocketAddr, Shutdown};
use path::Path;
Expand Down 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 duration.as_secs() == 0 && duration.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 duration.as_secs() == 0 && duration.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
10 changes: 9 additions & 1 deletion src/libstd/sys/redox/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use cell::UnsafeCell;
use cmp;
use io::{Error, ErrorKind, Result};
use io::{self, Error, ErrorKind, Result};
use mem;
use net::{SocketAddr, Ipv4Addr, Ipv6Addr};
use path::Path;
Expand Down 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 duration.as_secs() == 0 && duration.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 duration.as_secs() == 0 && duration.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 a554a2f

Please sign in to comment.