Skip to content
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

fix(edge): UnixDomainSocketEndPoint is available in .NET 2.1 and greater #1816

Merged
merged 5 commits into from
Mar 9, 2021
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
using var stream = new HttpBufferedStream(new NetworkStream(socket, true));

byte[] requestBytes = HttpRequestResponseSerializer.SerializeRequest(request);

#if NET451 || NET472 || NETSTANDARD2_0
await stream.WriteAsync(requestBytes, 0, requestBytes.Length, cancellationToken).ConfigureAwait(false);
#else
Expand All @@ -42,10 +43,27 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage

private async Task<Socket> GetConnectedSocketAsync()
{
var endpoint = new UnixDomainSocketEndPoint(_providerUri.LocalPath);
Socket socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
await socket.ConnectAsync(endpoint).ConfigureAwait(false);

/*
jamdavi marked this conversation as resolved.
Show resolved Hide resolved
* The Edge Agent uses unix sockets for communication with the modules deployed in docker for HSM.
* For netstandard 2.0 there was no implementation for a Unix Domain Socket (UDS) so we used a version
* that was part of a test that was reused in a number of libraries on the internet.
*
* https://github.com/dotnet/corefx/blob/12b51c6bf153cc237b251a4e264d5e7c0ee84a33/src/System.IO.Pipes/src/System/Net/Sockets/UnixDomainSocketEndPoint.cs
* https://github.com/dotnet/corefx/blob/12b51c6bf153cc237b251a4e264d5e7c0ee84a33/src/System.Net.Sockets/tests/FunctionalTests/UnixDomainSocketTest.cs#L248
*
* Since then the UnixDomainSocketEndpoint has been added to the dotnet framework and there has been considerable work
* around unix sockets in the BCL. For older versions of the framework we will continue to use the existing class since it works
* fine. For netcore 2.1 and greater as well as .NET 5.0 and greater we'll use the native framework version.
*/

#if NET451 || NET472 || NETSTANDARD2_0
var endpoint = new UnixDomainSocketEndPoint(_providerUri.LocalPath);
jamdavi marked this conversation as resolved.
Show resolved Hide resolved
#else
var endpoint = new System.Net.Sockets.UnixDomainSocketEndPoint(_providerUri.LocalPath);
jamdavi marked this conversation as resolved.
Show resolved Hide resolved
#endif
await socket.ConnectAsync(endpoint).ConfigureAwait(false);
return socket;
}
}
Expand Down