Both sides of the transport now error on ping timeout.

This commit is contained in:
Aaron Weiss 2017-06-22 17:33:29 -04:00
parent 4d9d015f84
commit 41632b10af
No known key found for this signature in database
GPG key ID: 0237035D9BF03AE2
2 changed files with 24 additions and 6 deletions

View file

@ -1,5 +1,4 @@
//! An IRC transport that wraps an IRC-framed stream to provide automatic PING replies.
use std::io;
use std::sync::{Arc, RwLock, RwLockReadGuard};
use std::time::Instant;
@ -50,9 +49,7 @@ where
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
if self.last_ping.elapsed().as_secs() >= self.ping_timeout {
self.close()?;
Err(
io::Error::new(io::ErrorKind::ConnectionReset, "Ping timed out.").into(),
)
Err(error::ErrorKind::PingTimeout.into())
} else {
loop {
match try_ready!(self.inner.poll()) {
@ -77,14 +74,28 @@ where
type SinkError = error::Error;
fn start_send(&mut self, item: Self::SinkItem) -> StartSend<Self::SinkItem, Self::SinkError> {
if self.last_ping.elapsed().as_secs() >= self.ping_timeout {
self.close()?;
Err(error::ErrorKind::PingTimeout.into())
} else {
Ok(self.inner.start_send(item)?)
}
}
fn poll_complete(&mut self) -> Poll<(), Self::SinkError> {
if self.last_ping.elapsed().as_secs() >= self.ping_timeout {
self.close()?;
Err(error::ErrorKind::PingTimeout.into())
} else {
Ok(self.inner.poll_complete()?)
}
}
fn close(&mut self) -> Poll<(), Self::SinkError> {
self.inner.close()
}
}
/// A view of the logs from a particular `Logged` transport.
#[derive(Clone, Debug)]
pub struct LogView {

View file

@ -30,6 +30,7 @@ error_chain! {
display("Failed to parse an IRC subcommand.")
}
/// Failed to parse a mode correctly.
ModeParsingFailed {
description("Failed to parse a mode correctly.")
display("Failed to parse a mode correctly.")
@ -46,5 +47,11 @@ error_chain! {
description("An error occured causing a mutex for a logged transport to be poisoned.")
display("An error occured causing a mutex for a logged transport to be poisoned.")
}
/// Connection timed out due to no ping response.
PingTimeout {
description("The connection timed out due to no ping response.")
display("The connection timed out due to no ping response.")
}
}
}