feat(net): add socket timeouts to Server and Client

While these methods are marked unstable in libstd, this is behind a
feature flag, `timeouts`. The Client and Server both have
`set_read_timeout` and `set_write_timeout` methods, that will affect all
connections with that entity.

BREAKING CHANGE: Any custom implementation of NetworkStream must now
  implement `set_read_timeout` and `set_write_timeout`, so those will
  break. Most users who only use the provided streams should work with
  no changes needed.

Closes #315
This commit is contained in:
Sean McArthur
2015-06-16 11:02:36 -07:00
parent 421422b620
commit 7d1f154cb7
11 changed files with 311 additions and 50 deletions

View File

@@ -2,6 +2,9 @@
use std::marker::PhantomData;
use std::io::{self, Write};
#[cfg(feature = "timeouts")]
use std::time::Duration;
use url::Url;
use method::{self, Method};
@@ -39,6 +42,20 @@ impl<W> Request<W> {
/// Read the Request method.
#[inline]
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)
}
}
impl Request<Fresh> {