Skip to content

Commit

Permalink
Fix Clippy warnings on Windows
Browse files Browse the repository at this point in the history
Seems this isn't check on the CI.
  • Loading branch information
Thomasdezeeuw committed Oct 8, 2021
1 parent b48cce6 commit e9e91ff
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 40 deletions.
24 changes: 12 additions & 12 deletions src/sys/windows/afd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ cfg_io_source! {
&AFD_HELPER_ATTRIBUTES as *const _ as *mut _,
&mut iosb,
null_mut(),
0 as ULONG,
0,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN,
0 as ULONG,
0,
null_mut(),
0 as ULONG,
0,
);
if status != STATUS_SUCCESS {
let raw_err = io::Error::from_raw_os_error(
Expand Down Expand Up @@ -214,18 +214,18 @@ cfg_io_source! {
}
}

pub const POLL_RECEIVE: u32 = 0b000_000_001;
pub const POLL_RECEIVE_EXPEDITED: u32 = 0b000_000_010;
pub const POLL_SEND: u32 = 0b000_000_100;
pub const POLL_DISCONNECT: u32 = 0b000_001_000;
pub const POLL_ABORT: u32 = 0b000_010_000;
pub const POLL_LOCAL_CLOSE: u32 = 0b000_100_000;
pub const POLL_RECEIVE: u32 = 0b0_0000_0001;
pub const POLL_RECEIVE_EXPEDITED: u32 = 0b0_0000_0010;
pub const POLL_SEND: u32 = 0b0_0000_0100;
pub const POLL_DISCONNECT: u32 = 0b0_0000_1000;
pub const POLL_ABORT: u32 = 0b0_0001_0000;
pub const POLL_LOCAL_CLOSE: u32 = 0b0_0010_0000;
// Not used as it indicated in each event where a connection is connected, not
// just the first time a connection is established.
// Also see https://github.com/piscisaureus/wepoll/commit/8b7b340610f88af3d83f40fb728e7b850b090ece.
pub const POLL_CONNECT: u32 = 0b001_000_000;
pub const POLL_ACCEPT: u32 = 0b010_000_000;
pub const POLL_CONNECT_FAIL: u32 = 0b100_000_000;
pub const POLL_CONNECT: u32 = 0b0_0100_0000;
pub const POLL_ACCEPT: u32 = 0b0_1000_0000;
pub const POLL_CONNECT_FAIL: u32 = 0b1_0000_0000;

pub const KNOWN_EVENTS: u32 = POLL_RECEIVE
| POLL_RECEIVE_EXPEDITED
Expand Down
11 changes: 4 additions & 7 deletions src/sys/windows/named_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,8 @@ impl Drop for NamedPipe {
}

let io = self.inner.io.lock().unwrap();

match io.read {
State::Pending(..) => {
drop(cancel(&self.inner.handle, &self.inner.read));
}
_ => {}
if let State::Pending(..) = io.read {
drop(cancel(&self.inner.handle, &self.inner.read));
}
}
}
Expand Down Expand Up @@ -587,7 +583,8 @@ impl Inner {

fn post_register(me: &Arc<Inner>, mut events: Option<&mut Vec<Event>>) {
let mut io = me.io.lock().unwrap();
if Inner::schedule_read(&me, &mut io, events.as_mut().map(|ptr| &mut **ptr)) {
#[allow(clippy::needless_option_as_deref)]
if Inner::schedule_read(me, &mut io, events.as_deref_mut()) {
if let State::None = io.write {
io.notify_writable(events);
}
Expand Down
21 changes: 9 additions & 12 deletions src/sys/windows/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl AfdGroup {

pub fn release_unused_afd(&self) {
let mut afd_group = self.afd_group.lock().unwrap();
afd_group.retain(|g| Arc::strong_count(&g) > 1);
afd_group.retain(|g| Arc::strong_count(g) > 1);
}
}

Expand All @@ -58,7 +58,7 @@ cfg_io_source! {
self._alloc_afd_group(&mut afd_group)?;
} else {
// + 1 reference in Vec
if Arc::strong_count(afd_group.last().unwrap()) >= POLL_GROUP__MAX_GROUP_SIZE + 1 {
if Arc::strong_count(afd_group.last().unwrap()) > POLL_GROUP__MAX_GROUP_SIZE {
self._alloc_afd_group(&mut afd_group)?;
}
}
Expand Down Expand Up @@ -447,11 +447,11 @@ impl SelectorInner {
if len == 0 {
continue;
}
return Ok(());
break Ok(());
}
} else {
self.select2(&mut events.statuses, &mut events.events, timeout)?;
return Ok(());
Ok(())
}
}

Expand All @@ -461,7 +461,7 @@ impl SelectorInner {
events: &mut Vec<Event>,
timeout: Option<Duration>,
) -> io::Result<usize> {
assert_eq!(self.is_polling.swap(true, Ordering::AcqRel), false);
assert!(!self.is_polling.swap(true, Ordering::AcqRel));

unsafe { self.update_sockets_events() }?;

Expand All @@ -481,7 +481,7 @@ impl SelectorInner {
for sock in update_queue.iter_mut() {
let mut sock_internal = sock.lock().unwrap();
if !sock_internal.is_pending_deletion() {
sock_internal.update(&sock)?;
sock_internal.update(sock)?;
}
}

Expand Down Expand Up @@ -517,12 +517,9 @@ impl SelectorInner {

let sock_state = from_overlapped(iocp_event.overlapped());
let mut sock_guard = sock_state.lock().unwrap();
match sock_guard.feed_event() {
Some(e) => {
events.push(e);
n += 1;
}
None => {}
if let Some(e) = sock_guard.feed_event() {
events.push(e);
n += 1;
}

if !sock_guard.is_pending_deletion() {
Expand Down
12 changes: 7 additions & 5 deletions tests/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,20 @@ pub fn set_linger_zero(socket: &TcpStream) {
l_linger: 0,
};

match unsafe {
let res = unsafe {
setsockopt(
socket.as_raw_socket() as _,
SOL_SOCKET,
SO_LINGER,
&val as *const _ as *const _,
size_of::<linger>() as _,
)
} {
SOCKET_ERROR => panic!("error setting linger: {}", io::Error::last_os_error()),
_ => {}
}
};
assert!(
res != SOCKET_ERROR,
"error setting linger: {}",
io::Error::last_os_error()
);
}

/// Returns a path to a temporary file using `name` as filename.
Expand Down
6 changes: 2 additions & 4 deletions tests/win_named_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ fn connect_before_client() {

let mut events = Events::with_capacity(128);
t!(poll.poll(&mut events, Some(Duration::new(0, 0))));
let e = events.iter().collect::<Vec<_>>();
assert_eq!(e.len(), 0);
assert_eq!(events.iter().count(), 0);
assert_eq!(
server.connect().err().unwrap().kind(),
io::ErrorKind::WouldBlock
Expand Down Expand Up @@ -157,8 +156,7 @@ fn connect_after_client() {

let mut events = Events::with_capacity(128);
t!(poll.poll(&mut events, Some(Duration::new(0, 0))));
let e = events.iter().collect::<Vec<_>>();
assert_eq!(e.len(), 0);
assert_eq!(events.iter().count(), 0);

let mut client = client(&name);
t!(poll.registry().register(
Expand Down

0 comments on commit e9e91ff

Please sign in to comment.