Skip to content

Commit e7e62c5

Browse files
committed
🐛 ipcServer
1 parent 87517a0 commit e7e62c5

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/BD.Common8.Ipc.Server/Services/Implementation/IpcServerService.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ protected virtual void OnExiting()
180180

181181
void Build()
182182
{
183+
var listenNamedPipe = ListenNamedPipe &&
184+
OperatingSystem.IsWindows(); // 虽然命名管道在 Unix 使用 UnixSocket 兼容实现,但是在 ASP.NET Core 中会抛出平台不支持异常
185+
183186
var builder = WebApplication.CreateEmptyBuilder(new WebApplicationOptions());
184187
builder.WebHost.UseKestrelCore();
185188
builder.WebHost.UseKestrelHttpsConfiguration();
@@ -215,7 +218,7 @@ static bool IsUsePort(IPAddress address, int port)
215218
listenOptions.UseHttps(serverCertificate);
216219
});
217220
}
218-
if (ListenNamedPipe)
221+
if (listenNamedPipe)
219222
{
220223
options.ListenNamedPipe(PipeName, listenOptions =>
221224
{
@@ -237,11 +240,11 @@ static bool IsUsePort(IPAddress address, int port)
237240
}
238241
});
239242

240-
if (ListenNamedPipe &&
241-
OperatingSystem.IsWindows() &&
242-
Environment.IsPrivilegedProcess)
243+
if (listenNamedPipe)
243244
{
245+
#pragma warning disable CA1416 // 验证平台兼容性
244246
builder.WebHost.UseNamedPipes(ConfigureNamedPipeTransportOptions);
247+
#pragma warning restore CA1416 // 验证平台兼容性
245248
}
246249

247250
builder.Services.Configure<KestrelServerOptions>(static options =>
@@ -453,7 +456,6 @@ protected virtual string GetUnixSocketPath()
453456
var dirPath = GetUnixSocketDirPath();
454457
IOPath.DirCreateByNotExists(dirPath);
455458
var filePath = Path.Combine(dirPath, $"{Hashs.String.Crc32(PipeName)}.uds"); // Unix Domain Socket
456-
IOPath.FileTryDelete(filePath);
457459
return filePath;
458460
}
459461

0 commit comments

Comments
 (0)