Fix references to socket APIs, and target the lowest net standard versions possible

This commit is contained in:
SteveSandersonMS
2016-06-01 18:04:40 +01:00
parent 931ba118e1
commit 311733b113
9 changed files with 45 additions and 9 deletions

View File

@@ -15,7 +15,7 @@
"frameworks": { "frameworks": {
"net451": { "net451": {
}, },
"netstandard1.5": { "netstandard1.0": {
"imports": [ "imports": [
"dotnet5.6", "dotnet5.6",
"dnxcore50", "dnxcore50",

View File

@@ -9,12 +9,18 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels.PhysicalConnections
private bool _disposedValue = false; private bool _disposedValue = false;
private NamedPipeClientStream _namedPipeClientStream; 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) public override async Task<Stream> Open(string address)
{ {
_namedPipeClientStream = new NamedPipeClientStream(".", address, PipeDirection.InOut); _namedPipeClientStream = new NamedPipeClientStream(".", address, PipeDirection.InOut);
#if NET451
_namedPipeClientStream.Connect();
#else
await _namedPipeClientStream.ConnectAsync().ConfigureAwait(false); await _namedPipeClientStream.ConnectAsync().ConfigureAwait(false);
#endif
return _namedPipeClientStream; return _namedPipeClientStream;
} }
#pragma warning restore 1998
public override void Dispose() public override void Dispose()
{ {

View File

@@ -1,6 +1,5 @@
using System; using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Microsoft.AspNetCore.NodeServices.HostingModels.PhysicalConnections namespace Microsoft.AspNetCore.NodeServices.HostingModels.PhysicalConnections
@@ -12,7 +11,11 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels.PhysicalConnections
public static StreamConnection Create() 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) if (useNamedPipes)
{ {
return new NamedPipeConnection(); return new NamedPipeConnection();
@@ -21,6 +24,7 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels.PhysicalConnections
{ {
return new UnixDomainSocketConnection(); return new UnixDomainSocketConnection();
} }
#endif
} }
} }
} }

View File

@@ -10,6 +10,16 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels.PhysicalConnections
private NetworkStream _networkStream; private NetworkStream _networkStream;
private Socket _socket; 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) public override async Task<Stream> Open(string address)
{ {
var endPoint = new UnixDomainSocketEndPoint("/tmp/" + address); var endPoint = new UnixDomainSocketEndPoint("/tmp/" + address);
@@ -18,6 +28,7 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels.PhysicalConnections
_networkStream = new NetworkStream(_socket); _networkStream = new NetworkStream(_socket);
return _networkStream; return _networkStream;
} }
#endif
public override void Dispose() public override void Dispose()
{ {

View File

@@ -59,7 +59,11 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels.PhysicalConnections
} }
else else
{ {
#if NET451
_encodedPath = new byte[0];
#else
_encodedPath = Array.Empty<byte>(); _encodedPath = Array.Empty<byte>();
#endif
_path = string.Empty; _path = string.Empty;
} }
} }

View File

@@ -12,6 +12,11 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels.VirtualConnections
/// </summary> /// </summary>
internal class VirtualConnection : Stream 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 VirtualConnectionClient _host;
private readonly BufferBlock<byte[]> _receivedDataQueue = new BufferBlock<byte[]>(); private readonly BufferBlock<byte[]> _receivedDataQueue = new BufferBlock<byte[]>();
private ArraySegment<byte> _receivedDataNotYetUsed; 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"); 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) public override int Read(byte[] buffer, int offset, int count)

View File

@@ -15,7 +15,10 @@
"frameworks": { "frameworks": {
"net451": { "net451": {
"frameworkAssemblies": { "frameworkAssemblies": {
"System.Net.Http": "4.0.0.0" "System.Net.Http": "4.0.0-*"
},
"dependencies": {
"Microsoft.Tpl.Dataflow": "4.5.24"
} }
}, },
"netstandard1.3": { "netstandard1.3": {
@@ -27,8 +30,11 @@
"dependencies": { "dependencies": {
"System.Console": "4.0.0-*", "System.Console": "4.0.0-*",
"System.Diagnostics.Process": "4.1.0-*", "System.Diagnostics.Process": "4.1.0-*",
"System.IO.Pipes": "4.0.0-*",
"System.Net.Http": "4.0.1-*", "System.Net.Http": "4.0.1-*",
"System.Text.RegularExpressions": "4.0.12-*" "System.Net.Sockets": "4.1.0-*",
"System.Text.RegularExpressions": "4.0.12-*",
"System.Threading.Tasks.Dataflow": "4.5.25-*"
} }
} }
}, },

View File

@@ -15,7 +15,7 @@
"frameworks": { "frameworks": {
"net451": { "net451": {
}, },
"netstandard1.5": { "netstandard1.0": {
"imports": [ "imports": [
"dotnet5.6", "dotnet5.6",
"dnxcore50", "dnxcore50",

View File

@@ -14,7 +14,7 @@
"frameworks": { "frameworks": {
"net451": { "net451": {
}, },
"netstandard1.5": { "netstandard1.0": {
"imports": [ "imports": [
"dotnet5.6", "dotnet5.6",
"dnxcore50", "dnxcore50",