Both sides of the transport now error on ping timeout.
This commit is contained in:
parent
4d9d015f84
commit
41632b10af
2 changed files with 24 additions and 6 deletions
|
@ -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,11 +74,25 @@ where
|
|||
type SinkError = error::Error;
|
||||
|
||||
fn start_send(&mut self, item: Self::SinkItem) -> StartSend<Self::SinkItem, Self::SinkError> {
|
||||
Ok(self.inner.start_send(item)?)
|
||||
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> {
|
||||
Ok(self.inner.poll_complete()?)
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue