mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-03 21:07:39 +03:00
Rename keep-alive flag
This commit is contained in:
parent
41045de766
commit
f07c0576a7
2 changed files with 22 additions and 22 deletions
|
@ -43,11 +43,11 @@ bitflags::bitflags! {
|
|||
|
||||
/// dispatcher is marked stopped
|
||||
const DSP_STOP = 0b0001_0000_0000_0000;
|
||||
/// keep-alive timeout occured
|
||||
const DSP_KEEPALIVE = 0b0010_0000_0000_0000;
|
||||
/// timeout occured
|
||||
const DSP_TIMEOUT = 0b0010_0000_0000_0000;
|
||||
|
||||
/// keep-alive timeout started
|
||||
const KEEPALIVE = 0b1000_0000_0000_0000;
|
||||
/// timer started
|
||||
const TIMEOUT = 0b1000_0000_0000_0000;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,12 +92,12 @@ impl IoState {
|
|||
}
|
||||
|
||||
pub(super) fn notify_timeout(&self) {
|
||||
log::trace!("keep-alive timeout, notify dispatcher");
|
||||
log::trace!("timeout, notify dispatcher");
|
||||
|
||||
let mut flags = self.flags.get();
|
||||
flags.remove(Flags::KEEPALIVE);
|
||||
if !flags.contains(Flags::DSP_KEEPALIVE) {
|
||||
flags.insert(Flags::DSP_KEEPALIVE);
|
||||
flags.remove(Flags::TIMEOUT);
|
||||
if !flags.contains(Flags::DSP_TIMEOUT) {
|
||||
flags.insert(Flags::DSP_TIMEOUT);
|
||||
self.flags.set(flags);
|
||||
self.dispatch_task.wake();
|
||||
}
|
||||
|
@ -348,7 +348,7 @@ impl<F> Io<F> {
|
|||
Ok(item) => Ok(Some(item)),
|
||||
Err(RecvError::KeepAlive) => Err(Either::Right(io::Error::new(
|
||||
io::ErrorKind::TimedOut,
|
||||
"Keep-alive",
|
||||
"Timeout",
|
||||
))),
|
||||
Err(RecvError::Stop) => Err(Either::Right(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
|
@ -552,8 +552,8 @@ impl<F> Io<F> {
|
|||
} else if flags.contains(Flags::DSP_STOP) {
|
||||
self.0 .0.remove_flags(Flags::DSP_STOP);
|
||||
Err(RecvError::Stop)
|
||||
} else if flags.contains(Flags::DSP_KEEPALIVE) {
|
||||
self.0 .0.remove_flags(Flags::DSP_KEEPALIVE);
|
||||
} else if flags.contains(Flags::DSP_TIMEOUT) {
|
||||
self.0 .0.remove_flags(Flags::DSP_TIMEOUT);
|
||||
Err(RecvError::KeepAlive)
|
||||
} else if flags.contains(Flags::WR_BACKPRESSURE) {
|
||||
Err(RecvError::WriteBackpressure)
|
||||
|
@ -645,8 +645,8 @@ impl<F> Io<F> {
|
|||
} else if flags.contains(Flags::DSP_STOP) {
|
||||
self.0 .0.remove_flags(Flags::DSP_STOP);
|
||||
Poll::Ready(IoStatusUpdate::Stop)
|
||||
} else if flags.contains(Flags::DSP_KEEPALIVE) {
|
||||
self.0 .0.remove_flags(Flags::DSP_KEEPALIVE);
|
||||
} else if flags.contains(Flags::DSP_TIMEOUT) {
|
||||
self.0 .0.remove_flags(Flags::DSP_TIMEOUT);
|
||||
Poll::Ready(IoStatusUpdate::KeepAlive)
|
||||
} else if flags.contains(Flags::WR_BACKPRESSURE) {
|
||||
Poll::Ready(IoStatusUpdate::WriteBackpressure)
|
||||
|
@ -940,7 +940,7 @@ mod tests {
|
|||
|
||||
server.0 .0.notify_timeout();
|
||||
let err = server.recv(&BytesCodec).await.err().unwrap();
|
||||
assert!(format!("{:?}", err).contains("Keep-alive"));
|
||||
assert!(format!("{:?}", err).contains("Timeout"));
|
||||
|
||||
server.0 .0.insert_flags(Flags::DSP_STOP);
|
||||
let err = server.recv(&BytesCodec).await.err().unwrap();
|
||||
|
|
|
@ -206,7 +206,7 @@ impl IoRef {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
/// Keep-alive deadline
|
||||
/// current timer deadline
|
||||
pub fn timer_deadline(&self) -> time::Instant {
|
||||
self.0.keepalive.get()
|
||||
}
|
||||
|
@ -214,23 +214,23 @@ impl IoRef {
|
|||
#[inline]
|
||||
/// Start timer
|
||||
pub fn start_timer(&self, timeout: time::Duration) {
|
||||
if self.flags().contains(Flags::KEEPALIVE) {
|
||||
if self.flags().contains(Flags::TIMEOUT) {
|
||||
timer::unregister(self.0.keepalive.get(), self);
|
||||
}
|
||||
if !timeout.is_zero() {
|
||||
log::debug!("start keep-alive timeout {:?}", timeout);
|
||||
self.0.insert_flags(Flags::KEEPALIVE);
|
||||
log::debug!("start timer {:?}", timeout);
|
||||
self.0.insert_flags(Flags::TIMEOUT);
|
||||
self.0.keepalive.set(timer::register(timeout, self));
|
||||
} else {
|
||||
self.0.remove_flags(Flags::KEEPALIVE);
|
||||
self.0.remove_flags(Flags::TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Stop keep-alive timer
|
||||
/// Stop timer
|
||||
pub fn stop_timer(&self) {
|
||||
if self.flags().contains(Flags::KEEPALIVE) {
|
||||
log::debug!("unregister keep-alive timer");
|
||||
if self.flags().contains(Flags::TIMEOUT) {
|
||||
log::debug!("unregister timer");
|
||||
timer::unregister(self.0.keepalive.get(), self)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue