Class SharedMemoryDuplexPipe
A zero-copy duplex transport over shared memory implementing IDuplexPipe. Serializers write directly into spans pointing to memory shared between the two endpoints, and readers observe a ReadOnlySequence<T> over the same shared memory.
public sealed class SharedMemoryDuplexPipe : IDuplexPipe, IDisposable
- Inheritance
-
SharedMemoryDuplexPipe
- Implements
- Inherited Members
- Extension Methods
Remarks
On Windows the shared memory is backed by the paging file, so no file is created and the OS frees the memory
when both processes close it or exit, even by crashing.
On other platforms it is backed by a file (in RAM-backed /dev/shm where available) that is deleted as soon as the client opens it.
Properties
Input
Gets the PipeReader half of the duplex pipe.
public PipeReader Input { get; }
Property Value
Output
Gets the PipeWriter half of the duplex pipe.
public PipeWriter Output { get; }
Property Value
Methods
ConnectAsync(string, SharedMemoryPipeOptions?, CancellationToken)
Connects to a listening server on the specified channel name.
public static Task<SharedMemoryDuplexPipe> ConnectAsync(string channelName, SharedMemoryPipeOptions? options = null, CancellationToken cancellationToken = default)
Parameters
channelNamestringThe unique name of the channel the server is listening on.
optionsSharedMemoryPipeOptionsOptions controlling ring capacity, signaling, and backing file directory.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<SharedMemoryDuplexPipe>
A connected SharedMemoryDuplexPipe endpoint representing the client side.
CreatePairAsync(SharedMemoryPipeOptions?, CancellationToken)
Creates two connected endpoints that share an in-memory mapped ring.
public static Task<(SharedMemoryDuplexPipe Client, SharedMemoryDuplexPipe Server)> CreatePairAsync(SharedMemoryPipeOptions? options = null, CancellationToken cancellationToken = default)
Parameters
optionsSharedMemoryPipeOptionsOptions controlling ring capacity, signaling, and backing file directory.
cancellationTokenCancellationTokenA token to cancel creation.
Returns
- Task<(SharedMemoryDuplexPipe Client, SharedMemoryDuplexPipe Server)>
The connected client and server endpoints.
Dispose()
Releases all unmanaged resources and backing files associated with this endpoint.
public void Dispose()
ListenAsync(string, SharedMemoryPipeOptions?, CancellationToken)
Listens on the specified channel name and accepts a connecting client.
public static Task<SharedMemoryDuplexPipe> ListenAsync(string channelName, SharedMemoryPipeOptions? options = null, CancellationToken cancellationToken = default)
Parameters
channelNamestringThe unique name for the shared channel.
optionsSharedMemoryPipeOptionsOptions controlling ring capacity, signaling, and backing file directory.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<SharedMemoryDuplexPipe>
A connected SharedMemoryDuplexPipe endpoint representing the server side.