feat(server): make AcceptorPool::accept() block and allow non'-static data
Change AcceptorPool to not spawn detached threads anymore. This, together with the recent `Send` changes, allows the `work` closure to close over non-`'static` data. This doesn't change the high-level `Server` interface, because that would make it's `listen` a blocking call (it's currently non-blocking) - which would be a breaking change.
This commit is contained in:
committed by
Sean McArthur
parent
b47f936525
commit
b0a72d80d0
@@ -2,7 +2,7 @@
|
||||
use std::old_io::{Listener, BufferedReader, BufferedWriter};
|
||||
use std::old_io::net::ip::{IpAddr, Port, SocketAddr};
|
||||
use std::os;
|
||||
use std::thread::JoinGuard;
|
||||
use std::thread::{self, JoinGuard};
|
||||
|
||||
pub use self::request::Request;
|
||||
pub use self::response::Response;
|
||||
@@ -77,8 +77,10 @@ S: NetworkStream + Clone + Send> Server<L> {
|
||||
let pool = AcceptorPool::new(acceptor.clone());
|
||||
let work = move |stream| handle_connection(stream, &handler);
|
||||
|
||||
let guard = thread::scoped(move || pool.accept(work, threads));
|
||||
|
||||
Ok(Listening {
|
||||
_guard: pool.accept(work, threads),
|
||||
_guard: guard,
|
||||
socket: socket,
|
||||
acceptor: acceptor
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user