aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJorge Israel Peña <[email protected]>2017-07-15 18:25:20 -0700
committeralex <[email protected]>2017-07-16 03:25:20 +0200
commit5fd3509c8cfe25370ca4fa66a8468bd2a9679ef5 (patch)
treedea53966bdb809408c23018f0225269767bc7cf6 /src
parentPossibly fix the closing of shards (diff)
downloadserenity-5fd3509c8cfe25370ca4fa66a8468bd2a9679ef5.tar.xz
serenity-5fd3509c8cfe25370ca4fa66a8468bd2a9679ef5.zip
Handle the closing of Shards (#126)
Diffstat (limited to 'src')
-rw-r--r--src/client/mod.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/client/mod.rs b/src/client/mod.rs
index b80b6ac..6702a92 100644
--- a/src/client/mod.rs
+++ b/src/client/mod.rs
@@ -779,7 +779,9 @@ fn boot_shard(info: &BootInfo) -> Result<Shard> {
fn monitor_shard<H: EventHandler + 'static>(mut info: MonitorInfo<H>, handle: Handle) {
handle_shard(&mut info, &handle);
- loop {
+ let mut handle_still = HANDLE_STILL.load(Ordering::Relaxed);
+
+ while handle_still {
let mut boot_successful = false;
for _ in 0..3 {
@@ -807,10 +809,21 @@ fn monitor_shard<H: EventHandler + 'static>(mut info: MonitorInfo<H>, handle: Ha
break;
}
- // The shard died: redo the cycle.
+ // The shard died: redo the cycle, unless client close was requested.
+ handle_still = HANDLE_STILL.load(Ordering::Relaxed);
}
- error!("Completely failed to reboot shard");
+ if handle_still {
+ error!("Completely failed to reboot shard");
+ } else {
+ info!("Client close was requested. Shutting down.");
+
+ let mut shard = info.shard.lock();
+
+ if let Err(e) = shard.shutdown_clean() {
+ error!("Error shutting down shard {:?}: {:?}", shard.shard_info(), e);
+ }
+ }
}
fn handle_shard<H: EventHandler + 'static>(info: &mut MonitorInfo<H>, handle: &Handle) {