Interface IDuplexConnection
- Namespace
- IceRpc.Transports
- Assembly
- IceRpc.dll
Represents a transport connection created by a duplex transport.
public interface IDuplexConnection : IDisposable
- Inherited Members
Remarks
Both the IceRPC core and the Slic transport implementation use this interface. They provide the following guarantees:
<ul><li>The <xref href="IceRpc.Transports.IDuplexConnection.ConnectAsync(System.Threading.CancellationToken)" data-throw-if-not-resolved="false"></xref> method is called first and once. No other methods are called
until it completes.</li><li>The <xref href="IceRpc.Transports.IDuplexConnection.ReadAsync(System.Memory%7bSystem.Byte%7d%2cSystem.Threading.CancellationToken)" data-throw-if-not-resolved="false"></xref> method is never called concurrently.</li><li>The <xref href="IceRpc.Transports.IDuplexConnection.WriteAsync(System.Buffers.ReadOnlySequence%7bSystem.Byte%7d%2cSystem.Threading.CancellationToken)" data-throw-if-not-resolved="false"></xref> method is never called concurrently.</li><li>The <xref href="IceRpc.Transports.IDuplexConnection.ReadAsync(System.Memory%7bSystem.Byte%7d%2cSystem.Threading.CancellationToken)" data-throw-if-not-resolved="false"></xref> and <xref href="IceRpc.Transports.IDuplexConnection.WriteAsync(System.Buffers.ReadOnlySequence%7bSystem.Byte%7d%2cSystem.Threading.CancellationToken)" data-throw-if-not-resolved="false"></xref> methods can be called concurrently.
</li><li>The <xref href="IceRpc.Transports.IDuplexConnection.ReadAsync(System.Memory%7bSystem.Byte%7d%2cSystem.Threading.CancellationToken)" data-throw-if-not-resolved="false"></xref> and <xref href="IceRpc.Transports.IDuplexConnection.ShutdownWriteAsync(System.Threading.CancellationToken)" data-throw-if-not-resolved="false"></xref> methods can be called
concurrently.
</li><li>The <xref href="IceRpc.Transports.IDuplexConnection.ShutdownWriteAsync(System.Threading.CancellationToken)" data-throw-if-not-resolved="false"></xref> method is called once but not while a <xref href="IceRpc.Transports.IDuplexConnection.WriteAsync(System.Buffers.ReadOnlySequence%7bSystem.Byte%7d%2cSystem.Threading.CancellationToken)" data-throw-if-not-resolved="false"></xref> call is in progress.</li><li>The <xref href="IceRpc.Transports.IDuplexConnection.WriteAsync(System.Buffers.ReadOnlySequence%7bSystem.Byte%7d%2cSystem.Threading.CancellationToken)" data-throw-if-not-resolved="false"></xref> is never called after a <xref href="IceRpc.Transports.IDuplexConnection.ShutdownWriteAsync(System.Threading.CancellationToken)" data-throw-if-not-resolved="false"></xref>
call.</li><li>The <xref href="System.IDisposable.Dispose" data-throw-if-not-resolved="false"></xref> method is called after the tasks returned by other methods
have completed. It can be called multiple times but not concurrently.</li></ul>
Methods
ConnectAsync(CancellationToken)
Connects this connection.
Task<TransportConnectionInformation> ConnectAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenA cancellation token that receives the cancellation requests.
Returns
- Task<TransportConnectionInformation>
A task that completes successfully with transport connection information when the connection is established.
Remarks
When you call this method on a client connection, the returned task can complete successfully before the server accepts the connection with AcceptAsync(CancellationToken): a connected client connection may be in the server-side listen backlog when the transport has such a backlog. See for example ListenBacklog.
The returned task can also complete with one of the following exceptions:
- AuthenticationException if authentication failed.
- IceRpcException if the transport reported an error.
- OperationCanceledException if cancellation was requested through the cancellation token.
Exceptions
- InvalidOperationException
Thrown if this connection is connected, connecting or if a previous connection attempt failed.
- ObjectDisposedException
Thrown if the connection is disposed.
ReadAsync(Memory<byte>, CancellationToken)
Reads data from the connection.
ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken)
Parameters
bufferMemory<byte>A buffer that receives the data read from the connection.
cancellationTokenCancellationTokenA cancellation token that receives the cancellation requests.
Returns
- ValueTask<int>
A value task that completes successfully with the number of bytes read into
buffer. This number is0when no data is available and the peer has called ShutdownWriteAsync(CancellationToken); otherwise, it is always greater than0.
Remarks
The returned value task can also complete with one of the following exceptions:
- IceRpcException if the transport reported an error.
- OperationCanceledException if cancellation was requested through the cancellation token.
Exceptions
- ArgumentException
Thrown if
bufferis empty.- InvalidOperationException
Thrown if the connection is not connected or if a read operation is already in progress.
- ObjectDisposedException
Thrown if the connection is disposed.
ShutdownWriteAsync(CancellationToken)
Shuts down the write side of the connection to notify the peer that no more data will be sent.
Task ShutdownWriteAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenA cancellation token that receives the cancellation requests.
Returns
- Task
A task that completes successfully when the shutdown completes successfully.
Remarks
The returned task can also complete with one of the following exceptions:
- IceRpcException if the transport reported an error.
- OperationCanceledException if cancellation was requested through the cancellation token.
Exceptions
- InvalidOperationException
Thrown if the connection is not connected, already shut down or shutting down, or a write operation is in progress.
- ObjectDisposedException
Thrown if the connection is disposed.
WriteAsync(ReadOnlySequence<byte>, CancellationToken)
Writes data over the connection.
ValueTask WriteAsync(ReadOnlySequence<byte> buffer, CancellationToken cancellationToken)
Parameters
bufferReadOnlySequence<byte>The buffer containing the data to write.
cancellationTokenCancellationTokenA cancellation token that receives the cancellation requests.
Returns
- ValueTask
A value task that completes successfully when the data is written successfully.
Remarks
The returned value task can also complete with one of the following exceptions:
- IceRpcException if the transport reported an error.
- OperationCanceledException if cancellation was requested through the cancellation token.
Exceptions
- ArgumentException
Thrown if
bufferis empty.- InvalidOperationException
Thrown if the connection is not connected, already shut down or shutting down, or a write operation is already in progress.
- ObjectDisposedException
Thrown if the connection is disposed.