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:
Sean McArthur
2015-11-24 10:27:46 -08:00
parent 21c4f51ad5
commit fec6e3e873
12 changed files with 24 additions and 109 deletions

View File

@@ -2,7 +2,6 @@
use std::marker::PhantomData;
use std::io::{self, Write};
#[cfg(feature = "timeouts")]
use std::time::Duration;
use url::Url;
@@ -44,14 +43,12 @@ impl<W> Request<W> {
pub fn method(&self) -> method::Method { self.method.clone() }
/// Set the write timeout.
#[cfg(feature = "timeouts")]
#[inline]
pub fn set_write_timeout(&self, dur: Option<Duration>) -> io::Result<()> {
self.message.set_write_timeout(dur)
}
/// Set the read timeout.
#[cfg(feature = "timeouts")]
#[inline]
pub fn set_read_timeout(&self, dur: Option<Duration>) -> io::Result<()> {
self.message.set_read_timeout(dur)