Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore timing out errors unless the timeout was specified to INFINITE #3

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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