feat(server): Add hooks for HttpListener and HttpsListener to be started from existing listeners.

This allows Servers to be started on existing TcpListeners.
This commit is contained in:
Jonathan Reem
2015-10-18 18:51:31 -07:00
parent 292b4e6dea
commit fa0848d421
3 changed files with 27 additions and 21 deletions

View File

@@ -194,8 +194,6 @@ impl<L: NetworkListener> Server<L> {
pub fn set_write_timeout(&mut self, dur: Option<Duration>) {
self.timeouts.write = dur;
}
}
impl Server<HttpListener> {
@@ -219,6 +217,7 @@ impl<L: NetworkListener + Send + 'static> Server<L> {
pub fn handle<H: Handler + 'static>(self, handler: H) -> ::Result<Listening> {
self.handle_threads(handler, num_cpus::get() * 5 / 4)
}
/// Binds to a socket and starts handling connections with the provided
/// number of threads.
pub fn handle_threads<H: Handler + 'static>(self, handler: H,
@@ -228,8 +227,7 @@ impl<L: NetworkListener + Send + 'static> Server<L> {
}
fn handle<H, L>(mut server: Server<L>, handler: H, threads: usize) -> ::Result<Listening>
where H: Handler + 'static,
L: NetworkListener + Send + 'static {
where H: Handler + 'static, L: NetworkListener + Send + 'static {
let socket = try!(server.listener.local_addr());
debug!("threads = {:?}", threads);
@@ -251,7 +249,6 @@ struct Worker<H: Handler + 'static> {
}
impl<H: Handler + 'static> Worker<H> {
fn new(handler: H, timeouts: Timeouts) -> Worker<H> {
Worker {
handler: handler,
@@ -299,7 +296,6 @@ impl<H: Handler + 'static> Worker<H> {
self.set_write_timeout(s, self.timeouts.write)
}
#[cfg(not(feature = "timeouts"))]
fn set_write_timeout(&self, _s: &NetworkStream, _timeout: Option<Duration>) -> io::Result<()> {
Ok(())
@@ -339,7 +335,6 @@ impl<H: Handler + 'static> Worker<H> {
}
};
if !self.handle_expect(&req, wrt) {
return false;
}