9
9
// except according to those terms.
10
10
11
11
use cmp;
12
- use io:: { Error , ErrorKind , Result } ;
12
+ use io:: { self , Error , ErrorKind , Result } ;
13
13
use mem;
14
14
use net:: { SocketAddr , Shutdown } ;
15
15
use path:: Path ;
@@ -130,6 +130,10 @@ impl TcpStream {
130
130
pub fn set_read_timeout ( & self , duration_option : Option < Duration > ) -> Result < ( ) > {
131
131
let file = self . 0 . dup ( b"read_timeout" ) ?;
132
132
if let Some ( duration) = duration_option {
133
+ if duration. as_secs ( ) == 0 && duration. subsec_nanos ( ) == 0 {
134
+ return Err ( io:: Error :: new ( io:: ErrorKind :: InvalidInput ,
135
+ "cannot set a 0 duration timeout" ) ) ;
136
+ }
133
137
file. write ( & TimeSpec {
134
138
tv_sec : duration. as_secs ( ) as i64 ,
135
139
tv_nsec : duration. subsec_nanos ( ) as i32
@@ -143,6 +147,10 @@ impl TcpStream {
143
147
pub fn set_write_timeout ( & self , duration_option : Option < Duration > ) -> Result < ( ) > {
144
148
let file = self . 0 . dup ( b"write_timeout" ) ?;
145
149
if let Some ( duration) = duration_option {
150
+ if duration. as_secs ( ) == 0 && duration. subsec_nanos ( ) == 0 {
151
+ return Err ( io:: Error :: new ( io:: ErrorKind :: InvalidInput ,
152
+ "cannot set a 0 duration timeout" ) ) ;
153
+ }
146
154
file. write ( & TimeSpec {
147
155
tv_sec : duration. as_secs ( ) as i64 ,
148
156
tv_nsec : duration. subsec_nanos ( ) as i32
0 commit comments