Skip to content

Commit 311733b

Browse files
Fix references to socket APIs, and target the lowest net standard versions possible
1 parent 931ba11 commit 311733b

File tree

9 files changed

+45
-9
lines changed

9 files changed

+45
-9
lines changed

src/Microsoft.AspNetCore.AngularServices/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"frameworks": {
1616
"net451": {
1717
},
18-
"netstandard1.5": {
18+
"netstandard1.0": {
1919
"imports": [
2020
"dotnet5.6",
2121
"dnxcore50",

src/Microsoft.AspNetCore.NodeServices/HostingModels/PhysicalConnections/NamedPipeConnection.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ internal class NamedPipeConnection : StreamConnection
99
private bool _disposedValue = false;
1010
private NamedPipeClientStream _namedPipeClientStream;
1111

12+
#pragma warning disable 1998 // Because in the NET451 code path, there's nothing to await
1213
public override async Task<Stream> Open(string address)
1314
{
1415
_namedPipeClientStream = new NamedPipeClientStream(".", address, PipeDirection.InOut);
16+
#if NET451
17+
_namedPipeClientStream.Connect();
18+
#else
1519
await _namedPipeClientStream.ConnectAsync().ConfigureAwait(false);
20+
#endif
1621
return _namedPipeClientStream;
1722
}
23+
#pragma warning restore 1998
1824

1925
public override void Dispose()
2026
{

src/Microsoft.AspNetCore.NodeServices/HostingModels/PhysicalConnections/StreamConnection.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.IO;
3-
using System.Runtime.InteropServices;
43
using System.Threading.Tasks;
54

65
namespace Microsoft.AspNetCore.NodeServices.HostingModels.PhysicalConnections
@@ -12,7 +11,11 @@ internal abstract class StreamConnection : IDisposable
1211

1312
public static StreamConnection Create()
1413
{
15-
var useNamedPipes = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
14+
#if NET451
15+
return new NamedPipeConnection();
16+
#else
17+
var useNamedPipes = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(
18+
System.Runtime.InteropServices.OSPlatform.Windows);
1619
if (useNamedPipes)
1720
{
1821
return new NamedPipeConnection();
@@ -21,6 +24,7 @@ public static StreamConnection Create()
2124
{
2225
return new UnixDomainSocketConnection();
2326
}
27+
#endif
2428
}
2529
}
2630
}

src/Microsoft.AspNetCore.NodeServices/HostingModels/PhysicalConnections/UnixDomainSocketConnection.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ internal class UnixDomainSocketConnection : StreamConnection
1010
private NetworkStream _networkStream;
1111
private Socket _socket;
1212

13+
#if NET451
14+
public override Task<Stream> Open(string address)
15+
{
16+
// The 'null' assignments avoid the compiler warnings about unassigned fields.
17+
// Note that this whole class isn't supported on .NET 4.5.1, since that's not cross-platform.
18+
_networkStream = null;
19+
_socket = null;
20+
throw new System.PlatformNotSupportedException();
21+
}
22+
#else
1323
public override async Task<Stream> Open(string address)
1424
{
1525
var endPoint = new UnixDomainSocketEndPoint("/tmp/" + address);
@@ -18,6 +28,7 @@ public override async Task<Stream> Open(string address)
1828
_networkStream = new NetworkStream(_socket);
1929
return _networkStream;
2030
}
31+
#endif
2132

2233
public override void Dispose()
2334
{

src/Microsoft.AspNetCore.NodeServices/HostingModels/PhysicalConnections/UnixDomainSocketEndPoint.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ internal UnixDomainSocketEndPoint(SocketAddress socketAddress)
5959
}
6060
else
6161
{
62+
#if NET451
63+
_encodedPath = new byte[0];
64+
#else
6265
_encodedPath = Array.Empty<byte>();
66+
#endif
6367
_path = string.Empty;
6468
}
6569
}

src/Microsoft.AspNetCore.NodeServices/HostingModels/VirtualConnections/VirtualConnection.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels.VirtualConnections
1212
/// </summary>
1313
internal class VirtualConnection : Stream
1414
{
15+
#if NET451
16+
private readonly static Task CompletedTask = Task.FromResult((object)null);
17+
#else
18+
private readonly static Task CompletedTask = Task.CompletedTask;
19+
#endif
1520
private VirtualConnectionClient _host;
1621
private readonly BufferBlock<byte[]> _receivedDataQueue = new BufferBlock<byte[]>();
1722
private ArraySegment<byte> _receivedDataNotYetUsed;
@@ -109,7 +114,7 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati
109114
throw new InvalidOperationException("The connection was already closed by the remote party");
110115
}
111116

112-
return count > 0 ? _host.WriteAsync(Id, buffer, offset, count, cancellationToken) : Task.CompletedTask;
117+
return count > 0 ? _host.WriteAsync(Id, buffer, offset, count, cancellationToken) : CompletedTask;
113118
}
114119

115120
public override int Read(byte[] buffer, int offset, int count)

src/Microsoft.AspNetCore.NodeServices/project.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
"frameworks": {
1616
"net451": {
1717
"frameworkAssemblies": {
18-
"System.Net.Http": "4.0.0.0"
18+
"System.Net.Http": "4.0.0-*"
19+
},
20+
"dependencies": {
21+
"Microsoft.Tpl.Dataflow": "4.5.24"
1922
}
2023
},
2124
"netstandard1.3": {
@@ -27,8 +30,11 @@
2730
"dependencies": {
2831
"System.Console": "4.0.0-*",
2932
"System.Diagnostics.Process": "4.1.0-*",
33+
"System.IO.Pipes": "4.0.0-*",
3034
"System.Net.Http": "4.0.1-*",
31-
"System.Text.RegularExpressions": "4.0.12-*"
35+
"System.Net.Sockets": "4.1.0-*",
36+
"System.Text.RegularExpressions": "4.0.12-*",
37+
"System.Threading.Tasks.Dataflow": "4.5.25-*"
3238
}
3339
}
3440
},

src/Microsoft.AspNetCore.ReactServices/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"frameworks": {
1616
"net451": {
1717
},
18-
"netstandard1.5": {
18+
"netstandard1.0": {
1919
"imports": [
2020
"dotnet5.6",
2121
"dnxcore50",

src/Microsoft.AspNetCore.SpaServices/project.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"frameworks": {
1515
"net451": {
1616
},
17-
"netstandard1.5": {
17+
"netstandard1.0": {
1818
"imports": [
1919
"dotnet5.6",
2020
"dnxcore50",
@@ -26,5 +26,5 @@
2626
"embed": [
2727
"Content/**/*"
2828
]
29-
}
29+
}
3030
}

0 commit comments

Comments
 (0)