struct Keepalive {
sent: Mutex<Option<Instant>>,
}Expand description
One connection’s keepalive: the ping it has out, if any.
A silent read is not evidence of a dead peer until something has been asked of it. A connection can spend longer than the bound in a single write - a 3.5 MB snapshot to a slow client was measured at 31.6 s - and through that stall no beat runs and no ping goes out, so a rule that counted “no frame read” as silence would kill a live client on the first tick after the write. What is tracked here is the one thing the peer was actually asked for: an unanswered ping.
Fields§
§sent: Mutex<Option<Instant>>When the outstanding ping was sent, None when none is out. Any
inbound frame clears it, because any frame is the peer answering in
some form. A lock rather than a cell: Keepalive::ping holds
&self across its send, and a cell is not Sync, which would make
the connection’s future not Send for the sake of a stamp.
Implementations§
Source§impl Keepalive
impl Keepalive
Sourcefn beat(&self, now: Instant, dead: Duration) -> Beat
fn beat(&self, now: Instant, dead: Duration) -> Beat
What this beat should do. Asking does not stamp the deadline: a send that queues behind a full buffer reaches the peer late, and a deadline taken before it would have expired before the peer saw it.
Sourceasync fn ping<S>(&self, sink: &mut S) -> Result<()>
async fn ping<S>(&self, sink: &mut S) -> Result<()>
Send the ping and start its deadline, in that order.
The stamp is taken here, only once the send answers, so no caller can
stamp it early: a ping still held in a full buffer owes nothing until
it reaches the peer. The send is a Sink rather than a closure so a
test can hold it and watch the state at each side of the await.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Keepalive
impl RefUnwindSafe for Keepalive
impl Send for Keepalive
impl Sync for Keepalive
impl Unpin for Keepalive
impl UnsafeUnpin for Keepalive
impl UnwindSafe for Keepalive
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more