Target NETStandard2.0
This commit is contained in:
parent
6006ebe96f
commit
d25dbd572c
|
|
@ -16,8 +16,8 @@
|
||||||
<PackageReference Include="Internal.AspNetCore.Sdk" Version="$(InternalAspNetCoreSdkVersion)" PrivateAssets="All" />
|
<PackageReference Include="Internal.AspNetCore.Sdk" Version="$(InternalAspNetCoreSdkVersion)" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework' AND '$(OutputType)'=='library'">
|
<ItemGroup Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'">
|
||||||
<PackageReference Include="NETStandard.Library" Version="$(BundledNETStandardPackageVersion)" />
|
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,9 @@
|
||||||
<AspNetCoreVersion>2.0.0-*</AspNetCoreVersion>
|
<AspNetCoreVersion>2.0.0-*</AspNetCoreVersion>
|
||||||
<AspNetCoreIntegrationTestingVersion>0.4.0-*</AspNetCoreIntegrationTestingVersion>
|
<AspNetCoreIntegrationTestingVersion>0.4.0-*</AspNetCoreIntegrationTestingVersion>
|
||||||
<AspNetCoreModuleVersion>1.0.0-*</AspNetCoreModuleVersion>
|
<AspNetCoreModuleVersion>1.0.0-*</AspNetCoreModuleVersion>
|
||||||
|
<CoreFxVersion>4.4.0-*</CoreFxVersion>
|
||||||
<InternalAspNetCoreSdkVersion>2.1.0-*</InternalAspNetCoreSdkVersion>
|
<InternalAspNetCoreSdkVersion>2.1.0-*</InternalAspNetCoreSdkVersion>
|
||||||
<NETStandardImplicitPackageVersion>$(BundledNETStandardPackageVersion)</NETStandardImplicitPackageVersion>
|
<NETStandardLibraryNETFrameworkVersion>2.0.0-*</NETStandardLibraryNETFrameworkVersion>
|
||||||
<TestSdkVersion>15.3.0-*</TestSdkVersion>
|
<TestSdkVersion>15.3.0-*</TestSdkVersion>
|
||||||
<XunitVersion>2.3.0-beta2-*</XunitVersion>
|
<XunitVersion>2.3.0-beta2-*</XunitVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
<Import Project="..\..\build\dependencies.props" />
|
<Import Project="..\..\build\dependencies.props" />
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
@ -18,4 +18,8 @@
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(AspNetCoreVersion)" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
|
||||||
|
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Description>ASP.NET Core web socket middleware for use on top of opaque servers.</Description>
|
<Description>ASP.NET Core web socket middleware for use on top of opaque servers.</Description>
|
||||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.Extensions.Options" Version="$(AspNetCoreVersion)" />
|
||||||
|
<PackageReference Include="System.Numerics.Vectors" Version="$(CoreFxVersion)" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,71 @@ namespace Microsoft.AspNetCore.WebSockets.Test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
|
||||||
|
{
|
||||||
|
// TODO: This option doesn't preserve the state object.
|
||||||
|
// return ReadAsync(buffer, offset, count);
|
||||||
|
return base.BeginRead(buffer, offset, count, callback, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int EndRead(IAsyncResult asyncResult)
|
||||||
|
{
|
||||||
|
// return ((Task<int>)asyncResult).Result;
|
||||||
|
return base.EndRead(asyncResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (_terminated)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
VerifyBuffer(buffer, offset, count, allowEmpty: false);
|
||||||
|
var registration = cancellationToken.Register(Abort);
|
||||||
|
await _readLock.WaitAsync(cancellationToken);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int totalRead = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
// Don't drained buffered data on abort.
|
||||||
|
CheckAborted();
|
||||||
|
if (_topBuffer.Count <= 0)
|
||||||
|
{
|
||||||
|
byte[] topBuffer = null;
|
||||||
|
while (!_bufferedData.TryDequeue(out topBuffer))
|
||||||
|
{
|
||||||
|
if (_disposed)
|
||||||
|
{
|
||||||
|
CheckAborted();
|
||||||
|
// Graceful close
|
||||||
|
return totalRead;
|
||||||
|
}
|
||||||
|
await WaitForDataAsync();
|
||||||
|
}
|
||||||
|
_topBuffer = new ArraySegment<byte>(topBuffer);
|
||||||
|
}
|
||||||
|
var actualCount = Math.Min(count, _topBuffer.Count);
|
||||||
|
Buffer.BlockCopy(_topBuffer.Array, _topBuffer.Offset, buffer, offset, actualCount);
|
||||||
|
_topBuffer = new ArraySegment<byte>(_topBuffer.Array,
|
||||||
|
_topBuffer.Offset + actualCount,
|
||||||
|
_topBuffer.Count - actualCount);
|
||||||
|
totalRead += actualCount;
|
||||||
|
offset += actualCount;
|
||||||
|
count -= actualCount;
|
||||||
|
}
|
||||||
|
while (count > 0 && (_topBuffer.Count > 0 || _bufferedData.Count > 0));
|
||||||
|
// Keep reading while there is more data available and we have more space to put it in.
|
||||||
|
return totalRead;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
registration.Dispose();
|
||||||
|
_readLock.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Write with count 0 will still trigger OnFirstWrite
|
// Write with count 0 will still trigger OnFirstWrite
|
||||||
public override void Write(byte[] buffer, int offset, int count)
|
public override void Write(byte[] buffer, int offset, int count)
|
||||||
{
|
{
|
||||||
|
|
@ -166,7 +231,7 @@ namespace Microsoft.AspNetCore.WebSockets.Test
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Copies are necessary because we don't know what the caller is going to do with the buffer afterwards.
|
// Copies are necessary because we don't know what the caller is going to do with the buffer afterwards.
|
||||||
byte[] internalBuffer = new byte[count];
|
var internalBuffer = new byte[count];
|
||||||
Buffer.BlockCopy(buffer, offset, internalBuffer, 0, count);
|
Buffer.BlockCopy(buffer, offset, internalBuffer, 0, count);
|
||||||
_bufferedData.Enqueue(internalBuffer);
|
_bufferedData.Enqueue(internalBuffer);
|
||||||
|
|
||||||
|
|
@ -178,6 +243,35 @@ namespace Microsoft.AspNetCore.WebSockets.Test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
|
||||||
|
{
|
||||||
|
Write(buffer, offset, count);
|
||||||
|
var tcs = new TaskCompletionSource<object>(state);
|
||||||
|
tcs.TrySetResult(null);
|
||||||
|
var result = tcs.Task;
|
||||||
|
if (callback != null)
|
||||||
|
{
|
||||||
|
callback(result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void EndWrite(IAsyncResult asyncResult) { }
|
||||||
|
|
||||||
|
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
VerifyBuffer(buffer, offset, count, allowEmpty: true);
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
var tcs = new TaskCompletionSource<object>();
|
||||||
|
tcs.TrySetCanceled();
|
||||||
|
return tcs.Task;
|
||||||
|
}
|
||||||
|
|
||||||
|
Write(buffer, offset, count);
|
||||||
|
return Task.FromResult<object>(null);
|
||||||
|
}
|
||||||
|
|
||||||
private static void VerifyBuffer(byte[] buffer, int offset, int count, bool allowEmpty)
|
private static void VerifyBuffer(byte[] buffer, int offset, int count, bool allowEmpty)
|
||||||
{
|
{
|
||||||
if (offset < 0 || offset > buffer.Length)
|
if (offset < 0 || offset > buffer.Length)
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,31 @@ namespace Microsoft.AspNetCore.WebSockets.Test
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override int ReadByte()
|
||||||
|
{
|
||||||
|
return ReadStream.ReadByte();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
|
||||||
|
{
|
||||||
|
return ReadStream.BeginRead(buffer, offset, count, callback, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int EndRead(IAsyncResult asyncResult)
|
||||||
|
{
|
||||||
|
return ReadStream.EndRead(asyncResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return ReadStream.ReadAsync(buffer, offset, count, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return ReadStream.CopyToAsync(destination, bufferSize, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
#region Read
|
#region Read
|
||||||
|
|
||||||
public override int Read(byte[] buffer, int offset, int count)
|
public override int Read(byte[] buffer, int offset, int count)
|
||||||
|
|
@ -102,6 +127,30 @@ namespace Microsoft.AspNetCore.WebSockets.Test
|
||||||
{
|
{
|
||||||
WriteStream.Write(buffer, offset, count);
|
WriteStream.Write(buffer, offset, count);
|
||||||
}
|
}
|
||||||
|
public override void WriteByte(byte value)
|
||||||
|
{
|
||||||
|
WriteStream.WriteByte(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
|
||||||
|
{
|
||||||
|
return WriteStream.BeginWrite(buffer, offset, count, callback, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void EndWrite(IAsyncResult asyncResult)
|
||||||
|
{
|
||||||
|
WriteStream.EndWrite(asyncResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return WriteStream.WriteAsync(buffer, offset, count, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Task FlushAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return WriteStream.FlushAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
public override void Flush()
|
public override void Flush()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,8 @@
|
||||||
<Import Project="..\..\build\common.props" />
|
<Import Project="..\..\build\common.props" />
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
|
||||||
|
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
|
||||||
<!--
|
|
||||||
Workaround for "Explicit RID still required for .NET Framework test projects" (https://github.com/dotnet/sdk/issues/909).
|
|
||||||
Remove when fixed.
|
|
||||||
-->
|
|
||||||
<OutputType>exe</OutputType>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue