mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-04 21:37:58 +03:00
Remove ReadFilter/WriteFilter traits
This commit is contained in:
parent
1af728eb01
commit
1ccb87ea51
6 changed files with 153 additions and 187 deletions
|
@ -9,27 +9,25 @@ pub struct ReadContext(pub(super) IoRef);
|
|||
impl ReadContext {
|
||||
#[inline]
|
||||
pub fn memory_pool(&self) -> PoolRef {
|
||||
self.0 .0.pool.get()
|
||||
self.0.memory_pool()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), ()>> {
|
||||
self.0 .0.filter.get().poll_read_ready(cx)
|
||||
self.0.filter().poll_read_ready(cx)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn close(&self, err: Option<io::Error>) {
|
||||
self.0 .0.filter.get().read_closed(err);
|
||||
self.0.filter().closed(err);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_read_buf(&self) -> BytesMut {
|
||||
self.0
|
||||
.0
|
||||
.filter
|
||||
.get()
|
||||
.filter()
|
||||
.get_read_buf()
|
||||
.unwrap_or_else(|| self.0 .0.pool.get().get_read_buf())
|
||||
.unwrap_or_else(|| self.0.memory_pool().get_read_buf())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -39,22 +37,20 @@ impl ReadContext {
|
|||
new_bytes: usize,
|
||||
) -> Result<(), io::Error> {
|
||||
if buf.is_empty() {
|
||||
self.0 .0.pool.get().release_read_buf(buf);
|
||||
self.0.memory_pool().release_read_buf(buf);
|
||||
Ok(())
|
||||
} else {
|
||||
let mut flags = self.0 .0.flags.get();
|
||||
let mut flags = self.0.flags();
|
||||
if new_bytes > 0 {
|
||||
flags.insert(Flags::RD_READY);
|
||||
self.0 .0.flags.set(flags);
|
||||
self.0.set_flags(flags);
|
||||
self.0 .0.dispatch_task.wake();
|
||||
}
|
||||
|
||||
let close = self.0 .0.filter.get().release_read_buf(buf, new_bytes)?;
|
||||
self.0.filter().release_read_buf(buf, new_bytes)?;
|
||||
|
||||
if flags.contains(Flags::IO_FILTERS) {
|
||||
self.0 .0.shutdown_filters(&self.0)?;
|
||||
} else if close {
|
||||
self.0 .0.init_shutdown(None, &self.0);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -66,17 +62,17 @@ pub struct WriteContext(pub(super) IoRef);
|
|||
impl WriteContext {
|
||||
#[inline]
|
||||
pub fn memory_pool(&self) -> PoolRef {
|
||||
self.0 .0.pool.get()
|
||||
self.0.memory_pool()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), WriteReadiness>> {
|
||||
self.0 .0.filter.get().poll_write_ready(cx)
|
||||
self.0.filter().poll_write_ready(cx)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn close(&self, err: Option<io::Error>) {
|
||||
self.0 .0.filter.get().write_closed(err)
|
||||
self.0.filter().closed(err)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -86,14 +82,14 @@ impl WriteContext {
|
|||
|
||||
#[inline]
|
||||
pub fn release_write_buf(&self, buf: BytesMut) -> Result<(), io::Error> {
|
||||
let pool = self.0 .0.pool.get();
|
||||
let mut flags = self.0 .0.flags.get();
|
||||
let pool = self.0.memory_pool();
|
||||
let mut flags = self.0.flags();
|
||||
|
||||
if buf.is_empty() {
|
||||
pool.release_write_buf(buf);
|
||||
if flags.intersects(Flags::WR_WAIT | Flags::WR_BACKPRESSURE) {
|
||||
flags.remove(Flags::WR_WAIT | Flags::WR_BACKPRESSURE);
|
||||
self.0 .0.flags.set(flags);
|
||||
self.0.set_flags(flags);
|
||||
self.0 .0.dispatch_task.wake();
|
||||
}
|
||||
} else {
|
||||
|
@ -102,7 +98,7 @@ impl WriteContext {
|
|||
&& buf.len() < pool.write_params_high() << 1
|
||||
{
|
||||
flags.remove(Flags::WR_BACKPRESSURE);
|
||||
self.0 .0.flags.set(flags);
|
||||
self.0.set_flags(flags);
|
||||
self.0 .0.dispatch_task.wake();
|
||||
}
|
||||
self.0 .0.write_buf.set(Some(buf))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue