mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
Support simplex and stdin/out
This commit is contained in:
@@ -7,22 +7,46 @@ namespace Microsoft.Iris.DebugAdapter;
|
||||
|
||||
public static class ConnectionStringHelper
|
||||
{
|
||||
private static readonly bool _useDuplex = false;
|
||||
|
||||
public static void CreateFromString(string connectionString, out Stream input, out Stream output)
|
||||
{
|
||||
// TODO: Support other transports
|
||||
if (NamedPipeUtils.TryGetPipeName(connectionString, out var pipeName))
|
||||
{
|
||||
var pipeToClient = NamedPipeUtils.CreateNamedPipe(pipeName + "_ToClient", PipeDirection.Out);
|
||||
var pipeFromClient = NamedPipeUtils.CreateNamedPipe(pipeName + "_FromClient", PipeDirection.In);
|
||||
Console.WriteLine($"Using pipe name {pipeName}");
|
||||
if (_useDuplex)
|
||||
{
|
||||
var pipe = NamedPipeUtils.CreateNamedPipe(pipeName, PipeDirection.InOut);
|
||||
|
||||
pipe.WaitForConnection();
|
||||
|
||||
var loggingStream = new LoggingStream(pipe, LoggingStream_OnRead, LoggingStream_OnWrite);
|
||||
|
||||
input = loggingStream;
|
||||
output = loggingStream;
|
||||
}
|
||||
else
|
||||
{
|
||||
var pipeToClientName = pipeName + "_ToClient";
|
||||
var pipeToClient = NamedPipeUtils.CreateNamedPipe(pipeToClientName, PipeDirection.Out);
|
||||
|
||||
var pipeFromClientName = pipeName + "_FromClient";
|
||||
var pipeFromClient = NamedPipeUtils.CreateNamedPipe(pipeFromClientName, PipeDirection.In);
|
||||
|
||||
Console.WriteLine($"Waiting for simplex pipe connections, {pipeToClientName} & {pipeFromClientName}");
|
||||
|
||||
pipeToClient.WaitForConnection();
|
||||
pipeFromClient.WaitForConnection();
|
||||
|
||||
Console.WriteLine("Pipes connected!");
|
||||
|
||||
var loggingInputStream = new LoggingStream(pipeFromClient, LoggingStream_OnRead, LoggingStream_OnWrite);
|
||||
var loggingOutputStream = new LoggingStream(pipeToClient, LoggingStream_OnRead, LoggingStream_OnWrite);
|
||||
|
||||
input = loggingInputStream;
|
||||
output = loggingOutputStream;
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (Uri.TryCreate(connectionString, UriKind.Absolute, out var connectionUri))
|
||||
@@ -32,6 +56,12 @@ public static class ConnectionStringHelper
|
||||
|
||||
}
|
||||
}
|
||||
else if (connectionString.Equals("std", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
input = Console.OpenStandardInput();
|
||||
output = Console.OpenStandardOutput();
|
||||
return;
|
||||
}
|
||||
|
||||
throw new ArgumentException("Invalid connection string", nameof(connectionString));
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public static class NamedPipeUtils
|
||||
// In the simple prefix-less case, just test the pipe name
|
||||
if (prefixes == null)
|
||||
{
|
||||
if (!IsPipeNameValid(pipeName))
|
||||
if (!IsPipeNameAvailable(pipeName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public static class NamedPipeUtils
|
||||
foreach (string prefix in prefixes)
|
||||
{
|
||||
string prefixedPipeName = $"IrisUIX_{prefix}_{pipeName}";
|
||||
if (!IsPipeNameValid(prefixedPipeName))
|
||||
if (!IsPipeNameAvailable(prefixedPipeName))
|
||||
{
|
||||
allPipeNamesValid = false;
|
||||
break;
|
||||
@@ -122,7 +122,7 @@ public static class NamedPipeUtils
|
||||
|
||||
public static bool TryGetPipeName(string pipePath, [NotNullWhen(true)] out string? pipeName)
|
||||
{
|
||||
if (!IsPipeNameValid(pipePath))
|
||||
if (!IsPipeNameAvailable(pipePath) || !pipePath.StartsWith(PIPE_PREFIX))
|
||||
{
|
||||
pipeName = null;
|
||||
return false;
|
||||
@@ -144,7 +144,7 @@ public static class NamedPipeUtils
|
||||
/// </summary>
|
||||
/// <param name="pipeName">The named pipe name to validate. This should be a simple name rather than a path.</param>
|
||||
/// <returns>True if the named pipe name is valid, false otherwise.</returns>
|
||||
public static bool IsPipeNameValid(string pipeName)
|
||||
public static bool IsPipeNameAvailable(string pipeName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(pipeName))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user