Files
CommTester/CommIpc/PipeName.cs

25 lines
778 B
C#

using System.Diagnostics;
using System.Runtime.InteropServices;
namespace CommIpc;
public static class PipeName
{
/// <summary>
/// Creates a pipe name that is unique per parent process instance and child id.
/// </summary>
public static string ForChild(int childId, int? parentPid = null)
{
parentPid ??= Environment.ProcessId;
return $"CommTester_{parentPid}_{childId}";
}
/// <summary>
/// Returns the full pipe path for the current platform.
/// Windows: \\.\pipe\{pipeName}
/// Unix/macOS: /tmp/CoreFxPipe_{pipeName}
/// </summary>
public static string Describe(string pipeName) =>
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? $"\\\\.\\pipe\\{pipeName}" : $"/tmp/CoreFxPipe_{pipeName}";
}