Class TcpConnection
Namespace: DotBoxD.Transports.Tcp
Assembly: DotBoxD.Transports.Tcp.dll
TCP-based connection implementation.
public sealed class TcpConnection : IRpcFrameChannel, IRpcValueTaskChannel, IRpcChannel, IAsyncDisposableInheritance
Section titled “Inheritance”Implements
Section titled “Implements”IRpcFrameChannel, IRpcValueTaskChannel, IRpcChannel, IAsyncDisposable
Inherited Members
Section titled “Inherited Members”object.Equals(object), object.Equals(object, object), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object, object), object.ToString()
Constructors
Section titled “Constructors”TcpConnection(TcpClient)
Section titled “ TcpConnection(TcpClient)”public TcpConnection(TcpClient client)Parameters
Section titled “Parameters”client TcpClient
TcpConnection(TcpClient, TimeSpan?)
Section titled “ TcpConnection(TcpClient, TimeSpan?)”Creates a TCP connection with an idle bound for both first-byte and body reads. Pass
System.Threading.Timeout.InfiniteTimeSpan to disable; null uses the default.
public TcpConnection(TcpClient client, TimeSpan? frameReadIdleTimeout)Parameters
Section titled “Parameters”client TcpClient
frameReadIdleTimeout TimeSpan?
Fields
Section titled “Fields”DefaultFrameReadIdleTimeout
Section titled “ DefaultFrameReadIdleTimeout”Default idle timeout applied to frame reads (30 seconds).
public static readonly TimeSpan DefaultFrameReadIdleTimeoutField Value
Section titled “Field Value”Properties
Section titled “Properties”IsConnected
Section titled “ IsConnected”Best-effort liveness hint combining disposal with the socket’s last known state. This does not probe the wire; rely on I/O exceptions for authoritative connection state.
public bool IsConnected { get; }Property Value
Section titled “Property Value”RemoteEndpoint
Section titled “ RemoteEndpoint”Gets a string representation of the remote endpoint.
public string RemoteEndpoint { get; }Property Value
Section titled “Property Value”Methods
Section titled “Methods”DisposeAsync()
Section titled “ DisposeAsync()”Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()Returns
Section titled “Returns”A task that represents the asynchronous dispose operation.
ReceiveAsync(CancellationToken)
Section titled “ ReceiveAsync(CancellationToken)”Receives a framed message. The caller owns the returned DotBoxD.Services.Buffers.Payload and must
dispose it. A payload with DotBoxD.Services.Buffers.Payload.Length of 0 signals the channel was closed.
public Task<Payload> ReceiveAsync(CancellationToken ct = default)Parameters
Section titled “Parameters”Returns
Section titled “Returns”ReceiveFrameValueAsync(CancellationToken)
Section titled “ ReceiveFrameValueAsync(CancellationToken)”Receives a complete frame whose ownership transfers to the caller on successful completion.
public ValueTask<RpcFrame> ReceiveFrameValueAsync(CancellationToken ct = default)Parameters
Section titled “Parameters”Returns
Section titled “Returns”Remarks
Section titled “Remarks”The caller must consume the returned logical frame exactly once by calling either
DotBoxD.Services.Transport.RpcFrame.DetachPayload or DotBoxD.Services.Transport.RpcFrame.Dispose.
ReceiveValueAsync(CancellationToken)
Section titled “ ReceiveValueAsync(CancellationToken)”public ValueTask<Payload> ReceiveValueAsync(CancellationToken ct = default)Parameters
Section titled “Parameters”Returns
Section titled “Returns”SendAsync(ReadOnlyMemory<byte>, CancellationToken)
Section titled “ SendAsync(ReadOnlyMemory<byte>, CancellationToken)”Sends a framed message over the channel.
public Task SendAsync(ReadOnlyMemory<byte> data, CancellationToken ct = default)Parameters
Section titled “Parameters”data ReadOnlyMemory<byte>
Returns
Section titled “Returns”SendFrameValueAsync(PooledBufferWriter, CancellationToken)
Section titled “ SendFrameValueAsync(PooledBufferWriter, CancellationToken)”Sends a complete pooled frame and transfers its ownership to the channel.
public ValueTask SendFrameValueAsync(PooledBufferWriter frame, CancellationToken ct = default)Parameters
Section titled “Parameters”frame PooledBufferWriter
Returns
Section titled “Returns”Remarks
Section titled “Remarks”Ownership transfers immediately when this invocation returns a System.Threading.Tasks.ValueTask,
including an already faulted or canceled result. The channel then owns
frame through terminal success, failure, or cancellation and must dispose
it; the caller must not read, detach, or dispose it. If the invocation throws synchronously,
ownership remains with the caller, which must dispose the frame. The implementation must drop
its raw writer reference when the returned operation terminates.
Exceptions
Section titled “Exceptions”frame is null.
SendValueAsync(ReadOnlyMemory<byte>, CancellationToken)
Section titled “ SendValueAsync(ReadOnlyMemory<byte>, CancellationToken)”public ValueTask SendValueAsync(ReadOnlyMemory<byte> data, CancellationToken ct = default)Parameters
Section titled “Parameters”data ReadOnlyMemory<byte>