This commit is contained in:
sxyazi 2025-02-16 18:46:11 +08:00
parent aa17c063a4
commit 52c69c11d4
No known key found for this signature in database

View file

@ -1,4 +1,4 @@
use std::{io, ops::{Deref, DerefMut}, time::Duration}; use std::{ops::{Deref, DerefMut}, time::Duration};
pub struct AsyncStdin { pub struct AsyncStdin {
inner: std::io::StdinLock<'static>, inner: std::io::StdinLock<'static>,
@ -43,7 +43,7 @@ impl AsyncStdin {
}; };
match result { match result {
-1 => Err(io::Error::last_os_error()), -1 => Err(std::io::Error::last_os_error()),
0 => Ok(false), 0 => Ok(false),
_ => { _ => {
self.reset(); self.reset();
@ -69,9 +69,11 @@ impl AsyncStdin {
pub fn poll(&mut self, timeout: Duration) -> std::io::Result<bool> { pub fn poll(&mut self, timeout: Duration) -> std::io::Result<bool> {
use std::os::windows::io::AsRawHandle; use std::os::windows::io::AsRawHandle;
use windows_sys::Win32::{Foundation::WAIT_TIMEOUT, System::Threading::WaitForSingleObject};
let handle = self.inner.as_raw_handle(); let handle = self.inner.as_raw_handle();
let millis = timeout.as_millis(); let millis = timeout.as_millis();
match unsafe { WaitForSingleObject(handle, millis) } { match unsafe { WaitForSingleObject(handle, millis as u32) } {
WAIT_TIMEOUT => Ok(false), WAIT_TIMEOUT => Ok(false),
_ => Ok(true), _ => Ok(true),
} }