@@ -2272,6 +2272,7 @@ impl ServerOptions {
22722272pub struct ClientOptions {
22732273 desired_access : u32 ,
22742274 security_qos_flags : u32 ,
2275+ pipe_mode : PipeMode ,
22752276}
22762277
22772278impl ClientOptions {
@@ -2293,6 +2294,7 @@ impl ClientOptions {
22932294 desired_access : windows_sys:: GENERIC_READ | windows_sys:: GENERIC_WRITE ,
22942295 security_qos_flags : windows_sys:: SECURITY_IDENTIFICATION
22952296 | windows_sys:: SECURITY_SQOS_PRESENT ,
2297+ pipe_mode : PipeMode :: Byte ,
22962298 }
22972299 }
22982300
@@ -2345,6 +2347,15 @@ impl ClientOptions {
23452347 self
23462348 }
23472349
2350+ /// The pipe mode.
2351+ ///
2352+ /// The default pipe mode is [`PipeMode::Byte`]. See [`PipeMode`] for
2353+ /// documentation of what each mode means.
2354+ pub fn pipe_mode ( & mut self , pipe_mode : PipeMode ) -> & mut Self {
2355+ self . pipe_mode = pipe_mode;
2356+ self
2357+ }
2358+
23482359 /// Opens the named pipe identified by `addr`.
23492360 ///
23502361 /// This opens the client using [`CreateFile`] with the
@@ -2441,6 +2452,20 @@ impl ClientOptions {
24412452 return Err ( io:: Error :: last_os_error ( ) ) ;
24422453 }
24432454
2455+ if matches ! ( self . pipe_mode, PipeMode :: Message ) {
2456+ let mut mode = windows_sys:: PIPE_READMODE_MESSAGE ;
2457+ let result = windows_sys:: SetNamedPipeHandleState (
2458+ h,
2459+ & mut mode,
2460+ ptr:: null_mut ( ) ,
2461+ ptr:: null_mut ( ) ,
2462+ ) ;
2463+
2464+ if result == 0 {
2465+ return Err ( io:: Error :: last_os_error ( ) ) ;
2466+ }
2467+ }
2468+
24442469 NamedPipeClient :: from_raw_handle ( h as _ )
24452470 }
24462471
@@ -2560,7 +2585,9 @@ unsafe fn named_pipe_info(handle: RawHandle) -> io::Result<PipeInfo> {
25602585
25612586#[ cfg( test) ]
25622587mod test {
2563- use self :: windows_sys:: { PIPE_REJECT_REMOTE_CLIENTS , PIPE_TYPE_BYTE , PIPE_TYPE_MESSAGE , PIPE_READMODE_MESSAGE } ;
2588+ use self :: windows_sys:: {
2589+ PIPE_READMODE_MESSAGE , PIPE_REJECT_REMOTE_CLIENTS , PIPE_TYPE_BYTE , PIPE_TYPE_MESSAGE ,
2590+ } ;
25642591 use super :: * ;
25652592
25662593 #[ test]
0 commit comments