소스 검색

Merge pull request #3782 from Bond-009/websocket2

Minor fixes for websocket code
Anthony Lavado 4 년 전
부모
커밋
c5bc046c40
2개의 변경된 파일5개의 추가작업 그리고 5개의 파일을 삭제
  1. 1 1
      Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
  2. 4 4
      Emby.Server.Implementations/HttpServer/WebSocketConnection.cs

+ 1 - 1
Emby.Server.Implementations/HttpServer/HttpListenerHost.cs

@@ -567,7 +567,7 @@ namespace Emby.Server.Implementations.HttpServer
 
 
                 WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync().ConfigureAwait(false);
                 WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync().ConfigureAwait(false);
 
 
-                var connection = new WebSocketConnection(
+                using var connection = new WebSocketConnection(
                     _loggerFactory.CreateLogger<WebSocketConnection>(),
                     _loggerFactory.CreateLogger<WebSocketConnection>(),
                     webSocket,
                     webSocket,
                     context.Connection.RemoteIpAddress,
                     context.Connection.RemoteIpAddress,

+ 4 - 4
Emby.Server.Implementations/HttpServer/WebSocketConnection.cs

@@ -19,7 +19,7 @@ namespace Emby.Server.Implementations.HttpServer
     /// <summary>
     /// <summary>
     /// Class WebSocketConnection.
     /// Class WebSocketConnection.
     /// </summary>
     /// </summary>
-    public class WebSocketConnection : IWebSocketConnection
+    public class WebSocketConnection : IWebSocketConnection, IDisposable
     {
     {
         /// <summary>
         /// <summary>
         /// The logger.
         /// The logger.
@@ -119,7 +119,7 @@ namespace Emby.Server.Implementations.HttpServer
                 Memory<byte> memory = writer.GetMemory(512);
                 Memory<byte> memory = writer.GetMemory(512);
                 try
                 try
                 {
                 {
-                    receiveresult = await _socket.ReceiveAsync(memory, cancellationToken);
+                    receiveresult = await _socket.ReceiveAsync(memory, cancellationToken).ConfigureAwait(false);
                 }
                 }
                 catch (WebSocketException ex)
                 catch (WebSocketException ex)
                 {
                 {
@@ -137,7 +137,7 @@ namespace Emby.Server.Implementations.HttpServer
                 writer.Advance(bytesRead);
                 writer.Advance(bytesRead);
 
 
                 // Make the data available to the PipeReader
                 // Make the data available to the PipeReader
-                FlushResult flushResult = await writer.FlushAsync();
+                FlushResult flushResult = await writer.FlushAsync().ConfigureAwait(false);
                 if (flushResult.IsCompleted)
                 if (flushResult.IsCompleted)
                 {
                 {
                     // The PipeReader stopped reading
                     // The PipeReader stopped reading
@@ -223,7 +223,7 @@ namespace Emby.Server.Implementations.HttpServer
 
 
             if (info.MessageType.Equals("KeepAlive", StringComparison.Ordinal))
             if (info.MessageType.Equals("KeepAlive", StringComparison.Ordinal))
             {
             {
-                await SendKeepAliveResponse();
+                await SendKeepAliveResponse().ConfigureAwait(false);
             }
             }
             else
             else
             {
             {