Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): join on thread when Listening drops #458

Merged
merged 1 commit into from
Apr 15, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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<()> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should probably take the guard for now, so that it at least lets you close a program running a server.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right

let _ = self._guard.take();
debug!("closing server");
//try!(self.acceptor.close());
Ok(())
Expand Down