Skip to content

Commit

Permalink
Merge pull request #3 from bmc-msft/ignore-GetQueuedCompletionStatus-…
Browse files Browse the repository at this point in the history
…timeout-errors
  • Loading branch information
passcod committed Aug 26, 2021
2 parents d16879f + 0a5a194 commit 6c37f76
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
17 changes: 14 additions & 3 deletions src/stdlib/child/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use std::{
process::{Child, ChildStderr, ChildStdin, ChildStdout, ExitStatus},
};
use winapi::{
shared::{basetsd::ULONG_PTR, minwindef::DWORD},
shared::{
basetsd::ULONG_PTR,
minwindef::{DWORD, FALSE},
},
um::{
handleapi::CloseHandle, ioapiset::GetQueuedCompletionStatus, jobapi2::TerminateJobObject,
minwinbase::LPOVERLAPPED, winbase::INFINITE, winnt::HANDLE,
Expand Down Expand Up @@ -69,15 +72,23 @@ impl ChildImp {
let mut key: ULONG_PTR = 0;
let mut overlapped = mem::MaybeUninit::<LPOVERLAPPED>::uninit();

res_bool(unsafe {
let result = unsafe {
GetQueuedCompletionStatus(
self.handles.completion_port,
&mut code,
&mut key,
overlapped.as_mut_ptr(),
timeout,
)
})?;
};

// ignore timing out errors unless the timeout was specified to INFINITE
// https://docs.microsoft.com/en-us/windows/win32/api/ioapiset/nf-ioapiset-getqueuedcompletionstatus
if timeout != INFINITE && result == FALSE && overlapped.as_ptr().is_null() {
return Ok(());
}

res_bool(result)?;

Ok(())
}
Expand Down
17 changes: 14 additions & 3 deletions src/tokio/child/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use tokio::{
task::spawn_blocking,
};
use winapi::{
shared::{basetsd::ULONG_PTR, minwindef::DWORD},
shared::{
basetsd::ULONG_PTR,
minwindef::{DWORD, FALSE},
},
um::{
handleapi::CloseHandle, ioapiset::GetQueuedCompletionStatus, jobapi2::TerminateJobObject,
minwinbase::LPOVERLAPPED, winbase::INFINITE, winnt::HANDLE,
Expand Down Expand Up @@ -69,15 +72,23 @@ impl ChildImp {
let mut key: ULONG_PTR = 0;
let mut overlapped = mem::MaybeUninit::<LPOVERLAPPED>::uninit();

res_bool(unsafe {
let result = unsafe {
GetQueuedCompletionStatus(
handles.completion_port,
&mut code,
&mut key,
overlapped.as_mut_ptr(),
timeout,
)
})?;
};

// ignore timing out errors unless the timeout was specified to INFINITE
// https://docs.microsoft.com/en-us/windows/win32/api/ioapiset/nf-ioapiset-getqueuedcompletionstatus
if timeout != INFINITE && result == FALSE && overlapped.as_ptr().is_null() {
return Ok(());
}

res_bool(result)?;

// don't drop them
mem::forget(handles);
Expand Down
7 changes: 6 additions & 1 deletion src/tokio/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ impl AsyncCommandGroup for Command {
self.creation_flags(CREATE_SUSPENDED);

let child = self.spawn()?;
assign_child(child.raw_handle().expect("child has exited but it has not even started"), job)?;
assign_child(
child
.raw_handle()
.expect("child has exited but it has not even started"),
job,
)?;

Ok(AsyncGroupChild::new(child, job, completion_port))
}
Expand Down
4 changes: 2 additions & 2 deletions src/winres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
ptr,
};
use winapi::{
shared::minwindef::{BOOL, DWORD, LPVOID},
shared::minwindef::{BOOL, DWORD, FALSE, LPVOID},
um::{
handleapi::{CloseHandle, INVALID_HANDLE_VALUE},
ioapiset::CreateIoCompletionPort,
Expand Down Expand Up @@ -48,7 +48,7 @@ pub(crate) fn res_null(handle: HANDLE) -> Result<HANDLE> {
}

pub(crate) fn res_bool(ret: BOOL) -> Result<()> {
if ret == 0 {
if ret == FALSE {
Err(Error::last_os_error())
} else {
Ok(())
Expand Down

0 comments on commit 6c37f76

Please sign in to comment.