-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
202 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.IO; | ||
namespace PodeMonitor | ||
{ | ||
public static class PipeNameGenerator | ||
{ | ||
private const string WindowsPipePrefix = @"\\.\pipe\"; // Windows pipe namespace | ||
private const int MaxUnixPathLength = 104; // Max length for Unix domain sockets on macOS | ||
private const string UnixTempDir = "/tmp"; // Short temporary directory for Unix systems | ||
|
||
public static string GeneratePipeName() | ||
{ | ||
// Generate a unique name based on a GUID | ||
string uniqueId = Guid.NewGuid().ToString("N").Substring(0, 8); | ||
|
||
if (OperatingSystem.IsWindows()) | ||
{ | ||
// Use Windows named pipe format | ||
return $"{WindowsPipePrefix}PodePipe_{uniqueId}"; | ||
} | ||
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) | ||
{ | ||
// Use Unix domain socket format with a shorter temp directory | ||
string pipePath = Path.Combine(UnixTempDir, $"PodePipe_{uniqueId}"); | ||
|
||
// Ensure the path is within the allowed length for Unix domain sockets | ||
if (pipePath.Length > MaxUnixPathLength) | ||
{ | ||
throw new InvalidOperationException($"Generated pipe path exceeds the maximum length of {MaxUnixPathLength} characters: {pipePath}"); | ||
} | ||
|
||
return pipePath; | ||
} | ||
else | ||
{ | ||
throw new PlatformNotSupportedException("Unsupported operating system for pipe name generation."); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.