aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md8
-rw-r--r--lib/Net.Messaging.FBM/src/Client/FBMClient.cs23
-rw-r--r--lib/Net.Messaging.FBM/src/Client/ManagedClientWebSocket.cs8
-rw-r--r--lib/Plugins/README.md4
-rw-r--r--lib/Utils/README.md76
-rw-r--r--lib/Utils/src/Memory/MemoryHandle.cs9
6 files changed, 57 insertions, 71 deletions
diff --git a/README.md b/README.md
index 744a475..4fbada6 100644
--- a/README.md
+++ b/README.md
@@ -18,10 +18,10 @@ Docs and articles will be available from the docs link below . There are docs pe
Again, go to my website below, my email address is available, go ahead and send me a message. Or use the email address from my profile to send me an email (via proton mail for now)
### Links
-[Home Page](https://www.vaughnnugent.com)- Website home page
-[Documentation](https://www.vaughnnugent.com/resources/software/articles?tags=docs,_VNLib.Core) - Docs and articles for this module
-[Builds for VNLib.Core](https://www.vaughnnugent.com/resources/software/modules/VNLib.Core) - Per-project build artifacts
-[Links for Nuget Feeds](https://www.vaughnnugent.com/resources/software/modules) - Get my NuGet feed links
+[Home Page](https://www.vaughnnugent.com)- Website home page
+[Documentation](https://www.vaughnnugent.com/resources/software/articles?tags=docs,_VNLib.Core) - Docs and articles for this module
+[Builds for VNLib.Core](https://www.vaughnnugent.com/resources/software/modules/VNLib.Core) - Per-project build artifacts
+[Links for Nuget Feeds](https://www.vaughnnugent.com/resources/software/modules) - Get my NuGet feed links
## Index/NameSpaces
**VNLib.**
diff --git a/lib/Net.Messaging.FBM/src/Client/FBMClient.cs b/lib/Net.Messaging.FBM/src/Client/FBMClient.cs
index 82b6c7e..d24aca8 100644
--- a/lib/Net.Messaging.FBM/src/Client/FBMClient.cs
+++ b/lib/Net.Messaging.FBM/src/Client/FBMClient.cs
@@ -65,6 +65,7 @@ namespace VNLib.Net.Messaging.FBM.Client
/// You may inspect the event args to determine the cause of the error.
/// </summary>
public event EventHandler<FMBClientErrorEventArgs>? ConnectionClosedOnError;
+
/// <summary>
/// Raised when the client listener operaiton has completed as a normal closure
/// </summary>
@@ -78,11 +79,13 @@ namespace VNLib.Net.Messaging.FBM.Client
/// The configuration for the current client
/// </summary>
public FBMClientConfig Config { get; }
+
/// <summary>
/// A handle that is reset when a connection has been successfully set, and is set
/// when the connection exists
/// </summary>
public ManualResetEvent ConnectionStatusHandle { get; }
+
/// <summary>
/// The <see cref="ClientWebSocket"/> to send/recieve message on
/// </summary>
@@ -150,7 +153,7 @@ namespace VNLib.Net.Messaging.FBM.Client
ConnectionStatusHandle.Reset();
//Begin listeing for requets in a background task
- _ = Task.Run(ProcessContinuousRecvAsync, cancellationToken);
+ _ = Task.Run(() => ProcessContinuousRecvAsync(ClientSocket), cancellationToken);
}
/// <summary>
@@ -298,16 +301,19 @@ namespace VNLib.Net.Messaging.FBM.Client
{
//Send the initial request packet
await ClientSocket.SendAsync(requestData, WebSocketMessageType.Binary, false, cancellationToken);
+
//Stream mesage body
do
{
//Read data
int read = await payload.ReadAsync(buffer.Memory, cancellationToken);
+
if (read == 0)
{
//No more data avialable
break;
}
+
//write message to socket, if the read data was smaller than the buffer, we can send the last packet
await ClientSocket.SendAsync(buffer.Memory[..read], WebSocketMessageType.Binary, read < bufSize, cancellationToken);
@@ -388,9 +394,10 @@ namespace VNLib.Net.Messaging.FBM.Client
/// until the socket is closed, or canceled
/// </summary>
/// <returns></returns>
- protected async Task ProcessContinuousRecvAsync()
+ protected async Task ProcessContinuousRecvAsync(WebSocket socket)
{
Debug("Begining receive loop");
+
//Alloc recv buffer
IMemoryOwner<byte> recvBuffer = Config.BufferHeap.DirectAlloc<byte>(Config.RecvBufferSize);
try
@@ -399,7 +406,8 @@ namespace VNLib.Net.Messaging.FBM.Client
while (true)
{
//Listen for incoming packets with the intial data buffer
- ValueWebSocketReceiveResult result = await ClientSocket.ReceiveAsync(recvBuffer.Memory, CancellationToken.None);
+ ValueWebSocketReceiveResult result = await socket.ReceiveAsync(recvBuffer.Memory, CancellationToken.None);
+
//If the message is a close message, its time to exit
if (result.MessageType == WebSocketMessageType.Close)
{
@@ -412,15 +420,19 @@ namespace VNLib.Net.Messaging.FBM.Client
Debug("Empty message recieved from server");
continue;
}
+
//Alloc data buffer and write initial data
VnMemoryStream responseBuffer = new(Config.BufferHeap);
+
//Copy initial data
responseBuffer.Write(recvBuffer.Memory.Span[..result.Count]);
+
//Receive packets until the EOF is reached
while (!result.EndOfMessage)
{
//recive more data
- result = await ClientSocket.ReceiveAsync(recvBuffer.Memory, CancellationToken.None);
+ result = await socket.ReceiveAsync(recvBuffer.Memory, CancellationToken.None);
+
//Make sure the buffer is not too large
if ((responseBuffer.Length + result.Count) > Config.MaxMessageSize)
{
@@ -429,12 +441,15 @@ namespace VNLib.Net.Messaging.FBM.Client
Debug("Recieved a message that was too large, skipped");
goto Skip;
}
+
//Copy continuous data
responseBuffer.Write(recvBuffer.Memory.Span[..result.Count]);
}
+
//Reset the buffer stream position
_ = responseBuffer.Seek(0, SeekOrigin.Begin);
ProcessResponse(responseBuffer);
+
//Goto skip statment to cleanup resources
Skip:;
}
diff --git a/lib/Net.Messaging.FBM/src/Client/ManagedClientWebSocket.cs b/lib/Net.Messaging.FBM/src/Client/ManagedClientWebSocket.cs
index acac369..d0352d3 100644
--- a/lib/Net.Messaging.FBM/src/Client/ManagedClientWebSocket.cs
+++ b/lib/Net.Messaging.FBM/src/Client/ManagedClientWebSocket.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2022 Vaughn Nugent
+* Copyright (c) 2023 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Net.Messaging.FBM
@@ -32,8 +32,6 @@ using System.Security.Cryptography.X509Certificates;
using VNLib.Utils.Memory;
-#nullable enable
-
namespace VNLib.Net.Messaging.FBM.Client
{
@@ -52,9 +50,13 @@ namespace VNLib.Net.Messaging.FBM.Client
/// A collection of headers to add to the client
/// </summary>
public WebHeaderCollection Headers { get; }
+
public X509CertificateCollection Certificates { get; }
+
public IWebProxy? Proxy { get; set; }
+
public CookieContainer? Cookies { get; set; }
+
public RemoteCertificateValidationCallback? RemoteCertificateValidationCallback { get; set; }
diff --git a/lib/Plugins/README.md b/lib/Plugins/README.md
index a4f4fc0..0f82523 100644
--- a/lib/Plugins/README.md
+++ b/lib/Plugins/README.md
@@ -10,8 +10,8 @@ Debug build w/ symbols & xml docs, release builds, NuGet packages, and individua
### Docs and Guides
Documentation, specifications, and setup guides are available on my website.
-[Docs and Articles](https://www.vaughnnugent.com/resources/software/articles?tags=docs,_VNLib.Plugins)
-[Builds and Source](https://www.vaughnnugent.com/resources/software/modules/VNLib.Core)
+[Docs and Articles](https://www.vaughnnugent.com/resources/software/articles?tags=docs,_VNLib.Plugins)
+[Builds and Source](https://www.vaughnnugent.com/resources/software/modules/VNLib.Core)
## License
The software in this repository is licensed under the GNU GPL version 2.0 (or any later version). See the LICENSE files for more information. \ No newline at end of file
diff --git a/lib/Utils/README.md b/lib/Utils/README.md
index 98abb07..632253c 100644
--- a/lib/Utils/README.md
+++ b/lib/Utils/README.md
@@ -1,8 +1,23 @@
# VNLib.Utils
-A .NET 6 /C# library for common .NET operation and memory optimizations.
+A .NET 6 /C# library for common .NET operation and memory optimizations.
-namespaces
+### License
+The software in this repository is licensed under the GNU GPL version 2.0 (or any later version). See the LICENSE files for more information.
+
+### Documentation
+Docs and articles will be available from the docs link below. This library is quite large and will take time to develop docs. I heavily document all public APIs in XML so you can at-least get basic information when using this library.
+
+### Builds & Feeds
+Builds contain the individual components listed below packaged per-project, available for download on my website. Build packages will be tgz archives (except for nuget packages). You can obtain debug and release builds, along with per-project source code.
+
+### Links
+[Home Page](https://www.vaughnnugent.com) - Website home page
+[Documentation](https://www.vaughnnugent.com/resources/software/articles?tags=docs,_VNLib.Utils) - Docs and articles for this project
+[Builds for VNLib.Core](https://www.vaughnnugent.com/resources/software/modules/VNLib.Core) - Per-project build artifacts
+[Links for Nuget Feeds](https://www.vaughnnugent.com/resources/software/modules) - Get my NuGet feed links
+
+### Namespaces
- VNLib.Utils.Async - Provides classes for asynchronous access synchronization and some asynchronous collections
- VNLib.Utils.Extensions - Internal and external extensions for condensed common operations
- VNLib.Utils.IO - Memory focused data structures for IO operations
@@ -13,57 +28,10 @@ namespaces
- VNLib.Utils.Native - Utilities for safely (dynamically) loading and accessing platform native libraries.
- VNLib.Utils.Resources - Abstractions and base data structures for holding and accessing resources.
-#### Builds
-Debug build w/ symbols & xml docs, release builds, NuGet packages, and individually packaged source code are available on my [website](https://www.vaughnnugent.com/resources/software). All tar-gzip (.tgz) files will have an associated .sha384 appended checksum of the desired download file.
-
-### Recommended 3rd Party Libs
-This library does not require any direct dependencies, however there are some optional ones that are recommended for higher performance. This library does not, modify, contribute, or affect the functionality of any of the 3rd party libraries recommended below.
-
-[**RPMalloc**](https://github.com/mjansson/rpmalloc) By Mattias Jansson - VNlib.Utils.Memory (and sub-classes) may load and bind function calls to this native library determined by environment variables. To use RPMalloc as the default unmanaged allocator simply add the dynamic library to the native lib search path, such as in the executable directory, and set the allocator environment variable as instructed below. I maintain a compatible Windows x64 [dll library](../WinRpMalloc/README.md) on my website and in this repository, that conforms to the [NativeHeap](../NativeHeapApi/README.md) api required for runtime loading.
-
-## Memory
-
-### Native Memory details and allocator selection
-Allocator selection has been updated to abstract the unmanaged heap loading to accommodate user defined memory allocators. A new class called the [NativeHeap](src/Memory/NativeHeap.cs) is the abstraction layer between your dll and the managed heap environment.
-
-There are two types of heap architectures that are in use within the Memory namespace. Global/Shared and Private/First Class. They generally make the following assumptions
-
-**Shared Heap** - Prefers performance over isolation, consumers expect calls to have minimal multi-threaded performance penalties at the cost of isolation.
-
-**Private Heap** - Prefers isolation over performance, consumers assume calls may have multi-threaded performance penalties for the benefit of isolation.
-
-On heap creation, the `UnmanagedHeapDescriptor` structure's `HeapCreationFlags` will have the IsShared flag set if the desired heap is the global heap, or a private heap in the absence of said flag. By default **ALL** heaps are assumed **not** thread safe, and synchronization is provided by the `UnmanagedHeapBase` class, and as such, the UseSynchronization flag is always present when using the `InitializeNewHeapForProcess` method call.
-
-#### Note for heap implementers
-Implementers may decide to clear the UseSynchronization flag if they know their implementation is thread safe, or are using their own synchronization method. Generally I would recommend letting the `UnmanagedHeapBase` class fallback to managed synchronization if your heap implementation requires synchronization, because the runtime *generally* provides the best performance for managed code (in my experience.) but you should do your own performance testing for your use case.
-
-Please use the [NativeHeapApi readme](../NativeHeapApi/README.md) for further instruction and implementation details.
-
-#### Note for consumers
-The [MemoryUtil](src/Memory/MemoryUtil.cs) class allows for consumers to allocate a "private" heaps on demand or a global/shared heap for the library consumer (see AssemblyLoadContext for static class details). When creating private heaps the MemoryUtil class exposes a method called `InitializeNewHeapForProcess` which will create a new "private" heap on demand using the same configuration variables as the shared global heap (shared heap calls the same method internally). All heaps, private or shared are assumed to be **thread safe** when using this method. When calling `NativeHeap.LoadHeap` directly, you may disable thread safety and "roll your own" if you prefer. Understand that the heap implementation may override your requests, understand your heap's implementation if you choose to use this method.
-
-Most VNLib libraries use the Shared heap for performance reasons, and in some cases private heaps for isolation, such as HTTP or TCP libraries, however they generally prefer performance over isolation and will choose the highest performance implementation.
-
-### Runtime allocator selection
-Setting the `VNLIB_SHARED_HEAP_FILE_PATH` environment variable will instruct the `InitializeNewHeapForProcess` method to load the native heap library at the given path, it may be an absolute path to the DLL file or a dll file name in a "safe" directory. It must conform to the NativeHeapApi, otherwise loading will fail. Understand that loading is deferred to the first access of the `MemoryUtil.Shared` property (this is subject to change) so don't be confused when seeing deferred debugging messages instead of a type initialization failure. This is also done to avoid Loader Lock contention issues, because we can.
-
-You may pass a hex encoded raw flags to the `heapCreate` method via the `UnmanagedHeapDescriptor.FLags` field globally, by setting the `VNLIB_SHARED_HEAP_RAW_FLAGS` environment variable.
-
-#### MemoryUtil fallbacks
-If you don't want to use a custom heap implementation, the library has safe fallbacks for all platforms. On Windows the PrivateHeap api is used by default. The shared heap, again, prefers performance and will use the process heap returned from `GetProcessHeap()`, instead of creating a private heap that requires synchronization penalties. On all other platforms the fallback will be the .NET NativeMemory allocator, which is cross platform, but does **not** actually implement a "private" heap. So that means on non-Windows platforms unless you select your own heap, isolation is not an option.
-
-### Heap Diagnostics
-The Memory.Diagnostics namespace was added to provide a wrapper for tracking IUnmanagedHeap memory allocations. Diagnostics can be enabled for the SharedHeap by setting the `VNLIB_SHARED_HEAP_DIAGNOSTICS` environment variable to "1". When enabled, calling `MemoryUtil.GetSharedHeapStats()` will return the heap's current statistics, otherwise an empty struct is returned. The Shared heap diagnostics are disabled by default.
-
-### Other notes
-Generally for internal library data structures that require memory allocation, a constructor override or a static method will consume a heap instance so you may pass your own heap instance or the Shared heap.
-
-## Usage
-A usage breakdown would be far to lengthy for this library, and instead I intend to keep valid and comprehensive documentation in Visual Studio XML documentation files included in this project's src directory.
-
-This library is a utilities library and therefor may be directly included in your application or libraries.
+## Recommended 3rd Party Libs
+This library does not require any direct dependencies, however there are some optional ones that are recommended for higher performance. This library does not, modify, contribute, or affect the functionality of any of the 3rd party libraries recommended below.
-### License
+[**RPMalloc**](https://github.com/mjansson/rpmalloc) By Mattias Jansson - VNlib.Utils.Memory (and sub-classes) may load and bind function calls to this native library determined by environment variables. To use RPMalloc as the default unmanaged allocator simply add the dynamic library to the native lib search path, such as in the executable directory, and set the allocator environment variable as instructed below. I maintain a compatible Windows x64 [dll library](../WinRpMalloc/README.md) on my website and in this repository, that conforms to the [NativeHeap](../NativeHeapApi/README.md) api required for runtime loading.
-The software in this repository is licensed under the GNU GPL version 2.0 (or any later version).
-See the LICENSE files for more information. \ No newline at end of file
+## Other notes
+Generally for internal library data structures that require memory allocation, a constructor override or a static method will consume a heap instance so you may pass your own heap instance or the Shared heap.
diff --git a/lib/Utils/src/Memory/MemoryHandle.cs b/lib/Utils/src/Memory/MemoryHandle.cs
index 067f6c0..bbf5a10 100644
--- a/lib/Utils/src/Memory/MemoryHandle.cs
+++ b/lib/Utils/src/Memory/MemoryHandle.cs
@@ -141,8 +141,6 @@ namespace VNLib.Utils.Memory
public unsafe void Resize(nuint elements)
{
this.ThrowIfClosed();
- //Update size (should never be less than inital size)
- _length = elements;
//Re-alloc (Zero if required)
try
{
@@ -150,9 +148,12 @@ namespace VNLib.Utils.Memory
* If resize raises an exception the current block pointer
* should still be valid, if its not, the pointer should
* be set to 0/-1, which will be considered invalid anyway
- */
+ */
+
+ Heap.Resize(ref handle, elements, (nuint)sizeof(T), ZeroMemory);
- Heap.Resize(ref handle, Length, (nuint)sizeof(T), ZeroMemory);
+ //Update size only if succeeded
+ _length = elements;
}
//Catch the disposed exception so we can invalidate the current ptr
catch (ObjectDisposedException)