-
Notifications
You must be signed in to change notification settings - Fork 116
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
Conversation
b73b821
to
4dcf75f
Compare
// 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 |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
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.
src/rust/inetstack/mod.rs
Outdated
FutureOperation::from(fut) | ||
}, | ||
Some(QType::UdpSocket) => { | ||
let udp_op = UdpOperation::Pushto(qd, self.ipv4.udp.do_close(qd)); |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
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!)
4dcf75f
to
6876763
Compare
6876763
to
78bf36b
Compare
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.