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

@@ -7,7 +7,6 @@ extern crate test;
use std::fmt;
use std::io::{self, Read, Write, Cursor};
use std::net::SocketAddr;
#[cfg(feature = "timeouts")]
use std::time::Duration;
use hyper::net;
@@ -75,12 +74,10 @@ impl net::NetworkStream for MockStream {
fn peer_addr(&mut self) -> io::Result<SocketAddr> {
Ok("127.0.0.1:1337".parse().unwrap())
}
#[cfg(feature = "timeouts")]
fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
// can't time out
Ok(())
}
#[cfg(feature = "timeouts")]
fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
// can't time out
Ok(())