Skip to content

Commit

Permalink
refactor(server): Remove redundant timeout setting
Browse files Browse the repository at this point in the history
As of the previous commit, timeouts are set directly after accepting the
connection in `HttpListener::accept`. This commit removes the code that
still redundantly set it in `Worker::handle_connection`.

`Worker` still does some read timeout setting related to keep-alive.
That code remains untouched.
  • Loading branch information
hannobraun authored and seanmonstar committed Jan 15, 2017
1 parent f5d4d65 commit baef7ab
Showing 1 changed file with 0 additions and 17 deletions.
17 changes: 0 additions & 17 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,13 @@ pub struct Server<L = HttpListener> {
#[derive(Clone, Copy, Debug)]
struct Timeouts {
read: Option<Duration>,
write: Option<Duration>,
keep_alive: Option<Duration>,
}

impl Default for Timeouts {
fn default() -> Timeouts {
Timeouts {
read: None,
write: None,
keep_alive: Some(Duration::from_secs(5))
}
}
Expand Down Expand Up @@ -205,7 +203,6 @@ impl<L: NetworkListener> Server<L> {
/// Sets the write timeout for all Response writes.
pub fn set_write_timeout(&mut self, dur: Option<Duration>) {
self.listener.set_write_timeout(dur);
self.timeouts.write = dur;
}
}

Expand Down Expand Up @@ -274,11 +271,6 @@ impl<H: Handler + 'static> Worker<H> {

self.handler.on_connection_start();

if let Err(e) = self.set_timeouts(&*stream) {
error!("set_timeouts error: {:?}", e);
return;
}

let addr = match stream.peer_addr() {
Ok(addr) => addr,
Err(e) => {
Expand All @@ -304,15 +296,6 @@ impl<H: Handler + 'static> Worker<H> {
debug!("keep_alive loop ending for {}", addr);
}

fn set_timeouts(&self, s: &NetworkStream) -> io::Result<()> {
try!(self.set_read_timeout(s, self.timeouts.read));
self.set_write_timeout(s, self.timeouts.write)
}

fn set_write_timeout(&self, s: &NetworkStream, timeout: Option<Duration>) -> io::Result<()> {
s.set_write_timeout(timeout)
}

fn set_read_timeout(&self, s: &NetworkStream, timeout: Option<Duration>) -> io::Result<()> {
s.set_read_timeout(timeout)
}
Expand Down

0 comments on commit baef7ab

Please sign in to comment.