Add extension to recycle websockets (#50)

Signed-off-by: Macocian Alexandru Victor <amacocian@yahoo.com>
This commit is contained in:
2023-05-15 11:21:29 +02:00
committed by GitHub
parent 0de73a967b
commit fe049d4c00
3 changed files with 10 additions and 2 deletions
@@ -9,7 +9,7 @@ namespace System.Net.WebSockets;
public sealed class ClientWebSocket<TScope> : IClientWebSocket<TScope>, IDisposable
{
private readonly ILogger<TScope>? logger;
private readonly ClientWebSocket internalWebSocket = new();
private ClientWebSocket internalWebSocket = new();
public ClientWebSocketOptions Options => this.internalWebSocket.Options;
@@ -89,4 +89,10 @@ public sealed class ClientWebSocket<TScope> : IClientWebSocket<TScope>, IDisposa
scopedLogger?.LogDebug($"Type: {messageType}\nCount: {buffer.Count}\nEndOfMessage: {endOfMessage}");
return this.internalWebSocket.SendAsync(buffer, messageType, endOfMessage, cancellationToken);
}
public void RefreshSocket(ClientWebSocket? clientWebSocket = null)
{
this.internalWebSocket?.Dispose();
this.internalWebSocket = clientWebSocket ?? new ClientWebSocket();
}
}