aboutsummaryrefslogtreecommitdiff
path: root/src/gateway/mod.rs
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-09-30 16:07:40 -0700
committerZeyla Hellyer <[email protected]>2017-10-09 15:45:48 -0700
commit45c1f27edbeedcb30aa3e9daa78eba44817f7260 (patch)
treec8ca606c603fe78c7b9efdd3c9b6708838324763 /src/gateway/mod.rs
parentImprove shard and shard runner logging (diff)
downloadserenity-45c1f27edbeedcb30aa3e9daa78eba44817f7260.tar.xz
serenity-45c1f27edbeedcb30aa3e9daa78eba44817f7260.zip
Improve shard logic
Improve shard logic by more cleanly differentiating when resuming, as well as actually fixing resume logic. For shard runners, better handling of dead clients is added, as well as more use of the shard manager, in that the runner will now more liberally request a restart when required (instead of sitting and doing nothing infinitely).
Diffstat (limited to 'src/gateway/mod.rs')
-rw-r--r--src/gateway/mod.rs53
1 files changed, 52 insertions, 1 deletions
diff --git a/src/gateway/mod.rs b/src/gateway/mod.rs
index 6f839db..bd9c45b 100644
--- a/src/gateway/mod.rs
+++ b/src/gateway/mod.rs
@@ -60,7 +60,7 @@ pub use self::shard::Shard;
/// This can be useful for knowing which shards are currently "down"/"up".
///
/// [`Shard`]: struct.Shard.html
-#[derive(Debug, Eq, PartialEq, PartialOrd, Ord)]
+#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub enum ConnectionStage {
/// Indicator that the [`Shard`] is normally connected and is not in, e.g.,
/// a resume phase.
@@ -83,5 +83,56 @@ pub enum ConnectionStage {
Handshake,
/// Indicator that the [`Shard`] has sent an IDENTIFY packet and is awaiting
/// a READY packet.
+ ///
+ /// [`Shard`]: struct.Shard.html
Identifying,
+ /// Indicator that the [`Shard`] has sent a RESUME packet and is awaiting a
+ /// RESUMED packet.
+ ///
+ /// [`Shard`]: struct.Shard.html
+ Resuming,
+}
+
+impl ConnectionStage {
+ /// Whether the stage is a form of connecting.
+ ///
+ /// This will return `true` on:
+ ///
+ /// - [`Connecting`][`ConnectionStage::Connecting`]
+ /// - [`Handshake`][`ConnectionStage::Handshake`]
+ /// - [`Identifying`][`ConnectionStage::Identifying`]
+ /// - [`Resuming`][`ConnectionStage::Resuming`]
+ ///
+ /// All other variants will return `false`.
+ ///
+ /// # Examples
+ ///
+ /// Assert that [`ConnectionStage::Identifying`] is a connecting stage:
+ ///
+ /// ```rust
+ /// use serenity::gateway::ConnectionStage;
+ ///
+ /// assert!(ConnectionStage::Identifying.is_connecting());
+ /// ```
+ ///
+ /// Assert that [`ConnectionStage::Connected`] is _not_ a connecting stage:
+ ///
+ /// ```rust
+ /// use serenity::gateway::ConnectionStage;
+ ///
+ /// assert!(!ConnectionStage::Connected.is_connecting());
+ /// ```
+ ///
+ /// [`ConnectionStage::Connecting`]: #variant.Connecting
+ /// [`ConnectionStage::Handshake`]: #variant.Handshake
+ /// [`ConnectionStage::Identifying`]: #variant.Identifying
+ /// [`ConnectionStage::Resuming`]: #variant.Resuming
+ pub fn is_connecting(&self) -> bool {
+ use self::ConnectionStage::*;
+
+ *self == Connecting
+ || *self == Handshake
+ || *self == Identifying
+ || *self == Resuming
+ }
}