Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/libraries/System.Net.WebSockets.Client/tests/CloseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ public async Task CloseOutputAsync_ClientInitiated_CanReceive_CanClose(Uri serve

[ActiveIssue("https://github.com/dotnet/runtime/issues/28957", typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))]
[OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
public async Task CloseOutputAsync_ServerInitiated_CanReceive(Uri server)
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServersWithSwitch))]
public async Task CloseOutputAsync_ServerInitiated_CanReceive(Uri server, bool delayReceiving)
{
var expectedCloseStatus = WebSocketCloseStatus.NormalClosure;
var expectedCloseDescription = ".shutdownafter";
Expand All @@ -280,6 +280,10 @@ await cws.SendAsync(
true,
cts.Token);

// let server close the output before we request receiving
if (delayReceiving)
await Task.Delay(1000);

// Should be able to receive the message echoed by the server.
var recvBuffer = new byte[100];
var segmentRecv = new ArraySegment<byte>(recvBuffer);
Expand Down Expand Up @@ -363,15 +367,15 @@ await cws.SendAsync(
}
}

public static IEnumerable<object[]> EchoServersSyncState =>
public static IEnumerable<object[]> EchoServersWithSwitch =>
EchoServers.SelectMany(server => new List<object[]>
{
new object[] { server[0], true },
new object[] { server[0], false }
});

[ActiveIssue("https://github.com/dotnet/runtime/issues/28957", typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServersSyncState))]
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServersWithSwitch))]
public async Task CloseOutputAsync_ServerInitiated_CanReceiveAfterClose(Uri server, bool syncState)
{
using (ClientWebSocket cws = await GetConnectedWebSocket(server, TimeOutMilliseconds, _output))
Expand Down
5 changes: 2 additions & 3 deletions src/mono/browser/runtime/web-socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function verifyEnvironment () {
}
}

export function ws_get_state (ws: WebSocketExtension) : number {
export function ws_get_state (ws: WebSocketExtension): number {
if (ws.readyState != WebSocket.CLOSED)
return ws.readyState ?? -1;
const receive_event_queue = ws[wasm_ws_pending_receive_event_queue];
Expand Down Expand Up @@ -228,8 +228,7 @@ export function ws_wasm_receive (ws: WebSocketExtension, buffer_ptr: VoidPtr, bu
return resolvedPromise();
}

const readyState = ws.readyState;
if (readyState == WebSocket.CLOSED) {
if (ws[wasm_ws_close_received]) {
const receive_status_ptr = ws[wasm_ws_receive_status_ptr];
setI32(receive_status_ptr, 0); // count
setI32(<any>receive_status_ptr + 4, 2); // type:close
Expand Down