mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 18:19:40 +00:00
Fix references to socket APIs, and target the lowest net standard versions possible
This commit is contained in:
@@ -9,12 +9,18 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels.PhysicalConnections
|
||||
private bool _disposedValue = false;
|
||||
private NamedPipeClientStream _namedPipeClientStream;
|
||||
|
||||
#pragma warning disable 1998 // Because in the NET451 code path, there's nothing to await
|
||||
public override async Task<Stream> Open(string address)
|
||||
{
|
||||
_namedPipeClientStream = new NamedPipeClientStream(".", address, PipeDirection.InOut);
|
||||
#if NET451
|
||||
_namedPipeClientStream.Connect();
|
||||
#else
|
||||
await _namedPipeClientStream.ConnectAsync().ConfigureAwait(false);
|
||||
#endif
|
||||
return _namedPipeClientStream;
|
||||
}
|
||||
#pragma warning restore 1998
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNetCore.NodeServices.HostingModels.PhysicalConnections
|
||||
@@ -12,7 +11,11 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels.PhysicalConnections
|
||||
|
||||
public static StreamConnection Create()
|
||||
{
|
||||
var useNamedPipes = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||
#if NET451
|
||||
return new NamedPipeConnection();
|
||||
#else
|
||||
var useNamedPipes = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(
|
||||
System.Runtime.InteropServices.OSPlatform.Windows);
|
||||
if (useNamedPipes)
|
||||
{
|
||||
return new NamedPipeConnection();
|
||||
@@ -21,6 +24,7 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels.PhysicalConnections
|
||||
{
|
||||
return new UnixDomainSocketConnection();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,16 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels.PhysicalConnections
|
||||
private NetworkStream _networkStream;
|
||||
private Socket _socket;
|
||||
|
||||
#if NET451
|
||||
public override Task<Stream> Open(string address)
|
||||
{
|
||||
// The 'null' assignments avoid the compiler warnings about unassigned fields.
|
||||
// Note that this whole class isn't supported on .NET 4.5.1, since that's not cross-platform.
|
||||
_networkStream = null;
|
||||
_socket = null;
|
||||
throw new System.PlatformNotSupportedException();
|
||||
}
|
||||
#else
|
||||
public override async Task<Stream> Open(string address)
|
||||
{
|
||||
var endPoint = new UnixDomainSocketEndPoint("/tmp/" + address);
|
||||
@@ -18,6 +28,7 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels.PhysicalConnections
|
||||
_networkStream = new NetworkStream(_socket);
|
||||
return _networkStream;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
|
||||
@@ -59,7 +59,11 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels.PhysicalConnections
|
||||
}
|
||||
else
|
||||
{
|
||||
#if NET451
|
||||
_encodedPath = new byte[0];
|
||||
#else
|
||||
_encodedPath = Array.Empty<byte>();
|
||||
#endif
|
||||
_path = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,11 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels.VirtualConnections
|
||||
/// </summary>
|
||||
internal class VirtualConnection : Stream
|
||||
{
|
||||
#if NET451
|
||||
private readonly static Task CompletedTask = Task.FromResult((object)null);
|
||||
#else
|
||||
private readonly static Task CompletedTask = Task.CompletedTask;
|
||||
#endif
|
||||
private VirtualConnectionClient _host;
|
||||
private readonly BufferBlock<byte[]> _receivedDataQueue = new BufferBlock<byte[]>();
|
||||
private ArraySegment<byte> _receivedDataNotYetUsed;
|
||||
@@ -109,7 +114,7 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels.VirtualConnections
|
||||
throw new InvalidOperationException("The connection was already closed by the remote party");
|
||||
}
|
||||
|
||||
return count > 0 ? _host.WriteAsync(Id, buffer, offset, count, cancellationToken) : Task.CompletedTask;
|
||||
return count > 0 ? _host.WriteAsync(Id, buffer, offset, count, cancellationToken) : CompletedTask;
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
|
||||
Reference in New Issue
Block a user