diff --git a/DebugAdapter/UIX.DebugAdapter.Shared/ConnectionStringHelper.cs b/DebugAdapter/UIX.DebugAdapter.Shared/ConnectionStringHelper.cs index 1b2942b..f67f6fc 100644 --- a/DebugAdapter/UIX.DebugAdapter.Shared/ConnectionStringHelper.cs +++ b/DebugAdapter/UIX.DebugAdapter.Shared/ConnectionStringHelper.cs @@ -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); - pipeToClient.WaitForConnection(); - pipeFromClient.WaitForConnection(); + pipe.WaitForConnection(); - var loggingInputStream = new LoggingStream(pipeFromClient, LoggingStream_OnRead, LoggingStream_OnWrite); - var loggingOutputStream = new LoggingStream(pipeToClient, LoggingStream_OnRead, LoggingStream_OnWrite); + 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); - input = loggingInputStream; - output = loggingOutputStream; + 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)); } diff --git a/DebugAdapter/UIX.DebugAdapter.Shared/NamedPipeUtils.cs b/DebugAdapter/UIX.DebugAdapter.Shared/NamedPipeUtils.cs index 8f75a6f..d58e1ac 100644 --- a/DebugAdapter/UIX.DebugAdapter.Shared/NamedPipeUtils.cs +++ b/DebugAdapter/UIX.DebugAdapter.Shared/NamedPipeUtils.cs @@ -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 /// /// The named pipe name to validate. This should be a simple name rather than a path. /// True if the named pipe name is valid, false otherwise. - public static bool IsPipeNameValid(string pipeName) + public static bool IsPipeNameAvailable(string pipeName) { if (string.IsNullOrEmpty(pipeName)) {