diff --git a/src/libraries/System.Net.WebSockets.WebSocketProtocol/Directory.Build.props b/src/libraries/System.Net.WebSockets.WebSocketProtocol/Directory.Build.props deleted file mode 100644 index d5b50038e363bd..00000000000000 --- a/src/libraries/System.Net.WebSockets.WebSocketProtocol/Directory.Build.props +++ /dev/null @@ -1,11 +0,0 @@ - - - - Open - true - Provides the WebSocketProtocol class, which allows creating a websocket from a connected stream using WebSocketsProtocol.CreateFromConnectedStream. - -Commonly Used Types: -System.Net.WebSockets.WebSocketProtocol - - \ No newline at end of file diff --git a/src/libraries/System.Net.WebSockets.WebSocketProtocol/System.Net.WebSockets.WebSocketProtocol.sln b/src/libraries/System.Net.WebSockets.WebSocketProtocol/System.Net.WebSockets.WebSocketProtocol.sln deleted file mode 100644 index 0a4115b62628b0..00000000000000 --- a/src/libraries/System.Net.WebSockets.WebSocketProtocol/System.Net.WebSockets.WebSocketProtocol.sln +++ /dev/null @@ -1,86 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtilities", "..\Common\tests\TestUtilities\TestUtilities.csproj", "{B6EF5109-6DE6-4CE3-879D-060AA8698540}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Win32.Registry", "..\Microsoft.Win32.Registry\ref\Microsoft.Win32.Registry.csproj", "{BFA2FE9A-920B-4A51-B6A7-571FCE6FF542}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Net.WebSockets.WebSocketProtocol", "ref\System.Net.WebSockets.WebSocketProtocol.csproj", "{753243E4-C9B5-4E5C-8FBA-1211B63C435A}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Net.WebSockets.WebSocketProtocol", "src\System.Net.WebSockets.WebSocketProtocol.csproj", "{F9419A4B-8CBA-4609-BC2A-8596087CD3B0}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Net.WebSockets.WebSocketProtocol.Tests", "tests\System.Net.WebSockets.WebSocketProtocol.Tests.csproj", "{EA24382F-2448-4217-8682-E213A6EF868F}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.CompilerServices.Unsafe", "..\System.Runtime.CompilerServices.Unsafe\ref\System.Runtime.CompilerServices.Unsafe.csproj", "{ABE7DC67-F098-409C-B28C-A59CBEE888F3}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.CompilerServices.Unsafe", "..\System.Runtime.CompilerServices.Unsafe\src\System.Runtime.CompilerServices.Unsafe.ilproj", "{D6B4EB67-A972-4252-9F8C-C53FA38730E6}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Security.AccessControl", "..\System.Security.AccessControl\ref\System.Security.AccessControl.csproj", "{FE98CB0A-9BF7-4FBF-A792-9F89F532CE43}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Security.Principal.Windows", "..\System.Security.Principal.Windows\ref\System.Security.Principal.Windows.csproj", "{22F639F5-413A-41A2-A66D-E8E6876C007C}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{CBA116A5-3B17-4ED8-9F82-E3E1A36E0424}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{7825E342-AA06-40BC-89BD-BBC88DD3C2FE}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{CBD1A8B6-B9E0-4D3D-9DEC-D95B022A8C23}" -EndProject -Global - GlobalSection(NestedProjects) = preSolution - {B6EF5109-6DE6-4CE3-879D-060AA8698540} = {CBA116A5-3B17-4ED8-9F82-E3E1A36E0424} - {EA24382F-2448-4217-8682-E213A6EF868F} = {CBA116A5-3B17-4ED8-9F82-E3E1A36E0424} - {BFA2FE9A-920B-4A51-B6A7-571FCE6FF542} = {7825E342-AA06-40BC-89BD-BBC88DD3C2FE} - {753243E4-C9B5-4E5C-8FBA-1211B63C435A} = {7825E342-AA06-40BC-89BD-BBC88DD3C2FE} - {ABE7DC67-F098-409C-B28C-A59CBEE888F3} = {7825E342-AA06-40BC-89BD-BBC88DD3C2FE} - {FE98CB0A-9BF7-4FBF-A792-9F89F532CE43} = {7825E342-AA06-40BC-89BD-BBC88DD3C2FE} - {22F639F5-413A-41A2-A66D-E8E6876C007C} = {7825E342-AA06-40BC-89BD-BBC88DD3C2FE} - {F9419A4B-8CBA-4609-BC2A-8596087CD3B0} = {CBD1A8B6-B9E0-4D3D-9DEC-D95B022A8C23} - {D6B4EB67-A972-4252-9F8C-C53FA38730E6} = {CBD1A8B6-B9E0-4D3D-9DEC-D95B022A8C23} - EndGlobalSection - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B6EF5109-6DE6-4CE3-879D-060AA8698540}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B6EF5109-6DE6-4CE3-879D-060AA8698540}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B6EF5109-6DE6-4CE3-879D-060AA8698540}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B6EF5109-6DE6-4CE3-879D-060AA8698540}.Release|Any CPU.Build.0 = Release|Any CPU - {BFA2FE9A-920B-4A51-B6A7-571FCE6FF542}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BFA2FE9A-920B-4A51-B6A7-571FCE6FF542}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BFA2FE9A-920B-4A51-B6A7-571FCE6FF542}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BFA2FE9A-920B-4A51-B6A7-571FCE6FF542}.Release|Any CPU.Build.0 = Release|Any CPU - {753243E4-C9B5-4E5C-8FBA-1211B63C435A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {753243E4-C9B5-4E5C-8FBA-1211B63C435A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {753243E4-C9B5-4E5C-8FBA-1211B63C435A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {753243E4-C9B5-4E5C-8FBA-1211B63C435A}.Release|Any CPU.Build.0 = Release|Any CPU - {F9419A4B-8CBA-4609-BC2A-8596087CD3B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F9419A4B-8CBA-4609-BC2A-8596087CD3B0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F9419A4B-8CBA-4609-BC2A-8596087CD3B0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F9419A4B-8CBA-4609-BC2A-8596087CD3B0}.Release|Any CPU.Build.0 = Release|Any CPU - {EA24382F-2448-4217-8682-E213A6EF868F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EA24382F-2448-4217-8682-E213A6EF868F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EA24382F-2448-4217-8682-E213A6EF868F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EA24382F-2448-4217-8682-E213A6EF868F}.Release|Any CPU.Build.0 = Release|Any CPU - {ABE7DC67-F098-409C-B28C-A59CBEE888F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ABE7DC67-F098-409C-B28C-A59CBEE888F3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {ABE7DC67-F098-409C-B28C-A59CBEE888F3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ABE7DC67-F098-409C-B28C-A59CBEE888F3}.Release|Any CPU.Build.0 = Release|Any CPU - {D6B4EB67-A972-4252-9F8C-C53FA38730E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D6B4EB67-A972-4252-9F8C-C53FA38730E6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D6B4EB67-A972-4252-9F8C-C53FA38730E6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D6B4EB67-A972-4252-9F8C-C53FA38730E6}.Release|Any CPU.Build.0 = Release|Any CPU - {FE98CB0A-9BF7-4FBF-A792-9F89F532CE43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FE98CB0A-9BF7-4FBF-A792-9F89F532CE43}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FE98CB0A-9BF7-4FBF-A792-9F89F532CE43}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FE98CB0A-9BF7-4FBF-A792-9F89F532CE43}.Release|Any CPU.Build.0 = Release|Any CPU - {22F639F5-413A-41A2-A66D-E8E6876C007C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {22F639F5-413A-41A2-A66D-E8E6876C007C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {22F639F5-413A-41A2-A66D-E8E6876C007C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {22F639F5-413A-41A2-A66D-E8E6876C007C}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {BC6A06B6-892F-402D-80A3-24138262A1A2} - EndGlobalSection -EndGlobal diff --git a/src/libraries/System.Net.WebSockets.WebSocketProtocol/pkg/System.Net.WebSockets.WebSocketProtocol.pkgproj b/src/libraries/System.Net.WebSockets.WebSocketProtocol/pkg/System.Net.WebSockets.WebSocketProtocol.pkgproj deleted file mode 100644 index e5902d27282209..00000000000000 --- a/src/libraries/System.Net.WebSockets.WebSocketProtocol/pkg/System.Net.WebSockets.WebSocketProtocol.pkgproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - - uap10.0.16299;net461;netcoreapp2.0;$(AllXamarinFrameworks) - - - - \ No newline at end of file diff --git a/src/libraries/System.Net.WebSockets.WebSocketProtocol/ref/System.Net.WebSockets.WebSocketProtocol.cs b/src/libraries/System.Net.WebSockets.WebSocketProtocol/ref/System.Net.WebSockets.WebSocketProtocol.cs deleted file mode 100644 index 295705fdf90acb..00000000000000 --- a/src/libraries/System.Net.WebSockets.WebSocketProtocol/ref/System.Net.WebSockets.WebSocketProtocol.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// ------------------------------------------------------------------------------ -// Changes to this file must follow the https://aka.ms/api-review process. -// ------------------------------------------------------------------------------ - -namespace System.Net.WebSockets -{ - [System.Runtime.Versioning.UnsupportedOSPlatform("browser")] - public static partial class WebSocketProtocol - { - public static System.Net.WebSockets.WebSocket CreateFromStream(System.IO.Stream stream, bool isServer, string? subProtocol, System.TimeSpan keepAliveInterval) { throw null; } - } -} diff --git a/src/libraries/System.Net.WebSockets.WebSocketProtocol/ref/System.Net.WebSockets.WebSocketProtocol.csproj b/src/libraries/System.Net.WebSockets.WebSocketProtocol/ref/System.Net.WebSockets.WebSocketProtocol.csproj deleted file mode 100644 index 7a11f13532cd39..00000000000000 --- a/src/libraries/System.Net.WebSockets.WebSocketProtocol/ref/System.Net.WebSockets.WebSocketProtocol.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - netstandard2.0;net461 - enable - - - - - - - - \ No newline at end of file diff --git a/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/Resources/Strings.resx b/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/Resources/Strings.resx deleted file mode 100644 index 1c8cf89eca5a30..00000000000000 --- a/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/Resources/Strings.resx +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Empty string is not a valid subprotocol value. Please use \"null\" to specify no value. - - - The WebSocket is in an invalid state ('{0}') for this operation. Valid states are: '{1}' - - - The WebSocket protocol '{0}' is invalid because it contains the invalid character '{1}'. - - - The close status description '{0}' is invalid. When using close status code '{1}' the description must be null. - - - The close status code '{0}' is reserved for system use only and cannot be specified when calling this method. - - - The close status description '{0}' is too long. The UTF8-representation of the status description must not be longer than {1} bytes. - - - The WebSocket protocol is not supported on this platform. - - - The message type '{0}' is not allowed for the '{1}' operation. Valid message types are: '{2}, {3}'. To close the WebSocket, use the '{4}' operation instead. - - - There is already one outstanding '{0}' call for this WebSocket instance. ReceiveAsync and SendAsync can be called simultaneously, but at most one outstanding operation for each of them is allowed at the same time. - - - The base stream is not readable. - - - The base stream is not writeable. - - - The argument must be a value greater than {0}. - - - The WebSocket received a frame with one or more reserved bits set. - - - The WebSocket server sent a masked frame. - - - The WebSocket received a continuation frame from a previous final message. - - - The WebSocket expected a continuation frame after having received a previous non-final frame. - - - The WebSocket received an invalid control message. - - - The WebSocket received a frame with an unknown opcode: '0x{0}'. - - diff --git a/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System.Net.WebSockets.WebSocketProtocol.csproj b/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System.Net.WebSockets.WebSocketProtocol.csproj deleted file mode 100644 index 32376f71db93db..00000000000000 --- a/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System.Net.WebSockets.WebSocketProtocol.csproj +++ /dev/null @@ -1,49 +0,0 @@ - - - True - $(NetCoreAppCurrent);netstandard2.0;netcoreapp2.1;net461 - true - enable - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Net/WebSockets/ManagedWebSocket.netstandard.cs b/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Net/WebSockets/ManagedWebSocket.netstandard.cs deleted file mode 100644 index 6d197afa68e900..00000000000000 --- a/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Net/WebSockets/ManagedWebSocket.netstandard.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Threading; -using System.Threading.Tasks; - -namespace System.Net.WebSockets -{ - internal sealed partial class ManagedWebSocket : WebSocket - { - private Task ValidateAndReceiveAsync(Task receiveTask, byte[] buffer, CancellationToken cancellationToken) - { - if (receiveTask == null || - (receiveTask.Status == TaskStatus.RanToCompletion && - !(receiveTask is Task wsrr && wsrr.Result.MessageType == WebSocketMessageType.Close))) - { - receiveTask = ReceiveAsyncPrivate(new ArraySegment(buffer), cancellationToken).AsTask(); - } - - return receiveTask; - } - } -} diff --git a/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Net/WebSockets/ManagedWebSocketExtensions.cs b/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Net/WebSockets/ManagedWebSocketExtensions.cs deleted file mode 100644 index 60a9f72d755ff3..00000000000000 --- a/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Net/WebSockets/ManagedWebSocketExtensions.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Threading; - -namespace System.Net.WebSockets -{ - internal static partial class ManagedWebSocketExtensions - { - internal static CancellationTokenRegistration UnsafeRegister(this CancellationToken cancellationToken, Action callback, object? state) => - cancellationToken.Register(callback, state); - } -} diff --git a/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Net/WebSockets/ManagedWebSocketExtensions.netstandard.cs b/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Net/WebSockets/ManagedWebSocketExtensions.netstandard.cs deleted file mode 100644 index d4d9cdd6467ca9..00000000000000 --- a/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Net/WebSockets/ManagedWebSocketExtensions.netstandard.cs +++ /dev/null @@ -1,87 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Buffers; -using System.Diagnostics; -using System.IO; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace System.Net.WebSockets -{ - internal static partial class ManagedWebSocketExtensions - { - internal static unsafe string GetString(this UTF8Encoding encoding, Span bytes) - { - fixed (byte* b = &MemoryMarshal.GetReference(bytes)) - { - return encoding.GetString(b, bytes.Length); - } - } - - internal static ValueTask ReadAsync(this Stream stream, Memory destination, CancellationToken cancellationToken = default) - { - if (MemoryMarshal.TryGetArray(destination, out ArraySegment array)) - { - return new ValueTask(stream.ReadAsync(array.Array, array.Offset, array.Count, cancellationToken)); - } - else - { - byte[] buffer = ArrayPool.Shared.Rent(destination.Length); - return new ValueTask(FinishReadAsync(stream.ReadAsync(buffer, 0, destination.Length, cancellationToken), buffer, destination)); - - static async Task FinishReadAsync(Task readTask, byte[] localBuffer, Memory localDestination) - { - try - { - int result = await readTask.ConfigureAwait(false); - new Span(localBuffer, 0, result).CopyTo(localDestination.Span); - return result; - } - finally - { - ArrayPool.Shared.Return(localBuffer); - } - } - } - } - - internal static ValueTask WriteAsync(this Stream stream, ReadOnlyMemory source, CancellationToken cancellationToken = default) - { - if (MemoryMarshal.TryGetArray(source, out ArraySegment array)) - { - return new ValueTask(stream.WriteAsync(array.Array, array.Offset, array.Count, cancellationToken)); - } - else - { - byte[] buffer = ArrayPool.Shared.Rent(source.Length); - source.Span.CopyTo(buffer); - return new ValueTask(FinishWriteAsync(stream.WriteAsync(buffer, 0, source.Length, cancellationToken), buffer)); - - static async Task FinishWriteAsync(Task writeTask, byte[] localBuffer) - { - try - { - await writeTask.ConfigureAwait(false); - } - finally - { - ArrayPool.Shared.Return(localBuffer); - } - } - } - } - } - - internal static class BitConverter - { - internal static unsafe int ToInt32(ReadOnlySpan value) - { - Debug.Assert(value.Length >= sizeof(int)); - return Unsafe.ReadUnaligned(ref MemoryMarshal.GetReference(value)); - } - } -} diff --git a/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Net/WebSockets/WebSocketProtocol.cs b/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Net/WebSockets/WebSocketProtocol.cs deleted file mode 100644 index 1178e70d760c1a..00000000000000 --- a/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Net/WebSockets/WebSocketProtocol.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.IO; -using System.Runtime.Versioning; -using System.Threading; - -namespace System.Net.WebSockets -{ - [UnsupportedOSPlatform("browser")] - public static class WebSocketProtocol - { - public static WebSocket CreateFromStream( - Stream stream, - bool isServer, - string? subProtocol, - TimeSpan keepAliveInterval) - { - if (stream == null) - { - throw new ArgumentNullException(nameof(stream)); - } - - if (!stream.CanRead || !stream.CanWrite) - { - throw new ArgumentException(!stream.CanRead ? SR.NotReadableStream : SR.NotWriteableStream, nameof(stream)); - } - - if (subProtocol != null) - { - WebSocketValidate.ValidateSubprotocol(subProtocol); - } - - if (keepAliveInterval != Timeout.InfiniteTimeSpan && keepAliveInterval < TimeSpan.Zero) - { - throw new ArgumentOutOfRangeException(nameof(keepAliveInterval), keepAliveInterval, - SR.Format(SR.net_WebSockets_ArgumentOutOfRange_TooSmall, - 0)); - } - - return ManagedWebSocket.CreateFromConnectedStream(stream, isServer, subProtocol, keepAliveInterval); - } - } -} diff --git a/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Numerics/BitOperations.cs b/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Numerics/BitOperations.cs deleted file mode 100644 index f9f3c33ef0e7b3..00000000000000 --- a/src/libraries/System.Net.WebSockets.WebSocketProtocol/src/System/Numerics/BitOperations.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Runtime.CompilerServices; - -namespace System.Numerics -{ - // NOTE: This is an edited excerpt copy from src\Common\src\CoreLib\System\Numerics\BitOperations.cs. - // It is only for use downlevel and internally by WebSocketProtocol. - - internal static class BitOperations - { - /// - /// Rotates the specified value right by the specified number of bits. - /// Similar in behavior to the x86 instruction ROR. - /// - /// The value to rotate. - /// The number of bits to rotate by. - /// Any value outside the range [0..31] is treated as congruent mod 32. - /// The rotated value. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint RotateRight(uint value, int offset) => - (value >> offset) | (value << (32 - offset)); - } -} diff --git a/src/libraries/System.Net.WebSockets.WebSocketProtocol/tests/System.Net.WebSockets.WebSocketProtocol.Tests.csproj b/src/libraries/System.Net.WebSockets.WebSocketProtocol/tests/System.Net.WebSockets.WebSocketProtocol.Tests.csproj deleted file mode 100644 index 16b078941bfc88..00000000000000 --- a/src/libraries/System.Net.WebSockets.WebSocketProtocol/tests/System.Net.WebSockets.WebSocketProtocol.Tests.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - $(NetCoreAppCurrent);net48 - - - - - - - - - - - - diff --git a/src/libraries/System.Net.WebSockets.WebSocketProtocol/tests/WebSocketProtocolTests.cs b/src/libraries/System.Net.WebSockets.WebSocketProtocol/tests/WebSocketProtocolTests.cs deleted file mode 100644 index 1d8aecbda9db2f..00000000000000 --- a/src/libraries/System.Net.WebSockets.WebSocketProtocol/tests/WebSocketProtocolTests.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.IO; -using Xunit; - -namespace System.Net.WebSockets.Tests -{ - public sealed class WebSocketProtocolCreateTests : WebSocketCreateTest - { - protected override WebSocket CreateFromStream(Stream stream, bool isServer, string subProtocol, TimeSpan keepAliveInterval) => - WebSocketProtocol.CreateFromStream(stream, isServer, subProtocol, keepAliveInterval); - } -} diff --git a/src/libraries/System.Net.WebSockets/src/System.Net.WebSockets.csproj b/src/libraries/System.Net.WebSockets/src/System.Net.WebSockets.csproj index 212dea7f6eb91f..d65e6c55737af0 100644 --- a/src/libraries/System.Net.WebSockets/src/System.Net.WebSockets.csproj +++ b/src/libraries/System.Net.WebSockets/src/System.Net.WebSockets.csproj @@ -5,7 +5,6 @@ enable - @@ -15,10 +14,9 @@ + - diff --git a/src/libraries/Common/src/System/Net/WebSockets/ManagedWebSocket.cs b/src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/ManagedWebSocket.cs similarity index 95% rename from src/libraries/Common/src/System/Net/WebSockets/ManagedWebSocket.cs rename to src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/ManagedWebSocket.cs index cffafdd0c41aae..bf4888a57b0579 100644 --- a/src/libraries/Common/src/System/Net/WebSockets/ManagedWebSocket.cs +++ b/src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/ManagedWebSocket.cs @@ -53,10 +53,8 @@ public static ManagedWebSocket CreateFromConnectedStream( /// Valid states to be in when calling CloseAsync. private static readonly WebSocketState[] s_validCloseStates = { WebSocketState.Open, WebSocketState.CloseReceived, WebSocketState.CloseSent }; -#pragma warning disable CA1823 // not used by System.Net.WebSockets.WebSocketProtocol.dll /// Successfully completed task representing a close message. private static readonly Task s_cachedCloseTask = Task.FromResult(new WebSocketReceiveResult(0, WebSocketMessageType.Close, true)); -#pragma warning restore CA1823 /// The maximum size in bytes of a message frame header that includes mask bytes. internal const int MaxMessageHeaderLength = 14; @@ -359,6 +357,67 @@ public override void Abort() Dispose(); // forcibly tear down connection } + public override ValueTask SendAsync(ReadOnlyMemory buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken) + { + return SendPrivateAsync(buffer, messageType, endOfMessage, cancellationToken); + } + + public override ValueTask ReceiveAsync(Memory buffer, CancellationToken cancellationToken) + { + try + { + WebSocketValidate.ThrowIfInvalidState(_state, _disposed, s_validReceiveStates); + + Debug.Assert(!Monitor.IsEntered(StateUpdateLock), $"{nameof(StateUpdateLock)} must never be held when acquiring {nameof(ReceiveAsyncLock)}"); + lock (ReceiveAsyncLock) // synchronize with receives in CloseAsync + { + ThrowIfOperationInProgress(_lastReceiveAsync.IsCompleted); + + ValueTask receiveValueTask = ReceiveAsyncPrivate(buffer, cancellationToken); + if (receiveValueTask.IsCompletedSuccessfully) + { + _lastReceiveAsync = receiveValueTask.Result.MessageType == WebSocketMessageType.Close ? s_cachedCloseTask : Task.CompletedTask; + return receiveValueTask; + } + + // We need to both store the last receive task and return it, but we can't do that with a ValueTask, + // as that could result in consuming it multiple times. Instead, we use AsTask to consume it just once, + // and then store that Task and return a new ValueTask that wraps it. (It would be nice in the future + // to avoid this AsTask as well; currently it's used both for error detection and as part of close tracking.) + Task receiveTask = receiveValueTask.AsTask(); + _lastReceiveAsync = receiveTask; + return new ValueTask(receiveTask); + } + } + catch (Exception exc) + { + return ValueTask.FromException(exc); + } + } + + private Task ValidateAndReceiveAsync(Task receiveTask, byte[] buffer, CancellationToken cancellationToken) + { + if (receiveTask == null || + (receiveTask.IsCompletedSuccessfully && + !(receiveTask is Task wsrr && wsrr.Result.MessageType == WebSocketMessageType.Close) && + !(receiveTask is Task vwsrr && vwsrr.Result.MessageType == WebSocketMessageType.Close))) + { + ValueTask vt = ReceiveAsyncPrivate(buffer, cancellationToken); + receiveTask = + vt.IsCompletedSuccessfully ? (vt.Result.MessageType == WebSocketMessageType.Close ? s_cachedCloseTask : Task.CompletedTask) : + vt.AsTask(); + } + + return receiveTask; + } + + /// implementation for . + private readonly struct ValueWebSocketReceiveResultGetter : IWebSocketReceiveResultGetter + { + public ValueWebSocketReceiveResult GetResult(int count, WebSocketMessageType messageType, bool endOfMessage, WebSocketCloseStatus? closeStatus, string? closeDescription) => + new ValueWebSocketReceiveResult(count, messageType, endOfMessage); // closeStatus/closeDescription are ignored + } + /// Sends a websocket frame to the network. /// The opcode for the message. /// The value of the FIN bit for the message. diff --git a/src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/ManagedWebSocket.netcoreapp.cs b/src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/ManagedWebSocket.netcoreapp.cs deleted file mode 100644 index 4b222c541dcb1b..00000000000000 --- a/src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/ManagedWebSocket.netcoreapp.cs +++ /dev/null @@ -1,73 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Diagnostics; -using System.Threading; -using System.Threading.Tasks; - -namespace System.Net.WebSockets -{ - internal sealed partial class ManagedWebSocket : WebSocket - { - public override ValueTask SendAsync(ReadOnlyMemory buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken) - { - return SendPrivateAsync(buffer, messageType, endOfMessage, cancellationToken); - } - - public override ValueTask ReceiveAsync(Memory buffer, CancellationToken cancellationToken) - { - try - { - WebSocketValidate.ThrowIfInvalidState(_state, _disposed, s_validReceiveStates); - - Debug.Assert(!Monitor.IsEntered(StateUpdateLock), $"{nameof(StateUpdateLock)} must never be held when acquiring {nameof(ReceiveAsyncLock)}"); - lock (ReceiveAsyncLock) // synchronize with receives in CloseAsync - { - ThrowIfOperationInProgress(_lastReceiveAsync.IsCompleted); - - ValueTask receiveValueTask = ReceiveAsyncPrivate(buffer, cancellationToken); - if (receiveValueTask.IsCompletedSuccessfully) - { - _lastReceiveAsync = receiveValueTask.Result.MessageType == WebSocketMessageType.Close ? s_cachedCloseTask : Task.CompletedTask; - return receiveValueTask; - } - - // We need to both store the last receive task and return it, but we can't do that with a ValueTask, - // as that could result in consuming it multiple times. Instead, we use AsTask to consume it just once, - // and then store that Task and return a new ValueTask that wraps it. (It would be nice in the future - // to avoid this AsTask as well; currently it's used both for error detection and as part of close tracking.) - Task receiveTask = receiveValueTask.AsTask(); - _lastReceiveAsync = receiveTask; - return new ValueTask(receiveTask); - } - } - catch (Exception exc) - { - return ValueTask.FromException(exc); - } - } - - private Task ValidateAndReceiveAsync(Task receiveTask, byte[] buffer, CancellationToken cancellationToken) - { - if (receiveTask == null || - (receiveTask.IsCompletedSuccessfully && - !(receiveTask is Task wsrr && wsrr.Result.MessageType == WebSocketMessageType.Close) && - !(receiveTask is Task vwsrr && vwsrr.Result.MessageType == WebSocketMessageType.Close))) - { - ValueTask vt = ReceiveAsyncPrivate(buffer, cancellationToken); - receiveTask = - vt.IsCompletedSuccessfully ? (vt.Result.MessageType == WebSocketMessageType.Close ? s_cachedCloseTask : Task.CompletedTask) : - vt.AsTask(); - } - - return receiveTask; - } - - /// implementation for . - private readonly struct ValueWebSocketReceiveResultGetter : IWebSocketReceiveResultGetter - { - public ValueWebSocketReceiveResult GetResult(int count, WebSocketMessageType messageType, bool endOfMessage, WebSocketCloseStatus? closeStatus, string? closeDescription) => - new ValueWebSocketReceiveResult(count, messageType, endOfMessage); // closeStatus/closeDescription are ignored - } - } -} diff --git a/src/libraries/System.Net.WebSockets/tests/System.Net.WebSockets.Tests.csproj b/src/libraries/System.Net.WebSockets/tests/System.Net.WebSockets.Tests.csproj index be4a5cfccf8fce..7cf0328df31ca8 100644 --- a/src/libraries/System.Net.WebSockets/tests/System.Net.WebSockets.Tests.csproj +++ b/src/libraries/System.Net.WebSockets/tests/System.Net.WebSockets.Tests.csproj @@ -6,8 +6,7 @@ - + - diff --git a/src/tests/Common/scripts/crossgen2_comparison.py b/src/tests/Common/scripts/crossgen2_comparison.py index df87eb750585f8..fbd5261f2e897b 100644 --- a/src/tests/Common/scripts/crossgen2_comparison.py +++ b/src/tests/Common/scripts/crossgen2_comparison.py @@ -400,7 +400,6 @@ def run_to_completion(self, async_callback, *extra_args): 'System.Net.WebProxy.dll', 'System.Net.WebSockets.Client.dll', 'System.Net.WebSockets.dll', - 'System.Net.WebSockets.WebSocketProtocol.dll', 'System.Numerics.dll', 'System.Numerics.Tensors.dll', 'System.Numerics.Vectors.dll',