mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-04-27 03:32:16 +00:00
Rename KeepAlive constructors. (#1078)
* KeepAlive::Now => KeepAlive::No * KeepAlive::Forever => KeepAlive::Yes As suggested in #1072.
This commit is contained in:
parent
5c34f8a0ed
commit
8cde987e6d
@ -90,7 +90,7 @@ where
|
|||||||
fn inject_dial_upgrade_error(&mut self, _: Self::OutboundOpenInfo, _: ProtocolsHandlerUpgrErr<<Self::OutboundProtocol as OutboundUpgrade<Self::Substream>>::Error>) {}
|
fn inject_dial_upgrade_error(&mut self, _: Self::OutboundOpenInfo, _: ProtocolsHandlerUpgrErr<<Self::OutboundProtocol as OutboundUpgrade<Self::Substream>>::Error>) {}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn connection_keep_alive(&self) -> KeepAlive { KeepAlive::Now }
|
fn connection_keep_alive(&self) -> KeepAlive { KeepAlive::No }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn poll(
|
fn poll(
|
||||||
|
@ -153,13 +153,13 @@ pub trait ProtocolsHandler {
|
|||||||
/// `ProtocolsHandler`s should be kept alive as far as this handler is concerned
|
/// `ProtocolsHandler`s should be kept alive as far as this handler is concerned
|
||||||
/// and if so, for how long.
|
/// and if so, for how long.
|
||||||
///
|
///
|
||||||
/// Returning [`KeepAlive::Now`] indicates that the connection should be
|
/// Returning [`KeepAlive::No`] indicates that the connection should be
|
||||||
/// closed and this handler destroyed immediately.
|
/// closed and this handler destroyed immediately.
|
||||||
///
|
///
|
||||||
/// Returning [`KeepAlive::Until`] indicates that the connection may be closed
|
/// Returning [`KeepAlive::Until`] indicates that the connection may be closed
|
||||||
/// and this handler destroyed after the specified `Instant`.
|
/// and this handler destroyed after the specified `Instant`.
|
||||||
///
|
///
|
||||||
/// Returning [`KeepAlive::Forever`] indicates that the connection should
|
/// Returning [`KeepAlive::Yes`] indicates that the connection should
|
||||||
/// be kept alive until the next call to this method.
|
/// be kept alive until the next call to this method.
|
||||||
///
|
///
|
||||||
/// > **Note**: The connection is always closed and the handler destroyed
|
/// > **Note**: The connection is always closed and the handler destroyed
|
||||||
@ -466,16 +466,16 @@ pub enum KeepAlive {
|
|||||||
/// If nothing new happens, the connection should be closed at the given `Instant`.
|
/// If nothing new happens, the connection should be closed at the given `Instant`.
|
||||||
Until(Instant),
|
Until(Instant),
|
||||||
/// Keep the connection alive.
|
/// Keep the connection alive.
|
||||||
Forever,
|
Yes,
|
||||||
/// Close the connection as soon as possible.
|
/// Close the connection as soon as possible.
|
||||||
Now,
|
No,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeepAlive {
|
impl KeepAlive {
|
||||||
/// Returns true for `Forever`, false otherwise.
|
/// Returns true for `Yes`, false otherwise.
|
||||||
pub fn is_forever(&self) -> bool {
|
pub fn is_yes(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
KeepAlive::Forever => true,
|
KeepAlive::Yes => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -492,10 +492,10 @@ impl Ord for KeepAlive {
|
|||||||
use self::KeepAlive::*;
|
use self::KeepAlive::*;
|
||||||
|
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
(Now, Now) | (Forever, Forever) => Ordering::Equal,
|
(No, No) | (Yes, Yes) => Ordering::Equal,
|
||||||
(Now, _) | (_, Forever) => Ordering::Less,
|
(No, _) | (_, Yes) => Ordering::Less,
|
||||||
(_, Now) | (Forever, _) => Ordering::Greater,
|
(_, No) | (Yes, _) => Ordering::Greater,
|
||||||
(Until(expiration), Until(other_expiration)) => expiration.cmp(other_expiration),
|
(Until(t1), Until(t2)) => t1.cmp(t2),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,8 +282,8 @@ where
|
|||||||
d.reset(t)
|
d.reset(t)
|
||||||
},
|
},
|
||||||
(_, KeepAlive::Until(t)) => self.shutdown = Shutdown::Later(Delay::new(t)),
|
(_, KeepAlive::Until(t)) => self.shutdown = Shutdown::Later(Delay::new(t)),
|
||||||
(_, KeepAlive::Now) => self.shutdown = Shutdown::Asap,
|
(_, KeepAlive::No) => self.shutdown = Shutdown::Asap,
|
||||||
(_, KeepAlive::Forever) => self.shutdown = Shutdown::None
|
(_, KeepAlive::Yes) => self.shutdown = Shutdown::None
|
||||||
};
|
};
|
||||||
|
|
||||||
match poll_result {
|
match poll_result {
|
||||||
|
@ -75,7 +75,7 @@ where
|
|||||||
dial_queue: SmallVec::new(),
|
dial_queue: SmallVec::new(),
|
||||||
dial_negotiated: 0,
|
dial_negotiated: 0,
|
||||||
max_dial_negotiated: 8,
|
max_dial_negotiated: 8,
|
||||||
keep_alive: KeepAlive::Forever,
|
keep_alive: KeepAlive::Yes,
|
||||||
inactive_timeout,
|
inactive_timeout,
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ where
|
|||||||
/// Opens an outbound substream with `upgrade`.
|
/// Opens an outbound substream with `upgrade`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn send_request(&mut self, upgrade: TOutProto) {
|
pub fn send_request(&mut self, upgrade: TOutProto) {
|
||||||
self.keep_alive = KeepAlive::Forever;
|
self.keep_alive = KeepAlive::Yes;
|
||||||
self.dial_queue.push(upgrade);
|
self.dial_queue.push(upgrade);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ where
|
|||||||
out: <Self::InboundProtocol as InboundUpgrade<Self::Substream>>::Output,
|
out: <Self::InboundProtocol as InboundUpgrade<Self::Substream>>::Output,
|
||||||
) {
|
) {
|
||||||
// If we're shutting down the connection for inactivity, reset the timeout.
|
// If we're shutting down the connection for inactivity, reset the timeout.
|
||||||
if !self.keep_alive.is_forever() {
|
if !self.keep_alive.is_yes() {
|
||||||
self.keep_alive = KeepAlive::Until(Instant::now() + self.inactive_timeout);
|
self.keep_alive = KeepAlive::Until(Instant::now() + self.inactive_timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ where
|
|||||||
|
|
||||||
fn connection_keep_alive(&self) -> KeepAlive {
|
fn connection_keep_alive(&self) -> KeepAlive {
|
||||||
self.inner.as_ref().map(|h| h.connection_keep_alive())
|
self.inner.as_ref().map(|h| h.connection_keep_alive())
|
||||||
.unwrap_or(KeepAlive::Now)
|
.unwrap_or(KeepAlive::No)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll(
|
fn poll(
|
||||||
|
@ -78,7 +78,7 @@ where
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn connection_keep_alive(&self) -> KeepAlive { KeepAlive::Now }
|
fn connection_keep_alive(&self) -> KeepAlive { KeepAlive::No }
|
||||||
|
|
||||||
fn poll(&mut self) -> Poll<ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent>, Self::Error> {
|
fn poll(&mut self) -> Poll<ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent>, Self::Error> {
|
||||||
Ok(Async::NotReady)
|
Ok(Async::NotReady)
|
||||||
|
@ -76,7 +76,7 @@ where
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn connection_keep_alive(&self) -> KeepAlive { KeepAlive::Forever }
|
fn connection_keep_alive(&self) -> KeepAlive { KeepAlive::Yes }
|
||||||
|
|
||||||
fn poll(&mut self) -> Poll<ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent>, Self::Error> {
|
fn poll(&mut self) -> Poll<ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent>, Self::Error> {
|
||||||
Ok(Async::NotReady)
|
Ok(Async::NotReady)
|
||||||
|
@ -90,7 +90,7 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn connection_keep_alive(&self) -> KeepAlive {
|
fn connection_keep_alive(&self) -> KeepAlive {
|
||||||
KeepAlive::Now
|
KeepAlive::No
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll(
|
fn poll(
|
||||||
|
@ -127,9 +127,9 @@ where
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn connection_keep_alive(&self) -> KeepAlive {
|
fn connection_keep_alive(&self) -> KeepAlive {
|
||||||
if self.first_id_happened {
|
if self.first_id_happened {
|
||||||
KeepAlive::Now
|
KeepAlive::No
|
||||||
} else {
|
} else {
|
||||||
KeepAlive::Forever
|
KeepAlive::Yes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,7 +326,7 @@ where
|
|||||||
allow_listening,
|
allow_listening,
|
||||||
next_connec_unique_id: UniqueConnecId(0),
|
next_connec_unique_id: UniqueConnecId(0),
|
||||||
substreams: Vec::new(),
|
substreams: Vec::new(),
|
||||||
keep_alive: KeepAlive::Forever,
|
keep_alive: KeepAlive::Yes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -525,7 +525,7 @@ where
|
|||||||
if self.substreams.is_empty() {
|
if self.substreams.is_empty() {
|
||||||
self.keep_alive = KeepAlive::Until(Instant::now() + Duration::from_secs(10));
|
self.keep_alive = KeepAlive::Until(Instant::now() + Duration::from_secs(10));
|
||||||
} else {
|
} else {
|
||||||
self.keep_alive = KeepAlive::Forever;
|
self.keep_alive = KeepAlive::Yes;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Async::NotReady)
|
Ok(Async::NotReady)
|
||||||
|
@ -202,7 +202,7 @@ where
|
|||||||
// the connection may be closed. I.e. the ping handler does not keep
|
// the connection may be closed. I.e. the ping handler does not keep
|
||||||
// the connection alive, it merely adds another condition (failed pings)
|
// the connection alive, it merely adds another condition (failed pings)
|
||||||
// for terminating it.
|
// for terminating it.
|
||||||
KeepAlive::Now
|
KeepAlive::No
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll(&mut self) -> Poll<ProtocolsHandlerEvent<protocol::Ping, (), PingResult>, Self::Error> {
|
fn poll(&mut self) -> Poll<ProtocolsHandlerEvent<protocol::Ping, (), PingResult>, Self::Error> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user