Skip to content

Commit

Permalink
read should return 0 if socket is in state closed/closing
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed Sep 3, 2023
1 parent b0b009c commit 73de27b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/fd/socket/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ impl<T> Socket<T> {
async fn async_read(&self, buffer: &mut [u8]) -> Result<isize, i32> {
future::poll_fn(|cx| {
self.with(|socket| match socket.state() {
tcp::State::Closed | tcp::State::Closing | tcp::State::CloseWait => {
Poll::Ready(Ok(0))
}
tcp::State::FinWait1
| tcp::State::FinWait2
| tcp::State::Closed
| tcp::State::Closing
| tcp::State::CloseWait
| tcp::State::Listen
| tcp::State::TimeWait => Poll::Ready(Err(-crate::errno::EIO)),
_ => {
if socket.can_recv() {
Expand Down Expand Up @@ -106,11 +107,12 @@ impl<T> Socket<T> {
let n = future::poll_fn(|cx| {
self.with(|socket| {
match socket.state() {
tcp::State::Closed | tcp::State::Closing | tcp::State::CloseWait => {
Poll::Ready(Ok(0))
}
tcp::State::FinWait1
| tcp::State::FinWait2
| tcp::State::Closed
| tcp::State::Closing
| tcp::State::CloseWait
| tcp::State::Listen
| tcp::State::TimeWait => Poll::Ready(Err(-crate::errno::EIO)),
_ => {
if socket.can_send() {
Expand Down

0 comments on commit 73de27b

Please sign in to comment.