feat(all): add socket timeouts
Methods added to `Client` and `Server` to control read and write timeouts of the underlying socket. Keep-Alive is re-enabled by default on the server, with a default timeout of 5 seconds. BREAKING CHANGE: This adds 2 required methods to the `NetworkStream` trait, `set_read_timeout` and `set_write_timeout`. Any local implementations will need to add them.
This commit is contained in:
		| @@ -4,7 +4,6 @@ use std::cmp::min; | ||||
| use std::fmt; | ||||
| use std::io::{self, Write, BufWriter, BufRead, Read}; | ||||
| use std::net::Shutdown; | ||||
| #[cfg(feature = "timeouts")] | ||||
| use std::time::Duration; | ||||
|  | ||||
| use httparse; | ||||
| @@ -341,13 +340,11 @@ impl HttpMessage for Http11Message { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     #[cfg(feature = "timeouts")] | ||||
|     #[inline] | ||||
|     fn set_read_timeout(&self, dur: Option<Duration>) -> io::Result<()> { | ||||
|         self.get_ref().set_read_timeout(dur) | ||||
|     } | ||||
|  | ||||
|     #[cfg(feature = "timeouts")] | ||||
|     #[inline] | ||||
|     fn set_write_timeout(&self, dur: Option<Duration>) -> io::Result<()> { | ||||
|         self.get_ref().set_write_timeout(dur) | ||||
|   | ||||
| @@ -4,7 +4,6 @@ use std::io::{self, Write, Read, Cursor}; | ||||
| use std::net::Shutdown; | ||||
| use std::ascii::AsciiExt; | ||||
| use std::mem; | ||||
| #[cfg(feature = "timeouts")] | ||||
| use std::time::Duration; | ||||
|  | ||||
| use http::{ | ||||
| @@ -404,13 +403,11 @@ impl<S> HttpMessage for Http2Message<S> where S: CloneableStream { | ||||
|         true | ||||
|     } | ||||
|  | ||||
|     #[cfg(feature = "timeouts")] | ||||
|     #[inline] | ||||
|     fn set_read_timeout(&self, _dur: Option<Duration>) -> io::Result<()> { | ||||
|         Ok(()) | ||||
|     } | ||||
|  | ||||
|     #[cfg(feature = "timeouts")] | ||||
|     #[inline] | ||||
|     fn set_write_timeout(&self, _dur: Option<Duration>) -> io::Result<()> { | ||||
|         Ok(()) | ||||
|   | ||||
| @@ -6,9 +6,7 @@ use std::fmt::Debug; | ||||
| use std::io::{Read, Write}; | ||||
| use std::mem; | ||||
|  | ||||
| #[cfg(feature = "timeouts")] | ||||
| use std::io; | ||||
| #[cfg(feature = "timeouts")] | ||||
| use std::time::Duration; | ||||
|  | ||||
| use typeable::Typeable; | ||||
| @@ -65,10 +63,8 @@ pub trait HttpMessage: Write + Read + Send + Any + Typeable + Debug { | ||||
|     /// the response body. | ||||
|     fn get_incoming(&mut self) -> ::Result<ResponseHead>; | ||||
|     /// Set the read timeout duration for this message. | ||||
|     #[cfg(feature = "timeouts")] | ||||
|     fn set_read_timeout(&self, dur: Option<Duration>) -> io::Result<()>; | ||||
|     /// Set the write timeout duration for this message. | ||||
|     #[cfg(feature = "timeouts")] | ||||
|     fn set_write_timeout(&self, dur: Option<Duration>) -> io::Result<()>; | ||||
|     /// Closes the underlying HTTP connection. | ||||
|     fn close_connection(&mut self) -> ::Result<()>; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user