Skip to content

Commit

Permalink
Unblock the accept thread on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
moises-silva committed Aug 21, 2016
1 parent 6cba5c4 commit a7a8c6f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 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 @@ -411,7 +410,13 @@ impl<'a> Iterator for IncomingRequests<'a> {
}

impl Drop for Server {
#[allow(unused_must_use)]
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 {
stream.shutdown(Shutdown::Both);
}
}
}

0 comments on commit a7a8c6f

Please sign in to comment.