From 6522926c2232123794ad7a343e3a25db5cfcfadd Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 2 Sep 2016 15:33:10 -0700 Subject: [PATCH] Port WebSocket fix from https://github.com/dotnet/corefx/pull/11348 --- .../System/Net/WebSockets/ManagedWebSocket.cs | 16 +++++----------- src/Microsoft.Net.Http.Server/project.json | 4 +--- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.Net.Http.Server/fx/src/System.Net.WebSockets.Client/src/System/Net/WebSockets/ManagedWebSocket.cs b/src/Microsoft.Net.Http.Server/fx/src/System.Net.WebSockets.Client/src/System/Net/WebSockets/ManagedWebSocket.cs index 738b0a7348..8253aebde5 100644 --- a/src/Microsoft.Net.Http.Server/fx/src/System.Net.WebSockets.Client/src/System/Net/WebSockets/ManagedWebSocket.cs +++ b/src/Microsoft.Net.Http.Server/fx/src/System.Net.WebSockets.Client/src/System/Net/WebSockets/ManagedWebSocket.cs @@ -30,7 +30,6 @@ namespace System.Net.WebSockets /// The connected Stream. /// true if this is the server-side of the connection; false if this is the client-side of the connection. /// The agreed upon subprotocol for the connection. - /// The current state of the websocket connection. /// The interval to use for keep-alive pings. /// The buffer size to use for received data. /// The created instance. @@ -616,12 +615,7 @@ namespace System.Net.WebSockets // Make sure we have the first two bytes, which includes the start of the payload length. if (_receiveBufferCount < 2) { - await EnsureBufferContainsAsync(2, cancellationToken, throwOnPrematureClosure: false).ConfigureAwait(false); - if (_receiveBufferCount < 2) - { - // The connection closed; nothing more to read. - return new WebSocketReceiveResult(0, WebSocketMessageType.Text, true); - } + await EnsureBufferContainsAsync(2, cancellationToken, throwOnPrematureClosure: true).ConfigureAwait(false); } // Then make sure we have the full header based on the payload length. @@ -877,7 +871,7 @@ namespace System.Net.WebSockets } /// Parses a message header from the buffer. This assumes the header is in the buffer. - /// The read header. + /// The read header. /// true if a header was read; false if the header was invalid. private bool TryParseMessageHeaderFromReceiveBuffer(out MessageHeader resultHeader) { @@ -1035,7 +1029,7 @@ namespace System.Net.WebSockets /// Sends a close message to the server. /// The close status to send. - /// The close status description to send. + /// The close status description to send. /// The CancellationToken to use to cancel the websocket. private async Task SendCloseFrameAsync(WebSocketCloseStatus closeStatus, string closeStatusDescription, CancellationToken cancellationToken) { @@ -1151,9 +1145,9 @@ namespace System.Net.WebSockets /// The buffer to which the mask should be applied. /// The offset into at which the mask should start to be applied. /// The four-byte mask, stored as an Int32. - /// The index into the mas + /// The index into the mask. /// The number of bytes to mask. - /// + /// The next index into the mask to be used for future applications of the mask. private static unsafe int ApplyMask(byte[] toMask, int toMaskOffset, int mask, int maskIndex, long count) { Debug.Assert(toMaskOffset <= toMask.Length - count, $"Unexpected inputs: {toMaskOffset}, {toMask.Length}, {count}"); diff --git a/src/Microsoft.Net.Http.Server/project.json b/src/Microsoft.Net.Http.Server/project.json index e23549b60d..c7083374f7 100644 --- a/src/Microsoft.Net.Http.Server/project.json +++ b/src/Microsoft.Net.Http.Server/project.json @@ -10,9 +10,7 @@ "warningsAsErrors": true, "keyFile": "../../tools/Key.snk", "nowarn": [ - "CS1591", - "CS1572", - "CS1573" + "CS1591" ], "xmlDoc": true },