Add Io::take() helper method

This commit is contained in:
Nikolay Kim 2022-01-16 12:06:06 +06:00
parent a563aca46b
commit 429073f9ff
6 changed files with 57 additions and 25 deletions

View file

@ -1,5 +1,9 @@
# Changes
## [0.1.4] - 2022-01-xx
* Add Io::take() method
## [0.1.3] - 2022-01-12
* Refactor Filter trait, fix read buffer processing

View file

@ -1,6 +1,6 @@
[package]
name = "ntex-io"
version = "0.1.3"
version = "0.1.4"
authors = ["ntex contributors <team@ntex.rs>"]
description = "Utilities for encoding and decoding frames"
keywords = ["network", "framework", "async", "futures"]

View file

@ -296,6 +296,37 @@ impl<F> Io<F> {
pub fn set_disconnect_timeout(&self, timeout: Millis) {
self.0 .0.disconnect_timeout.set(timeout);
}
#[inline]
/// Clone current io object.
///
/// Current io object becomes closed.
pub fn take(&mut self) -> Self {
let inner = Rc::new(IoState {
pool: self.0 .0.pool.clone(),
flags: Cell::new(
Flags::DSP_STOP
| Flags::IO_STOPPED
| Flags::IO_STOPPING
| Flags::IO_STOPPING_FILTERS,
),
error: Cell::new(None),
disconnect_timeout: Cell::new(Millis::ONE_SEC),
dispatch_task: LocalWaker::new(),
read_task: LocalWaker::new(),
write_task: LocalWaker::new(),
read_buf: Cell::new(None),
write_buf: Cell::new(None),
filter: Cell::new(NullFilter::get()),
handle: Cell::new(None),
on_disconnect: RefCell::new(Vec::new()),
keepalive: Cell::new(None),
});
let state = mem::replace(&mut self.0, IoRef(inner));
let filter = mem::replace(&mut self.1, FilterItem::Ptr(ptr::null_mut()));
Self(state, filter)
}
}
impl<F> Io<F> {