Skip to content

Class TcpConnection

Namespace: DotBoxD.Transports.Tcp
Assembly: DotBoxD.Transports.Tcp.dll

TCP-based connection implementation.

public sealed class TcpConnection : IRpcFrameChannel, IRpcValueTaskChannel, IRpcChannel, IAsyncDisposable

objectTcpConnection

IRpcFrameChannel, IRpcValueTaskChannel, IRpcChannel, IAsyncDisposable

object.Equals(object), object.Equals(object, object), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object, object), object.ToString()

public TcpConnection(TcpClient client)

client TcpClient

Creates a TCP connection. frameReadIdleTimeout bounds how long an frame read may stall with no data before the connection is torn down. This bounds both the first frame byte and body reads so a slow-loris peer cannot pin a connection or rented buffer. Pass System.Threading.Timeout.InfiniteTimeSpan to disable; null uses DotBoxD.Transports.Tcp.TcpConnection.DefaultFrameReadIdleTimeout.

public TcpConnection(TcpClient client, TimeSpan? frameReadIdleTimeout)

client TcpClient

frameReadIdleTimeout TimeSpan?

Default idle timeout applied to frame reads (30 seconds).

public static readonly TimeSpan DefaultFrameReadIdleTimeout

TimeSpan

Whether this connection is believed to be live. This is a best-effort hint: it combines the disposed flag with System.Net.Sockets.TcpClient.Connected, which reflects only the last known socket state and does not probe the wire. A dropped connection is not observed here until the next send/receive fails — rely on I/O exceptions for the authoritative state.

public bool IsConnected { get; }

bool

Gets a string representation of the remote endpoint.

public string RemoteEndpoint { get; }

string

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

ValueTask

A task that represents the asynchronous dispose operation.

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)

ct CancellationToken

Task<Payload>

ReceiveFrameValueAsync(CancellationToken)

Section titled “ ReceiveFrameValueAsync(CancellationToken)”
public ValueTask<RpcFrame> ReceiveFrameValueAsync(CancellationToken ct = default)

ct CancellationToken

ValueTask<RpcFrame>

public ValueTask<Payload> ReceiveValueAsync(CancellationToken ct = default)

ct CancellationToken

ValueTask<Payload>

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)

data ReadOnlyMemory<byte>

ct CancellationToken

Task

SendFrameValueAsync(PooledBufferWriter, CancellationToken)

Section titled “ SendFrameValueAsync(PooledBufferWriter, CancellationToken)”
public ValueTask SendFrameValueAsync(PooledBufferWriter frame, CancellationToken ct = default)

frame PooledBufferWriter

ct CancellationToken

ValueTask

SendValueAsync(ReadOnlyMemory<byte>, CancellationToken)

Section titled “ SendValueAsync(ReadOnlyMemory<byte>, CancellationToken)”
public ValueTask SendValueAsync(ReadOnlyMemory<byte> data, CancellationToken ct = default)

data ReadOnlyMemory<byte>

ct CancellationToken

ValueTask