Skip to content

Commit

Permalink
Return error for Io::poll_read_ready() if io is closed (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 authored Oct 7, 2024
1 parent 3a74770 commit c670b51
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions ntex-io/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

## [2.6.1] - 2024-10-17

* Return error for Io::poll_read_ready() if io is closed.

## [2.6.0] - 2024-10-17

* Return error for IoRef::write(), IoRef::with_write_buf(), Io::poll_flush() if io is closed.
Expand Down
2 changes: 1 addition & 1 deletion ntex-io/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ntex-io"
version = "2.6.0"
version = "2.6.1"
authors = ["ntex contributors <[email protected]>"]
description = "Utilities for encoding and decoding frames"
keywords = ["network", "framework", "async", "futures"]
Expand Down
14 changes: 10 additions & 4 deletions ntex-io/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ impl<F> Io<F> {
fn error(&self) -> Option<io::Error> {
self.st().error.take()
}

/// Get current io error
fn error_or_disconnected(&self) -> io::Error {
self.st()
.error
.take()
.unwrap_or_else(|| io::Error::new(io::ErrorKind::Other, "Disconnected"))
}
}

impl<F: FilterLayer, T: Filter> Io<Layer<F, T>> {
Expand Down Expand Up @@ -415,7 +423,7 @@ impl<F> Io<F> {
let mut flags = st.flags.get();

if flags.is_stopped() {
Poll::Ready(self.error().map(Err).unwrap_or(Ok(None)))
Poll::Ready(Err(self.error_or_disconnected()))
} else {
st.dispatch_task.register(cx.waker());

Expand Down Expand Up @@ -540,9 +548,7 @@ impl<F> Io<F> {
let flags = self.flags();

if flags.is_stopped() {
Poll::Ready(self.error().map(Err).unwrap_or_else(|| {
Err(io::Error::new(io::ErrorKind::Other, "Disconnected"))
}))
Poll::Ready(Err(self.error_or_disconnected()))
} else {
let st = self.st();
let len = st.buffer.write_destination_size();
Expand Down
2 changes: 1 addition & 1 deletion ntex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ntex-bytes = "0.1.27"
ntex-server = "2.4"
ntex-h2 = "1.1"
ntex-rt = "0.4.18"
ntex-io = "2.5"
ntex-io = "2.6"
ntex-net = "2.4"
ntex-tls = "2.1"

Expand Down

0 comments on commit c670b51

Please sign in to comment.