diff options
author | vnugent <public@vaughnnugent.com> | 2023-10-14 15:41:17 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2023-10-14 15:41:17 -0400 |
commit | 62f9e126912fa9a620a361fb5b88d33506e096fb (patch) | |
tree | 78665fe8516c559821aa4358ca9e2734e475415a /lib/Net.Messaging.FBM/src/Server | |
parent | 0f0c991891b6be076a9a367627201eceeb6d354e (diff) |
some refactoring and tests
Diffstat (limited to 'lib/Net.Messaging.FBM/src/Server')
-rw-r--r-- | lib/Net.Messaging.FBM/src/Server/FBMListener.cs | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/Net.Messaging.FBM/src/Server/FBMListener.cs b/lib/Net.Messaging.FBM/src/Server/FBMListener.cs index fd8b025..46ee160 100644 --- a/lib/Net.Messaging.FBM/src/Server/FBMListener.cs +++ b/lib/Net.Messaging.FBM/src/Server/FBMListener.cs @@ -74,6 +74,7 @@ namespace VNLib.Net.Messaging.FBM.Server { Heap = heap; } +#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task /// <summary> /// Begins listening for requests on the current websocket until @@ -86,6 +87,9 @@ namespace VNLib.Net.Messaging.FBM.Server /// <returns>A <see cref="Task"/> that completes when the connection closes</returns> public async Task ListenAsync(WebSocketSession wss, RequestHandler handler, FBMListenerSessionParams args, object? userState) { + _ = wss ?? throw new ArgumentNullException(nameof(wss)); + _ = handler ?? throw new ArgumentNullException(nameof(handler)); + ListeningSession session = new(wss, handler, in args, userState); //Alloc a recieve buffer @@ -112,10 +116,10 @@ namespace VNLib.Net.Messaging.FBM.Server //break listen loop break; } - //create buffer for storing data - VnMemoryStream request = new(Heap); - //Copy initial data - request.Write(recvBuffer.Memory.Span[..result.Count]); + + //create buffer for storing data, pre alloc with initial data + VnMemoryStream request = new(Heap, recvBuffer.Memory[..result.Count]); + //Streaming read while (!result.EndOfMessage) { @@ -213,18 +217,17 @@ namespace VNLib.Net.Messaging.FBM.Server } //Get response data + await using IAsyncMessageReader messageEnumerator = await context.Response.GetResponseDataAsync(session.CancellationToken); + //Load inital segment if (await messageEnumerator.MoveNextAsync() && !session.CancellationToken.IsCancellationRequested) { ValueTask sendTask; //Syncrhonize access to send data because we may need to stream data to the client - if (!session.ResponseLock.Wait(0)) - { - await session.ResponseLock.WaitAsync(SEND_SEMAPHORE_TIMEOUT_MS); - } + await session.ResponseLock.WaitAsync(SEND_SEMAPHORE_TIMEOUT_MS); try { @@ -284,9 +287,11 @@ namespace VNLib.Net.Messaging.FBM.Server return Task.CompletedTask; } +#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task + private sealed class ListeningSession { - private readonly ReusableStore<FBMContext> CtxStore; + private readonly ObjectRental<FBMContext> CtxStore; private readonly CancellationTokenSource Cancellation; private readonly CancellationTokenRegistration Registration; private readonly FBMListenerSessionParams Params; |