Merge branch 'io-stop' into auth-bft
This commit is contained in:
commit
475d4bcf3f
@ -430,6 +430,20 @@ impl<Message> IoService<Message> where Message: Send + Sync + Clone + 'static {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn stop(&mut self) {
|
||||||
|
trace!(target: "shutdown", "[IoService] Closing...");
|
||||||
|
// Clear handlers so that shared pointers are not stuck on stack
|
||||||
|
// in Channel::send_sync
|
||||||
|
self.handlers.write().clear();
|
||||||
|
self.host_channel.lock().send(IoMessage::Shutdown).unwrap_or_else(|e| warn!("Error on IO service shutdown: {:?}", e));
|
||||||
|
if let Some(thread) = self.thread.take() {
|
||||||
|
thread.join().unwrap_or_else(|e| {
|
||||||
|
debug!(target: "shutdown", "Error joining IO service event loop thread: {:?}", e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
trace!(target: "shutdown", "[IoService] Closed.");
|
||||||
|
}
|
||||||
|
|
||||||
/// Regiter an IO handler with the event loop.
|
/// Regiter an IO handler with the event loop.
|
||||||
pub fn register_handler(&self, handler: Arc<IoHandler<Message>+Send>) -> Result<(), IoError> {
|
pub fn register_handler(&self, handler: Arc<IoHandler<Message>+Send>) -> Result<(), IoError> {
|
||||||
try!(self.host_channel.lock().send(IoMessage::AddHandler {
|
try!(self.host_channel.lock().send(IoMessage::AddHandler {
|
||||||
@ -452,17 +466,7 @@ impl<Message> IoService<Message> where Message: Send + Sync + Clone + 'static {
|
|||||||
|
|
||||||
impl<Message> Drop for IoService<Message> where Message: Send + Sync + Clone {
|
impl<Message> Drop for IoService<Message> where Message: Send + Sync + Clone {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
trace!(target: "shutdown", "[IoService] Closing...");
|
self.stop()
|
||||||
// Clear handlers so that shared pointers are not stuck on stack
|
|
||||||
// in Channel::send_sync
|
|
||||||
self.handlers.write().clear();
|
|
||||||
self.host_channel.lock().send(IoMessage::Shutdown).unwrap_or_else(|e| warn!("Error on IO service shutdown: {:?}", e));
|
|
||||||
if let Some(thread) = self.thread.take() {
|
|
||||||
thread.join().unwrap_or_else(|e| {
|
|
||||||
debug!(target: "shutdown", "Error joining IO service event loop thread: {:?}", e);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
trace!(target: "shutdown", "[IoService] Closed.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user