aboutsummaryrefslogtreecommitdiff
path: root/lib/Net.Messaging.FBM/src
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-10-14 15:41:17 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2023-10-14 15:41:17 -0400
commit62f9e126912fa9a620a361fb5b88d33506e096fb (patch)
tree78665fe8516c559821aa4358ca9e2734e475415a /lib/Net.Messaging.FBM/src
parent0f0c991891b6be076a9a367627201eceeb6d354e (diff)
some refactoring and tests
Diffstat (limited to 'lib/Net.Messaging.FBM/src')
-rw-r--r--lib/Net.Messaging.FBM/src/Client/FBMClient.cs3
-rw-r--r--lib/Net.Messaging.FBM/src/Server/FBMListener.cs23
2 files changed, 16 insertions, 10 deletions
diff --git a/lib/Net.Messaging.FBM/src/Client/FBMClient.cs b/lib/Net.Messaging.FBM/src/Client/FBMClient.cs
index d24aca8..5184c38 100644
--- a/lib/Net.Messaging.FBM/src/Client/FBMClient.cs
+++ b/lib/Net.Messaging.FBM/src/Client/FBMClient.cs
@@ -73,7 +73,7 @@ namespace VNLib.Net.Messaging.FBM.Client
private readonly SemaphoreSlim SendLock;
private readonly ConcurrentDictionary<int, FBMRequest> ActiveRequests;
- private readonly ReusableStore<FBMRequest> RequestRental;
+ private readonly ObjectRental<FBMRequest> RequestRental;
/// <summary>
/// The configuration for the current client
@@ -539,6 +539,7 @@ namespace VNLib.Net.Messaging.FBM.Client
/// <param name="vms">The raw response packet from the server</param>
private void ProcessControlFrame(VnMemoryStream vms)
{
+ Debug("Client control frame received. Size: {size}", vms.Length.ToString());
vms.Dispose();
}
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;