@@ -1681,11 +1681,10 @@ impl ServerOptions {
1681
1681
///
1682
1682
/// [`dwPipeMode`]: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createnamedpipea
1683
1683
pub fn pipe_mode ( & mut self , pipe_mode : PipeMode ) -> & mut Self {
1684
- self . pipe_mode = match pipe_mode {
1685
- PipeMode :: Byte => winbase:: PIPE_TYPE_BYTE ,
1686
- PipeMode :: Message => winbase:: PIPE_TYPE_MESSAGE ,
1687
- } ;
1688
-
1684
+ let is_msg = matches ! ( pipe_mode, PipeMode :: Message ) ;
1685
+ // Pipe mode is implemented as a bit flag 0x4. Set is message and unset
1686
+ // is byte.
1687
+ bool_flag ! ( self . pipe_mode, is_msg, winbase:: PIPE_TYPE_MESSAGE ) ;
1689
1688
self
1690
1689
}
1691
1690
@@ -2412,3 +2411,48 @@ unsafe fn named_pipe_info(handle: RawHandle) -> io::Result<PipeInfo> {
2412
2411
max_instances,
2413
2412
} )
2414
2413
}
2414
+
2415
+ #[ cfg( test) ]
2416
+ mod test {
2417
+ use self :: winbase:: { PIPE_REJECT_REMOTE_CLIENTS , PIPE_TYPE_BYTE , PIPE_TYPE_MESSAGE } ;
2418
+ use super :: * ;
2419
+
2420
+ #[ test]
2421
+ fn opts_default_pipe_mode ( ) {
2422
+ let opts = ServerOptions :: new ( ) ;
2423
+ assert_eq ! ( opts. pipe_mode, PIPE_TYPE_BYTE | PIPE_REJECT_REMOTE_CLIENTS ) ;
2424
+ }
2425
+
2426
+ #[ test]
2427
+ fn opts_unset_reject_remote ( ) {
2428
+ let mut opts = ServerOptions :: new ( ) ;
2429
+ opts. reject_remote_clients ( false ) ;
2430
+ assert_eq ! ( opts. pipe_mode & PIPE_REJECT_REMOTE_CLIENTS , 0 ) ;
2431
+ }
2432
+
2433
+ #[ test]
2434
+ fn opts_set_pipe_mode_maintains_reject_remote_clients ( ) {
2435
+ let mut opts = ServerOptions :: new ( ) ;
2436
+ opts. pipe_mode ( PipeMode :: Byte ) ;
2437
+ assert_eq ! ( opts. pipe_mode, PIPE_TYPE_BYTE | PIPE_REJECT_REMOTE_CLIENTS ) ;
2438
+
2439
+ opts. reject_remote_clients ( false ) ;
2440
+ opts. pipe_mode ( PipeMode :: Byte ) ;
2441
+ assert_eq ! ( opts. pipe_mode, PIPE_TYPE_BYTE ) ;
2442
+
2443
+ opts. reject_remote_clients ( true ) ;
2444
+ opts. pipe_mode ( PipeMode :: Byte ) ;
2445
+ assert_eq ! ( opts. pipe_mode, PIPE_TYPE_BYTE | PIPE_REJECT_REMOTE_CLIENTS ) ;
2446
+
2447
+ opts. reject_remote_clients ( false ) ;
2448
+ opts. pipe_mode ( PipeMode :: Message ) ;
2449
+ assert_eq ! ( opts. pipe_mode, PIPE_TYPE_MESSAGE ) ;
2450
+
2451
+ opts. reject_remote_clients ( true ) ;
2452
+ opts. pipe_mode ( PipeMode :: Message ) ;
2453
+ assert_eq ! (
2454
+ opts. pipe_mode,
2455
+ PIPE_TYPE_MESSAGE | PIPE_REJECT_REMOTE_CLIENTS
2456
+ ) ;
2457
+ }
2458
+ }
0 commit comments