-
Notifications
You must be signed in to change notification settings - Fork 5.3k
WebSocket Feedback Follow-up #107662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
WebSocket Feedback Follow-up #107662
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
671972d
Fixes
CarnaViire 9957769
State validation update
CarnaViire ce11844
Roll back dispose changes, fix mutex logging
CarnaViire 290a0a0
Roll back observe changes
CarnaViire bbda9af
Add internal flags enum for states
CarnaViire 076b887
Update src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/…
CarnaViire 07acff1
Feedback
CarnaViire cf0e77e
Merge remote-tracking branch 'upstream/main' into ws-feedback
CarnaViire e23514d
Merge remote-tracking branch 'refs/remotes/origin/ws-feedback' into w…
CarnaViire File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/ManagedWebSocketStates.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace System.Net.WebSockets | ||
| { | ||
| [Flags] | ||
| internal enum ManagedWebSocketStates | ||
| { | ||
| None = 0, | ||
|
|
||
| // WebSocketState.None = 0 -- this state is invalid for the managed implementation | ||
| // WebSocketState.Connecting = 1 -- this state is invalid for the managed implementation | ||
| Open = 0x04, // WebSocketState.Open = 2 | ||
| CloseSent = 0x08, // WebSocketState.CloseSent = 3 | ||
| CloseReceived = 0x10, // WebSocketState.CloseReceived = 4 | ||
| Closed = 0x20, // WebSocketState.Closed = 5 | ||
| Aborted = 0x40, // WebSocketState.Aborted = 6 | ||
|
|
||
| All = Open | CloseSent | CloseReceived | Closed | Aborted | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/WebSocketStateHelper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // 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; | ||
|
|
||
| namespace System.Net.WebSockets | ||
| { | ||
| internal static class WebSocketStateHelper | ||
| { | ||
| /// <summary>Valid states to be in when calling SendAsync.</summary> | ||
| internal const ManagedWebSocketStates ValidSendStates = ManagedWebSocketStates.Open | ManagedWebSocketStates.CloseReceived; | ||
| /// <summary>Valid states to be in when calling ReceiveAsync.</summary> | ||
| internal const ManagedWebSocketStates ValidReceiveStates = ManagedWebSocketStates.Open | ManagedWebSocketStates.CloseSent; | ||
| /// <summary>Valid states to be in when calling CloseOutputAsync.</summary> | ||
| internal const ManagedWebSocketStates ValidCloseOutputStates = ManagedWebSocketStates.Open | ManagedWebSocketStates.CloseReceived; | ||
| /// <summary>Valid states to be in when calling CloseAsync.</summary> | ||
| internal const ManagedWebSocketStates ValidCloseStates = ManagedWebSocketStates.Open | ManagedWebSocketStates.CloseReceived | ManagedWebSocketStates.CloseSent; | ||
|
|
||
| internal static bool IsValidSendState(WebSocketState state) => ValidSendStates.HasFlag(ToFlag(state)); | ||
|
|
||
| internal static void ThrowIfInvalidState(WebSocketState currentState, bool isDisposed, Exception? innerException, ManagedWebSocketStates validStates) | ||
| { | ||
| ManagedWebSocketStates state = ToFlag(currentState); | ||
|
|
||
| if ((state & validStates) == 0) | ||
| { | ||
| string invalidStateMessage = SR.Format( | ||
| SR.net_WebSockets_InvalidState, currentState, validStates); | ||
|
|
||
| throw new WebSocketException(WebSocketError.InvalidState, invalidStateMessage, innerException); | ||
| } | ||
|
|
||
| if (innerException is not null) | ||
| { | ||
| Debug.Assert(state == ManagedWebSocketStates.Aborted); | ||
| throw new OperationCanceledException(nameof(WebSocketState.Aborted), innerException); | ||
| } | ||
|
|
||
| // Ordering is important to maintain .NET 4.5 WebSocket implementation exception behavior. | ||
| ObjectDisposedException.ThrowIf(isDisposed, typeof(WebSocket)); | ||
| } | ||
|
|
||
| private static ManagedWebSocketStates ToFlag(WebSocketState value) | ||
| { | ||
| ManagedWebSocketStates flag = (ManagedWebSocketStates)(1 << (int)value); | ||
| Debug.Assert(Enum.IsDefined(flag)); | ||
| return flag; | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.