Class TcpTransportConnection
Plaintext TCP implementation of ITransportConnection. Owns two pipes (input + output) and two pump loops that bridge them to a NetworkStream.
Inherited Members
Namespace: Akka.IO
Assembly: Akka.dll
Syntax
public sealed class TcpTransportConnection : ITransportConnection, IAsyncDisposable
Constructors
| Edit this page View SourceTcpTransportConnection(Socket, PipeOptions?, PipeOptions?)
Creates a transport connection from an already-connected socket. Starts the read and write pump loops immediately.
Declaration
public TcpTransportConnection(Socket socket, PipeOptions? inputPipeOptions = null, PipeOptions? outputPipeOptions = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Socket | socket | |
| PipeOptions | inputPipeOptions | |
| PipeOptions | outputPipeOptions |
TcpTransportConnection(Socket, Stream, PipeOptions?, PipeOptions?)
Creates a transport connection from an existing stream (for TLS or testing).
Declaration
public TcpTransportConnection(Socket socket, Stream stream, PipeOptions? inputPipeOptions = null, PipeOptions? outputPipeOptions = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Socket | socket | |
| Stream | stream | |
| PipeOptions | inputPipeOptions | |
| PipeOptions | outputPipeOptions |
Properties
| Edit this page View SourceHasReadError
Returns true if the read pump encountered an I/O error. This is set BEFORE the input pipe writer is completed, so the actor can check it synchronously when handling a completed pipe read to distinguish error-EOF from normal EOF, even before the ReadCompleted task has been observed.
Declaration
public bool HasReadError { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Input
Pipe reader for inbound data (data received from the remote peer). The actor reads from this to get Tcp.Received data.
Declaration
public PipeReader Input { get; }
Property Value
| Type | Description |
|---|---|
| PipeReader |
ReadCompleted
Completes when the read pump finishes. Check IsFaulted to determine whether the read ended due to an I/O error (vs. normal EOF). The input PipeWriter is always completed WITHOUT passing the exception, so buffered data is preserved and the actor can drain it before checking this task.
Declaration
public Task ReadCompleted { get; }
Property Value
| Type | Description |
|---|---|
| Task |
ReadError
The exception that caused the read pump to fail, or null if no error. Set at the same time as HasReadError.
Declaration
public Exception? ReadError { get; }
Property Value
| Type | Description |
|---|---|
| Exception |
WriteCompleted
Completes when the write pump finishes (all buffered data flushed to the stream).
Declaration
public Task WriteCompleted { get; }
Property Value
| Type | Description |
|---|---|
| Task |
Methods
| Edit this page View SourceAbort()
Abort: RST the connection immediately, no flush.
Declaration
public void Abort()
CloseAsync()
Full close: flushes remaining writes, closes the connection.
Declaration
public Task CloseAsync()
Returns
| Type | Description |
|---|---|
| Task |
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
Declaration
public ValueTask DisposeAsync()
Returns
| Type | Description |
|---|---|
| ValueTask | A task that represents the asynchronous dispose operation. |
FlushAsync(CancellationToken)
Explicitly flushes any buffered data to the write pump. Useful for low-throughput scenarios where writes don't fill the buffer. Under high throughput, the buffer auto-flushes at the pause threshold.
Declaration
public ValueTask<FlushResult> FlushAsync(CancellationToken ct = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | ct |
Returns
| Type | Description |
|---|---|
| ValueTask<FlushResult> |
ShutdownAsync()
Half-close: flushes remaining writes, sends FIN, keeps reading.
Declaration
public Task ShutdownAsync()
Returns
| Type | Description |
|---|---|
| Task |
WriteAsync(ReadOnlySequence<byte>, CancellationToken)
Writes a multi-segment sequence to the transport. Each segment is copied into the internal buffer. This avoids per-segment syscalls.
Declaration
public ValueTask<FlushResult> WriteAsync(ReadOnlySequence<byte> data, CancellationToken ct = default)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySequence<byte> | data | |
| CancellationToken | ct |
Returns
| Type | Description |
|---|---|
| ValueTask<FlushResult> |
WriteAsync(ReadOnlyMemory<byte>, CancellationToken)
Writes data to the transport. Bytes are copied into an internal buffer and will be flushed to the underlying stream by the write pump. Returns when bytes are accepted into the buffer (not when sent on the wire). Goes async when backpressure is active (buffer full).
Declaration
public ValueTask<FlushResult> WriteAsync(ReadOnlyMemory<byte> data, CancellationToken ct = default)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlyMemory<byte> | data | |
| CancellationToken | ct |
Returns
| Type | Description |
|---|---|
| ValueTask<FlushResult> |
Edit this page