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:
- The ConnectAsync(CancellationToken) method is called first and once. No other methods are called until it completes.
- The ReadAsync(Memory<byte>, CancellationToken) method is never called concurrently.
- The WriteAsync(ReadOnlySequence<byte>, CancellationToken) method is never called concurrently.
- The ReadAsync(Memory<byte>, CancellationToken) and WriteAsync(ReadOnlySequence<byte>, CancellationToken) methods can be called concurrently.
- The ReadAsync(Memory<byte>, CancellationToken) and ShutdownWriteAsync(CancellationToken) methods can be called concurrently.
- The ShutdownWriteAsync(CancellationToken) method is called once but not while a WriteAsync(ReadOnlySequence<byte>, CancellationToken) call is in progress.
- The WriteAsync(ReadOnlySequence<byte>, CancellationToken) is never called after a ShutdownWriteAsync(CancellationToken) call.
- The Dispose() method is called after the tasks returned by other methods have completed. It can be called multiple times but not concurrently.
Methods
ConnectAsync(CancellationToken)
Connects this connection.
Task<TransportConnectionInformation> ConnectAsync(CancellationToken cancellationToken)
Parameters
cancellationToken
CancellationTokenA cancellation token that receives the cancellation requests.
Returns
- Task<TransportConnectionInformation>
A task that completes successfully with transport connection information when the connection is established. This 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
buffer
Memory<byte>A buffer that receives the data read from the connection.
cancellationToken
CancellationTokenA 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 is0
when no data is available and the peer has called ShutdownWriteAsync(CancellationToken); otherwise, it is always greater than0
. This 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
buffer
is 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
cancellationToken
CancellationTokenA cancellation token that receives the cancellation requests.
Returns
- Task
A task that completes successfully when the shutdown completes successfully. This 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
buffer
ReadOnlySequence<byte>The buffer containing the data to write.
cancellationToken
CancellationTokenA cancellation token that receives the cancellation requests.
Returns
- ValueTask
A value task that completes successfully when the data is written successfully. This 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
buffer
is 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.