Skip to content

Commit

Permalink
[inetstack] Enhancement: Cancel pending ops
Browse files Browse the repository at this point in the history
  • Loading branch information
iyzhang committed Nov 16, 2023
1 parent 30a1cd8 commit c38446d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/rust/inetstack/protocols/tcp/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ impl<const N: usize> SharedTcpQueue<N> {

pub fn close(&mut self) -> Result<Option<SocketId>, Fail> {
self.state_machine.prepare(SocketOp::Close)?;
self.cancel_pending_ops(Fail::new(libc::ECANCELED, "This queue was closed"));
let new_socket: Option<Socket<N>> = match self.socket {
// Closing an active socket.
Socket::Established(ref mut socket) => {
Expand Down Expand Up @@ -496,6 +497,16 @@ impl<const N: usize> SharedTcpQueue<N> {
self.pending_ops.insert(handle.clone(), yielder_handle.clone());
}

/// Cancel all currently pending operations on this queue. If the operation is not complete and the coroutine has
/// yielded, wake the coroutine with an error.
fn cancel_pending_ops(&mut self, cause: Fail) {
for (handle, mut yielder_handle) in self.pending_ops.drain() {
if !handle.has_completed() {
yielder_handle.wake_with(Err(cause.clone()));
}
}
}

/// Generic function for spawning a control-path coroutine on [self].
fn do_generic_sync_control_path_call<F>(&mut self, coroutine: F) -> Result<TaskHandle, Fail>
where
Expand Down

0 comments on commit c38446d

Please sign in to comment.