Skip to content

Commit

Permalink
fix for issue tokio-rs#1073, deregistering not working on windows. Wh…
Browse files Browse the repository at this point in the history
…en deregistering a socket make sure it is marked for deletion so it won't be used in poll updates.

Signed-off-by: Daniel Tacalau <dst4096@gmail.com>
  • Loading branch information
dtacalau committed Nov 7, 2019
1 parent 6fc3ba8 commit 3814509
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/sys/windows/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,17 @@ impl super::SocketState for TcpListener {
let mut internal = self.internal.lock().unwrap();
match &mut *internal {
Some(internal) => {
// action of setting a None state it's a sign of deregistering a socket, so
// existing socket must be marked for deletion so it won't be used by selector
// for subsequent updates (atm it will be removed during first selector poll update)
if sock_state.is_none() {
if internal.sock_state.is_some() {
let sock_state = internal.sock_state.as_ref();
let mut sock_internal = sock_state.unwrap().lock().unwrap();
sock_internal.mark_delete();
}
}

internal.sock_state = sock_state;
}
None => {}
Expand Down
1 change: 0 additions & 1 deletion tests/tcp_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ fn reregister() {
}

#[test]
#[cfg_attr(windows, ignore = "deregister doesn't work, see #1073")]
fn deregister() {
let (mut poll, mut events) = init_with_poll();

Expand Down

0 comments on commit 3814509

Please sign in to comment.