refactor(server): make with_listener a free function
Allow a Server to operate without requiring the entire Server struct to move into the with_listener function (instead only the handler function needs to move). This, allows other members to not move, or move separately, which will be needed for the next commit. See #471
This commit is contained in:
		| @@ -103,7 +103,7 @@ impl<'a, H: Handler + 'static> Server<'a, H, HttpListener> { | ||||
|             Some((cert, key)) => HttpListener::https(addr, cert, key), | ||||
|             None => HttpListener::http(addr) | ||||
|         }); | ||||
|         self.with_listener(listener, threads) | ||||
|         with_listener(self.handler, listener, threads) | ||||
|     } | ||||
|  | ||||
|     /// Binds to a socket and starts handling connections. | ||||
| @@ -117,9 +117,15 @@ H: Handler + 'static, | ||||
| L: NetworkListener<Stream=S> + Send + 'static, | ||||
| S: NetworkStream + Clone + Send> Server<'a, H, L> { | ||||
|     /// Creates a new server that will handle `HttpStream`s. | ||||
|     pub fn with_listener(self, mut listener: L, threads: usize) -> HttpResult<Listening> { | ||||
|     pub fn with_listener(self, listener: L, threads: usize) -> HttpResult<Listening> { | ||||
|         with_listener(self.handler, listener, threads) | ||||
|     } | ||||
| } | ||||
|  | ||||
| fn with_listener<H, L>(handler: H, mut listener: L, threads: usize) -> HttpResult<Listening> | ||||
| where H: Handler + 'static, | ||||
| L: NetworkListener + Send + 'static { | ||||
|     let socket = try!(listener.local_addr()); | ||||
|         let handler = self.handler; | ||||
|  | ||||
|     debug!("threads = {:?}", threads); | ||||
|     let pool = ListenerPool::new(listener.clone()); | ||||
| @@ -132,8 +138,6 @@ S: NetworkStream + Clone + Send> Server<'a, H, L> { | ||||
|         socket: socket, | ||||
|     }) | ||||
| } | ||||
| } | ||||
|  | ||||
|  | ||||
| fn handle_connection<'h, S, H>(mut stream: &mut S, handler: &'h H) | ||||
| where S: NetworkStream + Clone, H: Handler { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user