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

Unblock the accept thread on shutdown #120

Merged
1 commit merged into from Aug 21, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/lib.rs
Expand Up @@ -126,7 +126,7 @@ use std::sync::Arc;
use std::sync::atomic::AtomicBool;
use std::thread;
use std::net;
use std::net::ToSocketAddrs;
use std::net::{ToSocketAddrs, TcpStream, Shutdown};
use std::time::Duration;
use std::sync::atomic::Ordering::Relaxed;

Expand Down Expand Up @@ -300,7 +300,6 @@ impl Server {
let new_client = match server.accept() {
Ok((sock, _)) => {
use util::RefinedTcpStream;

let (read_closable, write_closable) = match ssl {
None => {
RefinedTcpStream::new(sock)
Expand Down Expand Up @@ -413,5 +412,10 @@ impl<'a> Iterator for IncomingRequests<'a> {
impl Drop for Server {
fn drop(&mut self) {
self.close.store(true, Relaxed);
// Connect briefly to ourselves to unblock the accept thread
let maybe_stream = TcpStream::connect(self.listening_addr);
if let Ok(stream) = maybe_stream {
let _ = stream.shutdown(Shutdown::Both);
}
}
}