|
1 | 1 | #![unstable(issue = "none", feature = "windows_handle")] |
2 | 2 |
|
| 3 | +#[cfg(test)] |
| 4 | +mod tests; |
| 5 | + |
3 | 6 | use crate::cmp; |
4 | 7 | use crate::io::{self, ErrorKind, IoSlice, IoSliceMut, Read, ReadBuf}; |
5 | 8 | use crate::mem; |
@@ -248,14 +251,18 @@ impl Handle { |
248 | 251 | offset.map(|n| n as _).as_ref(), |
249 | 252 | None, |
250 | 253 | ); |
| 254 | + |
| 255 | + let status = if status == c::STATUS_PENDING { |
| 256 | + c::WaitForSingleObject(self.as_raw_handle(), c::INFINITE); |
| 257 | + io_status.status() |
| 258 | + } else { |
| 259 | + status |
| 260 | + }; |
251 | 261 | match status { |
252 | 262 | // If the operation has not completed then abort the process. |
253 | 263 | // Doing otherwise means that the buffer and stack may be written to |
254 | 264 | // after this function returns. |
255 | | - c::STATUS_PENDING => { |
256 | | - eprintln!("I/O error: operation failed to complete synchronously"); |
257 | | - crate::process::abort(); |
258 | | - } |
| 265 | + c::STATUS_PENDING => rtabort!("I/O error: operation failed to complete synchronously"), |
259 | 266 |
|
260 | 267 | // Return `Ok(0)` when there's nothing more to read. |
261 | 268 | c::STATUS_END_OF_FILE => Ok(0), |
@@ -294,13 +301,17 @@ impl Handle { |
294 | 301 | None, |
295 | 302 | ) |
296 | 303 | }; |
| 304 | + let status = if status == c::STATUS_PENDING { |
| 305 | + unsafe { c::WaitForSingleObject(self.as_raw_handle(), c::INFINITE) }; |
| 306 | + io_status.status() |
| 307 | + } else { |
| 308 | + status |
| 309 | + }; |
297 | 310 | match status { |
298 | 311 | // If the operation has not completed then abort the process. |
299 | 312 | // Doing otherwise means that the buffer may be read and the stack |
300 | 313 | // written to after this function returns. |
301 | | - c::STATUS_PENDING => { |
302 | | - rtabort!("I/O error: operation failed to complete synchronously"); |
303 | | - } |
| 314 | + c::STATUS_PENDING => rtabort!("I/O error: operation failed to complete synchronously"), |
304 | 315 |
|
305 | 316 | // Success! |
306 | 317 | status if c::nt_success(status) => Ok(io_status.Information), |
|
0 commit comments