aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-09-27 10:52:37 -0700
committerZeyla Hellyer <[email protected]>2017-09-27 10:52:37 -0700
commit86d8bddff3e3242186d0c2607b34771e5422ba5b (patch)
tree5dd747da21879fce74c6c14e9e897076256fdbab /src/client
parentFix client no-framework compilation (diff)
downloadserenity-86d8bddff3e3242186d0c2607b34771e5422ba5b.tar.xz
serenity-86d8bddff3e3242186d0c2607b34771e5422ba5b.zip
Fix client shards by cloning ShardManager runners
Due to the new ShardManager, `Client::shards` would never fill, so instead clone the `shard_runners` instance from the `ShardManager` to the `Client`.
Diffstat (limited to 'src/client')
-rw-r--r--src/client/bridge/gateway/mod.rs3
-rw-r--r--src/client/bridge/gateway/shard_manager.rs2
-rw-r--r--src/client/bridge/gateway/shard_queuer.rs1
-rw-r--r--src/client/mod.rs19
4 files changed, 15 insertions, 10 deletions
diff --git a/src/client/bridge/gateway/mod.rs b/src/client/bridge/gateway/mod.rs
index 24170e0..0b873aa 100644
--- a/src/client/bridge/gateway/mod.rs
+++ b/src/client/bridge/gateway/mod.rs
@@ -43,5 +43,6 @@ impl Display for ShardId {
}
pub struct ShardRunnerInfo {
- runner_tx: Sender<ShardManagerMessage>,
+ pub runner_tx: Sender<ShardManagerMessage>,
+ pub shard: Arc<Mutex<Shard>>,
}
diff --git a/src/client/bridge/gateway/shard_manager.rs b/src/client/bridge/gateway/shard_manager.rs
index e723398..3bdf0f9 100644
--- a/src/client/bridge/gateway/shard_manager.rs
+++ b/src/client/bridge/gateway/shard_manager.rs
@@ -18,7 +18,7 @@ use typemap::ShareMap;
use framework::Framework;
pub struct ShardManager {
- runners: Arc<ParkingLotMutex<HashMap<ShardId, ShardRunnerInfo>>>,
+ pub runners: Arc<ParkingLotMutex<HashMap<ShardId, ShardRunnerInfo>>>,
/// The index of the first shard to initialize, 0-indexed.
shard_index: u64,
/// The number of shards to initialize.
diff --git a/src/client/bridge/gateway/shard_queuer.rs b/src/client/bridge/gateway/shard_queuer.rs
index e313d55..76e3872 100644
--- a/src/client/bridge/gateway/shard_queuer.rs
+++ b/src/client/bridge/gateway/shard_queuer.rs
@@ -107,6 +107,7 @@ impl<H: EventHandler + Send + Sync + 'static> ShardQueuer<H> {
let runner_info = ShardRunnerInfo {
runner_tx: runner.runner_tx(),
+ shard: locked,
};
thread::spawn(move || {
diff --git a/src/client/mod.rs b/src/client/mod.rs
index 839328a..f497f2c 100644
--- a/src/client/mod.rs
+++ b/src/client/mod.rs
@@ -19,7 +19,8 @@
//! [Client examples]: struct.Client.html#examples
#![allow(zero_ptr)]
-mod bridge;
+pub mod bridge;
+
mod context;
mod dispatch;
mod error;
@@ -36,14 +37,13 @@ pub use http as rest;
#[cfg(feature = "cache")]
pub use CACHE;
-use self::bridge::gateway::ShardManager;
+use self::bridge::gateway::{ShardId, ShardManager, ShardRunnerInfo};
use self::dispatch::dispatch;
use std::sync::{self, Arc};
use std::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_INIT};
use parking_lot::Mutex;
use std::collections::HashMap;
use std::mem;
-use super::gateway::Shard;
use typemap::ShareMap;
use http;
use internal::prelude::*;
@@ -223,11 +223,12 @@ pub struct Client<H: EventHandler + Send + Sync + 'static> {
///
/// let mut client = Client::new(&env::var("DISCORD_TOKEN")?, Handler);
///
- /// let shards = client.shards.clone();
+ /// let shard_runners = client.shard_runners.clone();
///
/// thread::spawn(move || {
/// loop {
- /// println!("Shard count instantiated: {}", shards.lock().len());
+ /// println!("Shard count instantiated: {}",
+ /// shard_runners.lock().len());
///
/// thread::sleep(Duration::from_millis(5000));
/// }
@@ -242,7 +243,7 @@ pub struct Client<H: EventHandler + Send + Sync + 'static> {
///
/// [`Client::start_shard`]: #method.start_shard
/// [`Client::start_shards`]: #method.start_shards
- pub shards: Arc<Mutex<HashMap<u64, Arc<Mutex<Shard>>>>>,
+ pub shard_runners: Arc<Mutex<HashMap<ShardId, ShardRunnerInfo>>>,
token: Arc<sync::Mutex<String>>,
}
@@ -291,14 +292,14 @@ impl<H: EventHandler + Send + Sync + 'static> Client<H> {
data: Arc::new(Mutex::new(ShareMap::custom())),
event_handler: Arc::new(handler),
framework: Arc::new(sync::Mutex::new(None)),
- shards: Arc::new(Mutex::new(HashMap::new())),
+ shard_runners: Arc::new(Mutex::new(HashMap::new())),
token: locked,
}
} else {
Client {
data: Arc::new(Mutex::new(ShareMap::custom())),
event_handler: Arc::new(handler),
- shards: Arc::new(Mutex::new(HashMap::new())),
+ shard_runners: Arc::new(Mutex::new(HashMap::new())),
token: locked,
}
}}
@@ -762,6 +763,8 @@ impl<H: EventHandler + Send + Sync + 'static> Client<H> {
self.framework.clone(),
);
+ self.shard_runners = manager.runners.clone();
+
if let Err(why) = manager.initialize() {
error!("Failed to boot a shard: {:?}", why);
info!("Shutting down all shards");