Skip to content

Ensure NamedPipeServerStream is assigned in Windows PowerShell #955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 15, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Threading;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete?

using System.Threading.Tasks;
using System.Diagnostics;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete?


namespace Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.Channel
{
Expand Down Expand Up @@ -60,8 +62,27 @@ public override void Start()
{
try
{
if (Utils.IsNetCore)
{
this.inOutPipeServer = new NamedPipeServerStream(
pipeName: inOutPipeName,
direction: PipeDirection.InOut,
maxNumberOfServerInstances: 1,
transmissionMode: PipeTransmissionMode.Byte,
options: PipeOptions.Asynchronous | (PipeOptions)CurrentUserOnly);
if (this.outPipeName != null)
{
this.outPipeServer = new NamedPipeServerStream(
pipeName: outPipeName,
direction: PipeDirection.Out,
maxNumberOfServerInstances: 1,
transmissionMode: PipeTransmissionMode.Byte,
options: (PipeOptions)CurrentUserOnly);
}

}
// If we're running in Windows PowerShell, we use the constructor via Reflection
if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework"))
else
{
PipeSecurity pipeSecurity = new PipeSecurity();

Expand All @@ -83,7 +104,7 @@ public override void Start()
PipeAccessRights.ReadWrite, AccessControlType.Allow));
}

_netFrameworkPipeServerConstructor.Invoke(new object[]
this.inOutPipeServer = (NamedPipeServerStream)_netFrameworkPipeServerConstructor.Invoke(new object[]
{
inOutPipeName,
PipeDirection.InOut,
Expand All @@ -97,7 +118,7 @@ public override void Start()

if (this.outPipeName != null)
{
_netFrameworkPipeServerConstructor.Invoke(new object[]
this.outPipeServer = (NamedPipeServerStream)_netFrameworkPipeServerConstructor.Invoke(new object[]
{
outPipeName,
PipeDirection.InOut,
Expand All @@ -110,24 +131,6 @@ public override void Start()
});
}
}
else
{
this.inOutPipeServer = new NamedPipeServerStream(
pipeName: inOutPipeName,
direction: PipeDirection.InOut,
maxNumberOfServerInstances: 1,
transmissionMode: PipeTransmissionMode.Byte,
options: PipeOptions.Asynchronous | (PipeOptions)CurrentUserOnly);
if (this.outPipeName != null)
{
this.outPipeServer = new NamedPipeServerStream(
pipeName: outPipeName,
direction: PipeDirection.Out,
maxNumberOfServerInstances: 1,
transmissionMode: PipeTransmissionMode.Byte,
options: (PipeOptions)CurrentUserOnly);
}
}
ListenForConnection();
}
catch (IOException e)
Expand Down Expand Up @@ -188,11 +191,7 @@ private void ListenForConnection()

private static async Task WaitForConnectionAsync(NamedPipeServerStream pipeServerStream)
{
#if CoreCLR
await pipeServerStream.WaitForConnectionAsync();
#else
await Task.Factory.FromAsync(pipeServerStream.BeginWaitForConnection, pipeServerStream.EndWaitForConnection, null);
#endif
await pipeServerStream.FlushAsync();
}
}
Expand Down