-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Add Kestrel named pipes transport #44426
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#nullable enable | ||
*REMOVED*Microsoft.AspNetCore.Http.StreamResponseBodyFeature.StreamResponseBodyFeature(System.IO.Stream! stream, Microsoft.AspNetCore.Http.Features.IHttpResponseBodyFeature! priorFeature) -> void | ||
Microsoft.AspNetCore.Http.BindingAddress.IsNamedPipe.get -> bool | ||
Microsoft.AspNetCore.Http.BindingAddress.NamedPipeName.get -> string! | ||
Microsoft.AspNetCore.Http.StreamResponseBodyFeature.StreamResponseBodyFeature(System.IO.Stream! stream, Microsoft.AspNetCore.Http.Features.IHttpResponseBodyFeature? priorFeature) -> void |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.IO.Pipes; | ||
|
||
namespace Microsoft.AspNetCore.Connections.Features; | ||
|
||
/// <summary> | ||
/// Provides access to the connection's underlying <see cref="NamedPipeServerStream"/>. | ||
/// </summary> | ||
public interface IConnectionNamedPipeFeature | ||
{ | ||
/// <summary> | ||
/// Gets the underlying <see cref="NamedPipeServerStream"/>. | ||
/// </summary> | ||
NamedPipeServerStream NamedPipe { get; } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using System.Net; | ||
|
||
namespace Microsoft.AspNetCore.Connections; | ||
|
||
/// <summary> | ||
/// Represents a Named Pipe endpoint. | ||
/// </summary> | ||
public sealed class NamedPipeEndPoint : EndPoint | ||
{ | ||
internal const string LocalComputerServerName = "."; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="NamedPipeEndPoint"/> class. | ||
/// </summary> | ||
/// <param name="pipeName">The name of the pipe.</param> | ||
public NamedPipeEndPoint(string pipeName) : this(pipeName, LocalComputerServerName) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="NamedPipeEndPoint"/> class. | ||
/// </summary> | ||
/// <param name="pipeName">The name of the pipe.</param> | ||
/// <param name="serverName">The name of the remote computer to connect to, or "." to specify the local computer.</param> | ||
public NamedPipeEndPoint(string pipeName, string serverName) | ||
{ | ||
ServerName = serverName; | ||
PipeName = pipeName; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the name of the remote computer. The server name must be ".", the local computer, when creating a server. | ||
/// </summary> | ||
public string ServerName { get; } | ||
|
||
/// <summary> | ||
/// Gets the name of the pipe. | ||
/// </summary> | ||
public string PipeName { get; } | ||
|
||
/// <summary> | ||
/// Gets the pipe name represented by this <see cref="NamedPipeEndPoint"/> instance. | ||
/// </summary> | ||
public override string ToString() | ||
{ | ||
// Based on format at https://learn.microsoft.com/windows/win32/ipc/pipe-names | ||
return $@"\\{ServerName}\pipe\{PipeName}"; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a little bit more complicated than this. If the app is running in a Win32 App Container (think Windows Store app, NOT docker style container), then the pipe name needs to be of the format There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The user would add |
||
|
||
/// <inheritdoc/> | ||
public override bool Equals([NotNullWhen(true)] object? obj) | ||
{ | ||
return obj is NamedPipeEndPoint other && other.ServerName == ServerName && other.PipeName == PipeName; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override int GetHashCode() | ||
{ | ||
return ServerName.GetHashCode() ^ PipeName.GetHashCode(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
#nullable enable | ||
Microsoft.AspNetCore.Connections.Features.IConnectionNamedPipeFeature | ||
Microsoft.AspNetCore.Connections.Features.IConnectionNamedPipeFeature.NamedPipe.get -> System.IO.Pipes.NamedPipeServerStream! | ||
Microsoft.AspNetCore.Connections.Features.IStreamClosedFeature | ||
Microsoft.AspNetCore.Connections.Features.IStreamClosedFeature.OnClosed(System.Action<object?>! callback, object? state) -> void | ||
Microsoft.AspNetCore.Connections.IConnectionListenerFactorySelector | ||
Microsoft.AspNetCore.Connections.IConnectionListenerFactorySelector.CanBind(System.Net.EndPoint! endpoint) -> bool | ||
Microsoft.AspNetCore.Connections.NamedPipeEndPoint | ||
Microsoft.AspNetCore.Connections.NamedPipeEndPoint.NamedPipeEndPoint(string! pipeName) -> void | ||
Microsoft.AspNetCore.Connections.NamedPipeEndPoint.NamedPipeEndPoint(string! pipeName, string! serverName) -> void | ||
Microsoft.AspNetCore.Connections.NamedPipeEndPoint.PipeName.get -> string! | ||
Microsoft.AspNetCore.Connections.NamedPipeEndPoint.ServerName.get -> string! | ||
override Microsoft.AspNetCore.Connections.NamedPipeEndPoint.Equals(object? obj) -> bool | ||
override Microsoft.AspNetCore.Connections.NamedPipeEndPoint.GetHashCode() -> int | ||
override Microsoft.AspNetCore.Connections.NamedPipeEndPoint.ToString() -> string! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
#nullable enable | ||
Microsoft.AspNetCore.Connections.Features.IConnectionNamedPipeFeature | ||
Microsoft.AspNetCore.Connections.Features.IConnectionNamedPipeFeature.NamedPipe.get -> System.IO.Pipes.NamedPipeServerStream! | ||
Microsoft.AspNetCore.Connections.Features.IStreamClosedFeature | ||
Microsoft.AspNetCore.Connections.Features.IStreamClosedFeature.OnClosed(System.Action<object?>! callback, object? state) -> void | ||
Microsoft.AspNetCore.Connections.IConnectionListenerFactorySelector | ||
Microsoft.AspNetCore.Connections.IConnectionListenerFactorySelector.CanBind(System.Net.EndPoint! endpoint) -> bool | ||
Microsoft.AspNetCore.Connections.NamedPipeEndPoint | ||
Microsoft.AspNetCore.Connections.NamedPipeEndPoint.NamedPipeEndPoint(string! pipeName) -> void | ||
Microsoft.AspNetCore.Connections.NamedPipeEndPoint.NamedPipeEndPoint(string! pipeName, string! serverName) -> void | ||
Microsoft.AspNetCore.Connections.NamedPipeEndPoint.PipeName.get -> string! | ||
Microsoft.AspNetCore.Connections.NamedPipeEndPoint.ServerName.get -> string! | ||
override Microsoft.AspNetCore.Connections.NamedPipeEndPoint.Equals(object? obj) -> bool | ||
override Microsoft.AspNetCore.Connections.NamedPipeEndPoint.GetHashCode() -> int | ||
override Microsoft.AspNetCore.Connections.NamedPipeEndPoint.ToString() -> string! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This dovetails into the conversation going on in the thread model. Do you want to support connecting to other hosts? Is allowing a serverName intended to make this api represent the concept of a NamedPipe endpoint and as it has a server name, you're enabling representing it? Or is the intention to allow cross machine communication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just followed the flow of this object through and I'm convinced that for a service side application, including serverName doesn't make any sense. You only pass the path to NamedPipeServerStream as you can't create a named pipe on another host. NamedPipeServerStream inserts
\\.\pipe\
in front of the pipe name that you pass.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We added the server name here if someone wants to use this endpoint in a client. When Kestrel starts up, it validates that the server name is
.
.