changes to use dispose

This commit is contained in:
Luke Brown
2022-05-16 22:09:41 -05:00
parent 8bb4cd017c
commit a64eebe79f
9 changed files with 84 additions and 58 deletions

View File

@@ -19,7 +19,7 @@ namespace Emby.Server.Implementations.HttpServer
/// <summary>
/// Class WebSocketConnection.
/// </summary>
public class WebSocketConnection : IWebSocketConnection, IDisposable
public class WebSocketConnection : IWebSocketConnection, IAsyncDisposable, IDisposable
{
/// <summary>
/// The logger.
@@ -231,12 +231,6 @@ namespace Emby.Server.Implementations.HttpServer
CancellationToken.None);
}
/// <inheritdoc />
public async Task CloseSocket(CancellationToken cancellationToken)
{
await _socket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "System Shutdown", cancellationToken).ConfigureAwait(false);
}
/// <inheritdoc />
public void Dispose()
{
@@ -255,5 +249,25 @@ namespace Emby.Server.Implementations.HttpServer
_socket.Dispose();
}
}
/// <inheritdoc />
public async ValueTask DisposeAsync()
{
await DisposeAsyncCore().ConfigureAwait(false);
Dispose(false);
GC.SuppressFinalize(this);
}
/// <summary>
/// Used to perform asynchronous cleanup of managed resources or for cascading calls to <see cref="DisposeAsync"/>.
/// </summary>
/// <returns>A ValueTask.</returns>
protected virtual async ValueTask DisposeAsyncCore()
{
if (_socket.State == WebSocketState.Open)
{
await _socket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "System Shutdown", CancellationToken.None).ConfigureAwait(false);
}
}
}
}