Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Pinger until after MOTD #222

Merged
merged 1 commit into from
Nov 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/client/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ use tokio_util::codec::Framed;
use crate::{
client::data::Config,
error,
proto::{Command, IrcCodec, Message},
proto::{Command, Response, IrcCodec, Message},
};

/// Pinger-based futures helper.
struct Pinger {
tx: UnboundedSender<Message>,
// Whether this pinger pings.
enabled: bool,
/// The amount of time to wait before timing out from no ping response.
ping_timeout: Duration,
/// The instant that the last ping was sent to the server.
Expand All @@ -42,6 +44,7 @@ impl Pinger {

Self {
tx,
enabled: false,
ping_timeout,
ping_deadline: None,
ping_interval: time::interval(ping_time),
Expand All @@ -51,6 +54,10 @@ impl Pinger {
/// Handle an incoming message.
fn handle_message(&mut self, message: &Message) -> error::Result<()> {
match message.command {
Command::Response(Response::RPL_ENDOFMOTD, _)
| Command::Response(Response::ERR_NOMOTD, _) => {
self.enabled = true;
}
// On receiving a `PING` message from the server, we automatically respond with
// the appropriate `PONG` message to keep the connection alive for transport.
Command::PING(ref data, _) => {
Expand Down Expand Up @@ -109,8 +116,10 @@ impl Future for Pinger {
}

if let Poll::Ready(_) = Pin::new(&mut self.as_mut().ping_interval).poll_next(cx) {
self.as_mut().send_ping()?;
self.as_mut().set_deadline();
if self.enabled {
self.as_mut().send_ping()?;
self.as_mut().set_deadline();
}
}

Poll::Pending
Expand Down