Skip to content

Commit

Permalink
fix state machine of the progress engine
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed Jul 19, 2024
1 parent 4da94e9 commit 9806cb2
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions src/fd/socket/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,35 +84,25 @@ impl Socket {
}

async fn async_close(&self) -> io::Result<()> {
future::poll_fn(|cx| {
self.with(|socket| match socket.state() {
tcp::State::FinWait1
| tcp::State::FinWait2
| tcp::State::Closed
| tcp::State::Closing
| tcp::State::TimeWait => Poll::Ready(Err(io::Error::EIO)),
_ => {
if socket.send_queue() > 0 {
socket.register_send_waker(cx.waker());
Poll::Pending
} else {
socket.close();
Poll::Ready(Ok(()))
}
future::poll_fn(|_cx| {
self.with(|socket| {
if socket.is_active() {
socket.close();
Poll::Ready(Ok(()))
} else {
Poll::Ready(Err(io::Error::EIO))
}
})
})
.await?;

future::poll_fn(|cx| {
self.with(|socket| match socket.state() {
tcp::State::FinWait1
| tcp::State::FinWait2
| tcp::State::Closed
| tcp::State::Closing
| tcp::State::TimeWait => Poll::Ready(Ok(())),
_ => {
self.with(|socket| {
if !socket.is_active() {
Poll::Ready(Ok(()))
} else {
socket.register_send_waker(cx.waker());
socket.register_recv_waker(cx.waker());
Poll::Pending
}
})
Expand Down Expand Up @@ -243,9 +233,7 @@ impl ObjectInterface for Socket {
async fn async_read(&self, buffer: &mut [u8]) -> io::Result<usize> {
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::Closed => Poll::Ready(Ok(0)),
tcp::State::FinWait1
| tcp::State::FinWait2
| tcp::State::Listen
Expand Down

0 comments on commit 9806cb2

Please sign in to comment.