Skip to content

Commit

Permalink
fix(server): join on thread when Listening drops
Browse files Browse the repository at this point in the history
Closes #447
  • Loading branch information
seanmonstar committed Apr 15, 2015
1 parent f246c6a commit 68d4d63
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 68d4d63

Please sign in to comment.