Skip to content

Commit

Permalink
Keep interests_to_afd_flags in sync with is_* functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
goffrie authored and Thomasdezeeuw committed May 20, 2020
1 parent a98da62 commit 6ac72bb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
23 changes: 16 additions & 7 deletions src/sys/windows/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,35 @@ pub fn token(event: &Event) -> Token {
Token(event.data as usize)
}

pub(crate) const READABLE_FLAGS: u32 = afd::POLL_RECEIVE
| afd::POLL_DISCONNECT
| afd::POLL_ACCEPT
| afd::POLL_ABORT
| afd::POLL_CONNECT_FAIL;
pub(crate) const WRITABLE_FLAGS: u32 = afd::POLL_SEND | afd::POLL_ABORT | afd::POLL_CONNECT_FAIL;
pub(crate) const ERROR_FLAGS: u32 = afd::POLL_CONNECT_FAIL;
pub(crate) const READ_CLOSED_FLAGS: u32 =
afd::POLL_DISCONNECT | afd::POLL_ABORT | afd::POLL_CONNECT_FAIL;
pub(crate) const WRITE_CLOSED_FLAGS: u32 = afd::POLL_ABORT | afd::POLL_CONNECT_FAIL;

pub fn is_readable(event: &Event) -> bool {
event.flags
& (afd::POLL_RECEIVE | afd::POLL_DISCONNECT | afd::POLL_ACCEPT | afd::POLL_CONNECT_FAIL)
!= 0
event.flags & READABLE_FLAGS != 0
}

pub fn is_writable(event: &Event) -> bool {
event.flags & (afd::POLL_SEND | afd::POLL_CONNECT_FAIL) != 0
event.flags & WRITABLE_FLAGS != 0
}

pub fn is_error(event: &Event) -> bool {
event.flags & afd::POLL_CONNECT_FAIL != 0
event.flags & ERROR_FLAGS != 0
}

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

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

pub fn is_priority(event: &Event) -> bool {
Expand Down
8 changes: 5 additions & 3 deletions src/sys/windows/selector.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use super::afd::{self, Afd, AfdPollInfo};
use super::io_status_block::IoStatusBlock;
use super::Event;
use crate::sys::event::{
ERROR_FLAGS, READABLE_FLAGS, READ_CLOSED_FLAGS, WRITABLE_FLAGS, WRITE_CLOSED_FLAGS,
};
use crate::sys::Events;
use crate::Interest;

Expand Down Expand Up @@ -719,12 +722,11 @@ fn interests_to_afd_flags(interests: Interest) -> u32 {
let mut flags = 0;

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

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

flags
Expand Down
2 changes: 2 additions & 0 deletions tests/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ fn connect_error() {
}

assert!(l.take_error().unwrap().is_some());

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

#[test]
Expand Down

0 comments on commit 6ac72bb

Please sign in to comment.