Skip to content

Commit

Permalink
Merge pull request #458 from hyperium/server-spawn
Browse files Browse the repository at this point in the history
fix(server): join on thread when Listening drops
  • Loading branch information
reem committed Apr 15, 2015
2 parents f246c6a + 68d4d63 commit dac2f4d
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 @@ -107,7 +107,7 @@ S: NetworkStream + Clone + Send> Server<'a, H, L> {
let guard = thread::spawn(move || pool.accept(work, threads));

Ok(Listening {
_guard: guard,
_guard: Some(guard),
socket: socket,
})
}
Expand Down Expand Up @@ -176,16 +176,23 @@ where S: NetworkStream + Clone, H: Handler {
/// A listening server, which can later be closed.
pub struct Listening {
#[cfg(feature = "nightly")]
_guard: JoinHandle<()>,
_guard: Option<JoinHandle<()>>,
#[cfg(not(feature = "nightly"))]
_guard: JoinHandle,
_guard: Option<JoinHandle>,
/// The socket addresses that the server is bound to.
pub socket: SocketAddr,
}

impl Drop for Listening {
fn drop(&mut self) {
let _ = self._guard.take().map(|g| g.join());
}
}

impl Listening {
/// Stop the server from listening to its socket address.
pub fn close(&mut self) -> HttpResult<()> {
let _ = self._guard.take();
debug!("closing server");
//try!(self.acceptor.close());
Ok(())
Expand Down

0 comments on commit dac2f4d

Please sign in to comment.