pipedconsole/com/
receive.rs

1
2#[cfg(windows)]
3use winapi::um::{fileapi::ReadFile, errhandlingapi::GetLastError};
4
5use std::ffi::c_void;
6use crate::error::InternalError;
7
8#[cfg(not(windows))]
9pub(crate) unsafe fn receive(pipe_handle: *mut c_void, buffer: *mut i8, bytes_to_read: u32) -> Result<u32, InternalError> {
10    Ok(0)
11}
12
13// This code is used.
14#[allow(dead_code)]
15#[cfg(windows)]
16pub(crate) unsafe fn receive(pipe_handle: *mut c_void, buffer: *mut i8, bytes_to_read: u32) -> Result<u32, InternalError> {
17
18    let mut bytes_read = 0;
19
20    ReadFile(
21        pipe_handle,
22        buffer as *mut c_void,
23        bytes_to_read,
24        &mut bytes_read,
25        std::ptr::null_mut()
26    );
27
28    let error = GetLastError();
29    match error {
30        0 => (),
31        0x6D => return Err(InternalError::PipeBroken), // todo this does not work
32        0xEA => return Err(InternalError::MoreData),
33        _ => return Err(InternalError::OsError(error))
34    }
35
36    Ok(bytes_read)
37
38}