@@ -1705,11 +1705,10 @@ impl ServerOptions {
1705
1705
///
1706
1706
/// [`dwPipeMode`]: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createnamedpipea
1707
1707
pub fn pipe_mode ( & mut self , pipe_mode : PipeMode ) -> & mut Self {
1708
- self . pipe_mode = match pipe_mode {
1709
- PipeMode :: Byte => windows_sys:: PIPE_TYPE_BYTE ,
1710
- PipeMode :: Message => windows_sys:: PIPE_TYPE_MESSAGE ,
1711
- } ;
1712
-
1708
+ let is_msg = matches ! ( pipe_mode, PipeMode :: Message ) ;
1709
+ // Pipe mode is implemented as a bit flag 0x4. Set is message and unset
1710
+ // is byte.
1711
+ bool_flag ! ( self . pipe_mode, is_msg, windows_sys:: PIPE_TYPE_MESSAGE ) ;
1713
1712
self
1714
1713
}
1715
1714
@@ -2554,3 +2553,48 @@ unsafe fn named_pipe_info(handle: RawHandle) -> io::Result<PipeInfo> {
2554
2553
max_instances,
2555
2554
} )
2556
2555
}
2556
+
2557
+ #[ cfg( test) ]
2558
+ mod test {
2559
+ use self :: windows_sys:: { PIPE_REJECT_REMOTE_CLIENTS , PIPE_TYPE_BYTE , PIPE_TYPE_MESSAGE } ;
2560
+ use super :: * ;
2561
+
2562
+ #[ test]
2563
+ fn opts_default_pipe_mode ( ) {
2564
+ let opts = ServerOptions :: new ( ) ;
2565
+ assert_eq ! ( opts. pipe_mode, PIPE_TYPE_BYTE | PIPE_REJECT_REMOTE_CLIENTS ) ;
2566
+ }
2567
+
2568
+ #[ test]
2569
+ fn opts_unset_reject_remote ( ) {
2570
+ let mut opts = ServerOptions :: new ( ) ;
2571
+ opts. reject_remote_clients ( false ) ;
2572
+ assert_eq ! ( opts. pipe_mode & PIPE_REJECT_REMOTE_CLIENTS , 0 ) ;
2573
+ }
2574
+
2575
+ #[ test]
2576
+ fn opts_set_pipe_mode_maintains_reject_remote_clients ( ) {
2577
+ let mut opts = ServerOptions :: new ( ) ;
2578
+ opts. pipe_mode ( PipeMode :: Byte ) ;
2579
+ assert_eq ! ( opts. pipe_mode, PIPE_TYPE_BYTE | PIPE_REJECT_REMOTE_CLIENTS ) ;
2580
+
2581
+ opts. reject_remote_clients ( false ) ;
2582
+ opts. pipe_mode ( PipeMode :: Byte ) ;
2583
+ assert_eq ! ( opts. pipe_mode, PIPE_TYPE_BYTE ) ;
2584
+
2585
+ opts. reject_remote_clients ( true ) ;
2586
+ opts. pipe_mode ( PipeMode :: Byte ) ;
2587
+ assert_eq ! ( opts. pipe_mode, PIPE_TYPE_BYTE | PIPE_REJECT_REMOTE_CLIENTS ) ;
2588
+
2589
+ opts. reject_remote_clients ( false ) ;
2590
+ opts. pipe_mode ( PipeMode :: Message ) ;
2591
+ assert_eq ! ( opts. pipe_mode, PIPE_TYPE_MESSAGE ) ;
2592
+
2593
+ opts. reject_remote_clients ( true ) ;
2594
+ opts. pipe_mode ( PipeMode :: Message ) ;
2595
+ assert_eq ! (
2596
+ opts. pipe_mode,
2597
+ PIPE_TYPE_MESSAGE | PIPE_REJECT_REMOTE_CLIENTS
2598
+ ) ;
2599
+ }
2600
+ }
0 commit comments