Changes SessionWebSocketListener to (re)use a timer (#11358)

This commit is contained in:
Bond-009
2024-04-17 18:44:39 +02:00
committed by GitHub
parent 82e5f99f83
commit 356e05e3af
2 changed files with 36 additions and 88 deletions

View File

@@ -101,14 +101,14 @@ namespace Emby.Server.Implementations.HttpServer
var pipe = new Pipe();
var writer = pipe.Writer;
ValueWebSocketReceiveResult receiveresult;
ValueWebSocketReceiveResult receiveResult;
do
{
// Allocate at least 512 bytes from the PipeWriter
Memory<byte> memory = writer.GetMemory(512);
try
{
receiveresult = await _socket.ReceiveAsync(memory, cancellationToken).ConfigureAwait(false);
receiveResult = await _socket.ReceiveAsync(memory, cancellationToken).ConfigureAwait(false);
}
catch (WebSocketException ex)
{
@@ -116,7 +116,7 @@ namespace Emby.Server.Implementations.HttpServer
break;
}
int bytesRead = receiveresult.Count;
int bytesRead = receiveResult.Count;
if (bytesRead == 0)
{
break;
@@ -135,13 +135,13 @@ namespace Emby.Server.Implementations.HttpServer
LastActivityDate = DateTime.UtcNow;
if (receiveresult.EndOfMessage)
if (receiveResult.EndOfMessage)
{
await ProcessInternal(pipe.Reader).ConfigureAwait(false);
}
}
while ((_socket.State == WebSocketState.Open || _socket.State == WebSocketState.Connecting)
&& receiveresult.MessageType != WebSocketMessageType.Close);
&& receiveResult.MessageType != WebSocketMessageType.Close);
Closed?.Invoke(this, EventArgs.Empty);