99// except according to those terms.
1010
1111use cmp;
12- use io:: { Error , ErrorKind , Result } ;
12+ use io:: { self , Error , ErrorKind , Result } ;
1313use mem;
1414use net:: { SocketAddr , Shutdown } ;
1515use path:: Path ;
@@ -130,6 +130,10 @@ impl TcpStream {
130130 pub fn set_read_timeout ( & self , duration_option : Option < Duration > ) -> Result < ( ) > {
131131 let file = self . 0 . dup ( b"read_timeout" ) ?;
132132 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+ }
133137 file. write ( & TimeSpec {
134138 tv_sec : duration. as_secs ( ) as i64 ,
135139 tv_nsec : duration. subsec_nanos ( ) as i32
@@ -143,6 +147,10 @@ impl TcpStream {
143147 pub fn set_write_timeout ( & self , duration_option : Option < Duration > ) -> Result < ( ) > {
144148 let file = self . 0 . dup ( b"write_timeout" ) ?;
145149 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+ }
146154 file. write ( & TimeSpec {
147155 tv_sec : duration. as_secs ( ) as i64 ,
148156 tv_nsec : duration. subsec_nanos ( ) as i32
0 commit comments