Table of Contents

Interface IMultiplexedStreamWriter

Namespace
IceRpc.Transports
Assembly
IceRpc.dll

Writes bytes to the output of an IMultiplexedStream. The IBufferWriter<T> methods buffer bytes locally; the next WriteAsync(ReadOnlySequence<byte>, bool, CancellationToken) or CompleteAsync(CancellationToken) call sends them. IceRPC uses them to encode the request and response headers in place, so that a header rides in the same frame as the first payload bytes.

public interface IMultiplexedStreamWriter : IBufferWriter<byte>
Inherited Members

Remarks

The owner of this writer completes it with CompleteAsync(CancellationToken) or Abort(). An implementation makes both calls idempotent: a call after the writer is completed, by either method, does nothing.

Properties

UnflushedBytes

Gets the number of bytes buffered by the IBufferWriter<T> methods and not yet sent. IceRPC reads this property before and after encoding a header to compute the size of this header, since parts of the header can be written directly with the IBufferWriter<T> methods.

long UnflushedBytes { get; }

Property Value

long

The number of unflushed bytes.

Methods

Abort()

Aborts this writer: discards the unflushed bytes, closes the writes of the stream abruptly and releases the resources of this writer. This method never blocks.

void Abort()

CompleteAsync(CancellationToken)

Completes this writer gracefully: sends the unflushed bytes and any trailing bytes the implementation produces, closes the writes of the stream if a WriteAsync(ReadOnlySequence<byte>, bool, CancellationToken) call with endStream hasn't already, and releases the resources of this writer. The peer having closed its reads is not a failure.

ValueTask CompleteAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token that receives the cancellation requests.

Returns

ValueTask

A task that completes once the writer is completed.

Remarks

When this method fails, it aborts the writer before throwing: the caller does not need to call Abort() afterwards.

WriteAsync(ReadOnlySequence<byte>, bool, CancellationToken)

Sends the unflushed bytes followed by source.

ValueTask<WriteResult> WriteAsync(ReadOnlySequence<byte> source, bool endStream, CancellationToken cancellationToken)

Parameters

source ReadOnlySequence<byte>

The bytes to send.

endStream bool

When true, no more bytes will be written: the transport marks this frame as the last one of the stream, and later calls to WriteAsync(ReadOnlySequence<byte>, bool, CancellationToken) and Advance(int) throw InvalidOperationException.

cancellationToken CancellationToken

A cancellation token that receives the cancellation requests.

Returns

ValueTask<WriteResult>

Written, or WritesClosed when the peer has closed its reads and the bytes were discarded.

Remarks

When this method throws, the owner aborts the writer with Abort().

Exceptions

InvalidOperationException

Thrown when the writer is completed or a previous call to WriteAsync(ReadOnlySequence<byte>, bool, CancellationToken) had endStream set.