Class StreamDeviceConnection

Namespace
ProtoTest.Devices
Assembly
ProtoTest.Devices.dll

A device connection over a byte stream, framed by an IDeviceFramer. The TCP and serial transports use it, and a hand-written transport over any other stream (a Bluetooth socket, a USB bridge) can wrap its stream the same way.

public sealed class StreamDeviceConnection : IProtoDeviceConnection, IAsyncDisposable
Inheritance
StreamDeviceConnection
Implements
Inherited Members
Extension Methods

Constructors

StreamDeviceConnection(Stream, IDeviceFramer, string?, int, IAsyncDisposable?)

Wraps stream; disposing the connection disposes the stream and owner.

public StreamDeviceConnection(Stream stream, IDeviceFramer framer, string? remoteAddress = null, int maxFrameBytes = 1048576, IAsyncDisposable? owner = null)

Parameters

stream Stream

The open stream to the device.

framer IDeviceFramer

How the stream's bytes become frames.

remoteAddress string

The address the stream reached, for errors and the trace.

maxFrameBytes int

The most bytes a receive buffers before it fails without a whole frame.

owner IAsyncDisposable

What else to dispose with the stream, such as its socket or port.

Fields

DefaultMaxFrameBytes

The largest frame a connection buffers by default: 1 MiB.

public const int DefaultMaxFrameBytes = 1048576

Field Value

int

Properties

RemoteAddress

Gets the address the connection reached, when the transport can report it.

public string? RemoteAddress { get; }

Property Value

string

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 the next frame, or null when the device closed the connection.

public ValueTask<DeviceFrame?> ReceiveAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

ValueTask<DeviceFrame?>

SendAsync(DeviceFrame, CancellationToken)

Sends one frame.

public ValueTask SendAsync(DeviceFrame frame, CancellationToken cancellationToken = default)

Parameters

frame DeviceFrame
cancellationToken CancellationToken

Returns

ValueTask