Skip to content

Commit

Permalink
feat(server): add idle_timeout to Server
Browse files Browse the repository at this point in the history
Closes #790
  • Loading branch information
seanmonstar committed Jul 15, 2016
1 parent 8de8b74 commit 02cb96a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ impl<A: Accept> Server<A> where A::Output: Transport {
config.slab_capacity(self.max_sockets);
config.mio().notify_capacity(self.max_sockets);
let keep_alive = self.keep_alive;
let idle_timeout = self.idle_timeout;
let mut loop_ = rotor::Loop::new(&config).unwrap();
let mut notifier = None;
{
Expand All @@ -135,8 +136,9 @@ impl<A: Accept> Server<A> where A::Output: Transport {
};
let server = ServerLoop {
inner: Some((loop_, Context {
factory: factory,
idle_timeout: idle_timeout,
keep_alive: keep_alive,
factory: factory
}))
};
Ok((listening, server))
Expand All @@ -162,8 +164,9 @@ impl<A: Accept, H: HandlerFactory<A::Output>> Drop for ServerLoop<A, H> {
}

struct Context<F> {
keep_alive: bool,
factory: F,
idle_timeout: Option<Duration>,
keep_alive: bool,
}

impl<F: HandlerFactory<T>, T: Transport> http::MessageHandlerFactory<(), T> for Context<F> {
Expand All @@ -174,7 +177,11 @@ impl<F: HandlerFactory<T>, T: Transport> http::MessageHandlerFactory<(), T> for
}

fn keep_alive_interest(&self) -> Next {
Next::read()
if let Some(dur) = self.idle_timeout {
Next::read().timeout(dur)
} else {
Next::read()
}
}
}

Expand Down

0 comments on commit 02cb96a

Please sign in to comment.