Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[inetstack] Implement async_close #530

Merged
merged 1 commit into from
Mar 13, 2023
Merged

Conversation

iyzhang
Copy link
Contributor

@iyzhang iyzhang commented Mar 9, 2023

This PR implements asynchronous close for the inet stack. Importantly, this PR creates a future/coroutine for driving the TCP connection to the close state and then freeing resources associated with the queue/socket. This PR leaves TODOs for actually implementing the TCP close state transitions for a later PR. Currently, the future immediately returns without being yielding, so there is no need to wake up the future. We will need to store a waker in the established socket, separate from the one for receiving data for close operations. Note that there is no need to free any of the socket data structures or control blocks explicitly because they are now all owned by the IoQueueTable, so when we free the queue descriptor, all associated metadata should be correctly freed as well. This means that it is important for us to not free the queue descriptor or SocketIds in the addresses backmap until we are sure that we will not continue to receive any more packets for the connection.

@iyzhang iyzhang requested a review from ppenna March 9, 2023 01:03
@iyzhang iyzhang force-pushed the enhancement-inetstack-async-close branch from b73b821 to 4dcf75f Compare March 9, 2023 01:31
@iyzhang iyzhang added the enhancement Enhancement Request on an Existing Feature label Mar 9, 2023
// Remember that the user has called close.
self.user_is_done_sending.set(true);

Ok(())
}

/// Handle moving the connection to the closed state.
///
/// This function runs the TCP state machine once it has either sent or received a FIN. This function is only for
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this function is meant for closing established connections only, shouldn't we name it accordingly, like poll_close_established()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured that was unnecessary since it is inside the established socket already.

FutureOperation::from(fut)
},
Some(QType::UdpSocket) => {
let udp_op = UdpOperation::Pushto(qd, self.ipv4.udp.do_close(qd));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to keep a symmetric design, don't we want a self.ipv4.udp.do_async_close()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is symmetric with how UDP handles Push, where there is nothing asynchronous to do, so I left it without an additional implementation. (In fact, I forgot to change the name of the UdpOperation!)

@iyzhang iyzhang force-pushed the enhancement-inetstack-async-close branch from 4dcf75f to 6876763 Compare March 9, 2023 18:37
@ppenna ppenna force-pushed the enhancement-inetstack-async-close branch from 6876763 to 78bf36b Compare March 13, 2023 11:58
@ppenna ppenna merged commit 0f67a1b into dev Mar 13, 2023
@ppenna ppenna deleted the enhancement-inetstack-async-close branch March 13, 2023 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement Request on an Existing Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants