Skip to content

Commit d1226b5

Browse files
committed
Fixup windows
1 parent 30f1966 commit d1226b5

6 files changed

Lines changed: 228 additions & 115 deletions

File tree

datadog-ipc/src/example_interface.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
time::{Duration, Instant},
1010
};
1111

12-
use super::platform::PlatformHandle;
12+
use super::platform::{FileBackedHandle, PlatformHandle, ShmHandle};
1313

1414
extern crate self as datadog_ipc;
1515

@@ -21,6 +21,13 @@ pub trait ExampleInterface {
2121
async fn time_now() -> Duration;
2222
async fn req_cnt() -> u32;
2323
async fn store_file(#[SerializedHandle] file: PlatformHandle<File>);
24+
/// Receives a shared memory handle, maps it, and returns the sum of the first `len` bytes.
25+
/// Used to verify cross-process handle transfer (Windows DuplicateHandle / Unix SCM_RIGHTS).
26+
async fn shm_sum(#[SerializedHandle] handle: ShmHandle, len: usize) -> u64;
27+
/// Receives a byte payload and returns its length.
28+
/// Used to verify that messages larger than mio's 4 KB internal read buffer are handled
29+
/// correctly (no ERROR_MORE_DATA panic).
30+
async fn echo_len(payload: Vec<u8>) -> u32;
2431
}
2532

2633
#[derive(Default, Clone)]
@@ -29,7 +36,6 @@ pub struct ExampleServer {
2936
stored_files: Arc<Mutex<Vec<PlatformHandle<File>>>>,
3037
}
3138

32-
#[cfg(unix)]
3339
impl ExampleServer {
3440
pub async fn accept_connection(self, conn: crate::SeqpacketConn) {
3541
serve_example_interface_connection(conn, Arc::new(self)).await
@@ -78,4 +84,26 @@ impl ExampleInterface for ExampleServer {
7884
self.stored_files.lock().unwrap().push(file);
7985
std::future::ready(())
8086
}
87+
88+
fn shm_sum(
89+
&self,
90+
_peer: datadog_ipc::PeerCredentials,
91+
handle: ShmHandle,
92+
len: usize,
93+
) -> impl std::future::Future<Output = u64> + Send + '_ {
94+
async move {
95+
match handle.map() {
96+
Ok(mapped) => mapped.as_slice()[..len].iter().map(|&b| b as u64).sum(),
97+
Err(_) => u64::MAX,
98+
}
99+
}
100+
}
101+
102+
fn echo_len(
103+
&self,
104+
_peer: datadog_ipc::PeerCredentials,
105+
payload: Vec<u8>,
106+
) -> impl std::future::Future<Output = u32> + Send + '_ {
107+
std::future::ready(payload.len() as u32)
108+
}
81109
}

datadog-ipc/src/platform/windows/handles.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ use crate::platform::PlatformHandle;
66
use std::collections::VecDeque;
77
use std::os::windows::io::{FromRawHandle, IntoRawHandle, OwnedHandle};
88

9-
/// No-op sink — Windows handles are transferred in-band via message suffix, not out-of-band.
10-
pub struct FdSink;
9+
/// Collects Windows handles to be transferred in-band in the message suffix.
10+
///
11+
/// `copy_handle` records each handle's raw value; `into_fds` returns them so
12+
/// `append_handle_suffix` can duplicate them into the peer process before sending.
13+
pub struct FdSink(Vec<std::os::windows::io::RawHandle>);
1114

1215
impl FdSink {
1316
pub fn new() -> Self {
14-
FdSink
17+
FdSink(Vec::new())
1518
}
1619

1720
pub fn into_fds(self) -> Vec<std::os::windows::io::RawHandle> {
18-
Vec::new()
21+
self.0
1922
}
2023
}
2124

@@ -28,7 +31,9 @@ impl Default for FdSink {
2831
impl HandlesTransport for &mut FdSink {
2932
type Error = std::convert::Infallible;
3033

31-
fn copy_handle<T>(self, _handle: PlatformHandle<T>) -> Result<(), Self::Error> {
34+
fn copy_handle<T>(self, handle: PlatformHandle<T>) -> Result<(), Self::Error> {
35+
use std::os::windows::io::AsRawHandle;
36+
self.0.push(handle.as_raw_handle());
3237
Ok(())
3338
}
3439

0 commit comments

Comments
 (0)