Skip to content

Commit

Permalink
Windows: Fix afd::POLL_ABORT handling
Browse files Browse the repository at this point in the history
  • Loading branch information
goffrie authored and Thomasdezeeuw committed May 20, 2020
1 parent b8bbdcb commit a98da62
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/sys/windows/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn is_error(event: &Event) -> bool {
}

pub fn is_read_closed(event: &Event) -> bool {
event.flags & afd::POLL_DISCONNECT != 0
event.flags & (afd::POLL_ABORT | afd::POLL_DISCONNECT) != 0
}

pub fn is_write_closed(event: &Event) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions src/sys/windows/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,11 +720,11 @@ fn interests_to_afd_flags(interests: Interest) -> u32 {

if interests.is_readable() {
// afd::POLL_DISCONNECT for is_read_hup()
flags |= afd::POLL_RECEIVE | afd::POLL_ACCEPT | afd::POLL_DISCONNECT;
flags |= afd::POLL_RECEIVE | afd::POLL_ACCEPT | afd::POLL_DISCONNECT | afd::POLL_ABORT;
}

if interests.is_writable() {
flags |= afd::POLL_SEND;
flags |= afd::POLL_SEND | afd::POLL_ABORT;
}

flags
Expand Down
36 changes: 36 additions & 0 deletions tests/tcp_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,42 @@ fn tcp_shutdown_server_write_close_event() {
handle.join().expect("failed to join thread");
}

#[test]
fn tcp_reset_close_event() {
let (mut poll, mut events) = init_with_poll();

let listener = net::TcpListener::bind(any_local_address()).unwrap();
let sockaddr = listener.local_addr().unwrap();
let mut stream = TcpStream::connect(sockaddr).unwrap();

poll.registry()
.register(&mut stream, ID1, Interest::READABLE.add(Interest::WRITABLE))
.unwrap();

let server_stream = listener.accept().unwrap();

expect_events(
&mut poll,
&mut events,
vec![ExpectEvent::new(ID1, Interest::WRITABLE)],
);
checked_write!(stream.write(DATA1));

// Try to read something.
assert_would_block(stream.read(&mut [0]));

// Server goes away.
drop(server_stream);

expect_events(
&mut poll,
&mut events,
vec![ExpectEvent::new(ID1, Readiness::READ_CLOSED)],
);

expect_no_events(&mut poll, &mut events);
}

#[test]
#[cfg_attr(
windows,
Expand Down

0 comments on commit a98da62

Please sign in to comment.