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.
|
//! 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::sync::{Arc, RwLock, RwLockReadGuard};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
|
@ -50,9 +49,7 @@ where
|
||||||
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
|
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
|
||||||
if self.last_ping.elapsed().as_secs() >= self.ping_timeout {
|
if self.last_ping.elapsed().as_secs() >= self.ping_timeout {
|
||||||
self.close()?;
|
self.close()?;
|
||||||
Err(
|
Err(error::ErrorKind::PingTimeout.into())
|
||||||
io::Error::new(io::ErrorKind::ConnectionReset, "Ping timed out.").into(),
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
loop {
|
loop {
|
||||||
match try_ready!(self.inner.poll()) {
|
match try_ready!(self.inner.poll()) {
|
||||||
|
@ -77,14 +74,28 @@ where
|
||||||
type SinkError = error::Error;
|
type SinkError = error::Error;
|
||||||
|
|
||||||
fn start_send(&mut self, item: Self::SinkItem) -> StartSend<Self::SinkItem, Self::SinkError> {
|
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)?)
|
Ok(self.inner.start_send(item)?)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn poll_complete(&mut self) -> Poll<(), Self::SinkError> {
|
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()?)
|
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.
|
/// A view of the logs from a particular `Logged` transport.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct LogView {
|
pub struct LogView {
|
||||||
|
|
|
@ -30,6 +30,7 @@ error_chain! {
|
||||||
display("Failed to parse an IRC subcommand.")
|
display("Failed to parse an IRC subcommand.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Failed to parse a mode correctly.
|
||||||
ModeParsingFailed {
|
ModeParsingFailed {
|
||||||
description("Failed to parse a mode correctly.")
|
description("Failed to parse a mode correctly.")
|
||||||
display("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.")
|
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.")
|
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