summaryrefslogtreecommitdiffstats
path: root/library/std/src/sys/windows/handle/tests.rs
blob: d836dae4c305b72b97c5e3d7a613c94d4f7c6799 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use crate::sys::pipe::{anon_pipe, Pipes};
use crate::{thread, time};

/// Test the synchronous fallback for overlapped I/O.
#[test]
fn overlapped_handle_fallback() {
    // Create some pipes. `ours` will be asynchronous.
    let Pipes { ours, theirs } = anon_pipe(true, false).unwrap();

    let async_readable = ours.into_handle();
    let sync_writeable = theirs.into_handle();

    thread::scope(|_| {
        thread::sleep(time::Duration::from_millis(100));
        sync_writeable.write(b"hello world!").unwrap();
    });

    // The pipe buffer starts empty so reading won't complete synchronously unless
    // our fallback path works.
    let mut buffer = [0u8; 1024];
    async_readable.read(&mut buffer).unwrap();
}