Cleanup internal flags on io error

This commit is contained in:
Nikolay Kim 2021-12-29 01:55:09 +06:00
parent 7a54d61376
commit 59eedcc51c
4 changed files with 21 additions and 13 deletions

View file

@ -1,5 +1,9 @@
# Changes
## [0.1.0-b.10] - 2021-12-xx
* Cleanup internal flags on io error
## [0.1.0-b.9] - 2021-12-29
* Add `async-std` support

View file

@ -18,7 +18,6 @@ impl Filter for Base {
fn closed(&self, err: Option<io::Error>) {
self.0 .0.set_error(err);
self.0 .0.handle.take();
self.0 .0.insert_flags(Flags::IO_CLOSED);
self.0 .0.dispatch_task.wake();
}

View file

@ -21,8 +21,6 @@ bitflags::bitflags! {
const IO_FILTERS_TO = 0b0000_0000_0000_0100;
/// shutdown io tasks
const IO_SHUTDOWN = 0b0000_0000_0000_1000;
/// io object is closed
const IO_CLOSED = 0b0000_0000_0001_0000;
/// pause io read
const RD_PAUSED = 0b0000_0000_0010_0000;
@ -107,9 +105,10 @@ impl IoState {
#[inline]
pub(super) fn is_io_open(&self) -> bool {
!self.flags.get().intersects(
Flags::IO_ERR | Flags::IO_SHUTDOWN | Flags::IO_SHUTDOWN | Flags::IO_CLOSED,
)
!self
.flags
.get()
.intersects(Flags::IO_ERR | Flags::IO_SHUTDOWN)
}
#[inline]
@ -120,8 +119,18 @@ impl IoState {
self.read_task.wake();
self.write_task.wake();
self.dispatch_task.wake();
self.insert_flags(Flags::IO_ERR);
self.notify_disconnect();
let mut flags = self.flags.get();
flags.insert(Flags::IO_ERR);
flags.remove(
Flags::DSP_KEEPALIVE
| Flags::RD_PAUSED
| Flags::RD_READY
| Flags::RD_BUF_FULL
| Flags::WR_WAIT
| Flags::WR_BACKPRESSURE,
);
self.flags.set(flags);
}
#[inline]
@ -617,7 +626,7 @@ impl<F> Io<F> {
pub fn poll_shutdown(&self, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
let flags = self.flags();
if flags.intersects(Flags::IO_ERR | Flags::IO_CLOSED) {
if flags.intersects(Flags::IO_ERR) {
Poll::Ready(Ok(()))
} else {
if !flags.contains(Flags::IO_FILTERS) {

View file

@ -48,11 +48,7 @@ impl IoRef {
/// Check if io stream is closed
pub fn is_closed(&self) -> bool {
self.0.flags.get().intersects(
Flags::IO_ERR
| Flags::IO_SHUTDOWN
| Flags::IO_CLOSED
| Flags::IO_FILTERS
| Flags::DSP_STOP,
Flags::IO_ERR | Flags::IO_SHUTDOWN | Flags::IO_FILTERS | Flags::DSP_STOP,
)
}