Skip to content

Commit

Permalink
More tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
drasticactions committed Jan 19, 2025
1 parent 925c4ed commit 539edaa
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/FishyFlip/ATWebSocketProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private void Dispose(bool disposing)
{
if (disposing)
{
// this.webSocketWrapper.DisposeAsync();
this.webSocketWrapper.DisposeAsync().GetAwaiter().GetResult();
}

this.disposedValue = true;
Expand Down Expand Up @@ -281,7 +281,13 @@ void HandleProgressStatus(CarProgressStatusEvent e)
private Task OnMessageReceived(ReadOnlySequence<byte> message)
{
var newMessage = message.ToArray();
Task.Run(() => this.HandleMessage(newMessage)).FireAndForgetSafeAsync(this.logger);
Task.Run(() =>
{
if (this.IsConnected)
{
this.HandleMessage(newMessage);
}
}).FireAndForgetSafeAsync(this.logger);
return Task.CompletedTask;
}

Expand Down Expand Up @@ -323,6 +329,11 @@ public async Task ConnectAsync(Uri uri, CancellationToken cancellationToken = de

public async Task CloseAsync(CancellationToken cancellationToken = default)
{
if (this.webSocket.State == WebSocketState.Closed || this.webSocket.State == WebSocketState.Aborted)
{
return;
}

this.logger?.LogInformation("WSS: Closing WebSocket connection.");
await this.webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Closing", cancellationToken);
}
Expand Down Expand Up @@ -351,7 +362,7 @@ private async Task StartReceiveLoop()
{
try
{
while (!this.cts.Token.IsCancellationRequested && this.webSocket.State == WebSocketState.Open)
while (!this.cts.Token.IsCancellationRequested || this.webSocket.State == WebSocketState.Open)
{
var memory = this.pipe.Writer.GetMemory(8192);
#if NETSTANDARD
Expand Down

0 comments on commit 539edaa

Please sign in to comment.