Skip to content

Commit 699573d

Browse files
committed
net: fix named pipes server configuration builder
The `pipe_mode` function would erase any previously set configuration option that is specified using the pipe_mode fit field. This patch fixes the builder to maintain the bit field when changing the pipe mode.
1 parent 5c76d07 commit 699573d

File tree

2 files changed

+49
-22
lines changed

2 files changed

+49
-22
lines changed

.github/workflows/ci.yml

-17
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ jobs:
3333
- features
3434
- minrust
3535
- fmt
36-
- clippy
3736
- docs
3837
- valgrind
3938
- loom-compile
@@ -341,22 +340,6 @@ jobs:
341340
exit 1
342341
fi
343342
344-
clippy:
345-
name: clippy
346-
runs-on: ubuntu-latest
347-
steps:
348-
- uses: actions/checkout@v2
349-
- name: Install Rust ${{ env.rust_clippy }}
350-
uses: actions-rs/toolchain@v1
351-
with:
352-
toolchain: ${{ env.rust_clippy }}
353-
override: true
354-
components: clippy
355-
- uses: Swatinem/rust-cache@v1
356-
# Run clippy
357-
- name: "clippy --all"
358-
run: cargo clippy --all --tests --all-features
359-
360343
docs:
361344
name: docs
362345
runs-on: ubuntu-latest

tokio/src/net/windows/named_pipe.rs

+49-5
Original file line numberDiff line numberDiff line change
@@ -1681,11 +1681,10 @@ impl ServerOptions {
16811681
///
16821682
/// [`dwPipeMode`]: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createnamedpipea
16831683
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);
16891688
self
16901689
}
16911690

@@ -2412,3 +2411,48 @@ unsafe fn named_pipe_info(handle: RawHandle) -> io::Result<PipeInfo> {
24122411
max_instances,
24132412
})
24142413
}
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

Comments
 (0)