dotnet core create named pipes without “CoreFxPipe

2019-08-28 11:52发布

问题:

When creating named pipes using the NamedPipeClientStream or NamedPipeServerStream classes of dotnet core, the associated "pipe" (which appears to actually be a socket) has "CoreFxPipe_" added to the front of the file name automatically.

Is there a non-hacky way to prevent this behavior? I would simply like the file name to be exactly the name I provide to the constructor.

In the dotnet core documentation, it describes the following constructor:

NamedPipeServerStream(String)
Initializes a new instance of the NamedPipeServerStream class with the specified pipe name.

But, for reasons described above, this description appears to be misleading at best.

回答1:

Solution:

Use an absolute path for the pipe name

Details:

Looking through the source code for NamedPipeClientStream, line 93 reveals that the pipe name is "normalized" with a call to GetPipePath which is a method of the PipeStream class. Looking through the source code for PipeStream, GetPipePath is implemented on line 35.

It seems the method checks "IsPathRooted" (presumably; is the pipe name an absolute path). If it is then it will give you "full control" over defining the path to the socket. Otherwise it will place the socket in /tmp/ and add a prefix of CoreFxPipe_ to the filename.

line 93 https://github.com/dotnet/corefx/blob/master/src/System.IO.Pipes/src/System/IO/Pipes/NamedPipeClientStream.cs

line 35: https://github.com/dotnet/corefx/blob/master/src/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Unix.cs