Named Pipes: Support Message Read Mode #5349
Labels
A-tokio
Area: The main tokio crate
C-feature-request
Category: A feature request.
M-net
Module: tokio/net
Context on Windows Named Pipes
Windows has message-based and byte stream-based pipes, but there also is an additional concept of read modes. From the docs:
Is your feature request related to a problem? Please describe.
Tokio allows the creation of message-based named pipes using
.pipe_mode
, but it currently always opens them in byte read mode. In other words, when calling.read()
, a "random" slice of bytes is returned (which may not be aligned with message boundaries). This was unexpected to me, I expected to read messages from my message pipe.The same problem applies to NamedPipeClient instances, which always operate in byte read mode at the moment.
Describe the solution you'd like
When calling
server_options.pipe_mode(PipeMode::Message)
, the pipe should not only be set to be a message type pipe, but it should also be opened in message read mode.For NamedPipeClient, an additional
.pipe_mode
method should be added to the builder to switch to message read mode (equivalent to the server).Describe alternatives you've considered
The first design decision here is whether tokio should expose Windows' distinction between pipe type and read mode. In other words, tokio could alternatively expose two distinct
.pipe_mode
and.read_mode
builder methods. I personally feel that this comes at the risk of introducting subtle bugs (people will forget to also set.read_mode
, which isn't immediately obvious).The second design decision is whether ClientNamedPipe should 1) automatically query the pipe type and use the equivalent read mode, or 2) have an explicit
.pipe_mode
builder method. The explicit version seems more reasonable to me, but I don't have strong opinions on this either.Additional context
I will follow up with a PR for the proposed changes momentarily. :)
The text was updated successfully, but these errors were encountered: