dotnet core 创建命名管道,文件名中没有 "CoreFxPipe_"

dotnet core create named pipes without "CoreFxPipe_" in file name

使用 dotnet 核心的 NamedPipeClientStreamNamedPipeServerStream classes 创建命名管道时,关联的 "pipe"(看起来实际上是一个套接字)自动将 "CoreFxPipe_" 添加到文件名的前面。

有没有一种简单的方法可以防止这种行为?我只是希望文件名与我提供给构造函数的名称完全相同。

在dotnet核心documentation中,描述了以下构造函数:

NamedPipeServerStream(字符串)
使用指定的管道名称初始化 NamedPipeServerStream class 的新实例。

但是,由于上述原因,这种描述充其量只是误导。

解法:

管道名称使用绝对路径

详情:

查看 NamedPipeClientStream 的源代码,第 93 行 显示管道名称是 "normalized" 并调用GetPipePath 这是 PipeStream class 的一个方法。查看 PipeStream 的源代码,GetPipePathline 35.

上实现

似乎该方法检查 "IsPathRooted"(大概;管道名称是绝对路径)。如果是,那么它会给你"full control" over defining the path to the socket。否则,它会将套接字放在 /tmp/ 中,并向文件名添加 CoreFxPipe_[​​=38=] 前缀。

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

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