@@ -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
1414extern 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) ]
3339impl 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}
0 commit comments