Class TcpConnection
- Namespace
- DotBoxD.Transports.Tcp
- Assembly
- DotBoxD.Transports.Tcp.dll
TCP-based connection implementation.
public sealed class TcpConnection : IRpcFrameChannel, IRpcValueTaskChannel, IRpcChannel, IAsyncDisposable
- Inheritance
-
TcpConnection
- Implements
- Inherited Members
Constructors
TcpConnection(TcpClient)
public TcpConnection(TcpClient client)
Parameters
clientTcpClient
TcpConnection(TcpClient, TimeSpan?)
Creates a TCP connection. frameReadIdleTimeout bounds how long an
in-progress frame read may stall with no data before the connection is torn down — defending
against a slow-loris peer that declares a large frame then trickles (or sends nothing),
pinning a connection and a rented buffer. It is NOT applied while idly awaiting the first byte
of the next frame, so legitimately idle connections are unaffected. Pass
InfiniteTimeSpan to disable; null uses
DefaultFrameReadIdleTimeout.
public TcpConnection(TcpClient client, TimeSpan? frameReadIdleTimeout)
Parameters
Fields
DefaultFrameReadIdleTimeout
Default inter-read idle timeout applied to an in-progress frame read (30 seconds).
public static readonly TimeSpan DefaultFrameReadIdleTimeout
Field Value
Properties
IsConnected
Whether this connection is believed to be live. This is a best-effort hint: it combines the disposed flag with 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; }
Property Value
RemoteEndpoint
Gets a string representation of the remote endpoint.
public string RemoteEndpoint { get; }
Property Value
Methods
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
ReceiveAsync(CancellationToken)
Receives a framed message. The caller owns the returned Payload and must dispose it. A payload with Length of 0 signals the channel was closed.
public Task<Payload> ReceiveAsync(CancellationToken ct = default)
Parameters
Returns
ReceiveFrameValueAsync(CancellationToken)
public ValueTask<RpcFrame> ReceiveFrameValueAsync(CancellationToken ct = default)
Parameters
Returns
ReceiveValueAsync(CancellationToken)
public ValueTask<Payload> ReceiveValueAsync(CancellationToken ct = default)
Parameters
Returns
SendAsync(ReadOnlyMemory<byte>, CancellationToken)
Sends a framed message over the channel.
public Task SendAsync(ReadOnlyMemory<byte> data, CancellationToken ct = default)
Parameters
dataReadOnlyMemory<byte>ctCancellationToken
Returns
SendFrameValueAsync(PooledBufferWriter, CancellationToken)
public ValueTask SendFrameValueAsync(PooledBufferWriter frame, CancellationToken ct = default)
Parameters
framePooledBufferWriterctCancellationToken
Returns
SendValueAsync(ReadOnlyMemory<byte>, CancellationToken)
public ValueTask SendValueAsync(ReadOnlyMemory<byte> data, CancellationToken ct = default)
Parameters
dataReadOnlyMemory<byte>ctCancellationToken