Class StreamDeviceConnection
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
streamStreamThe open stream to the device.
framerIDeviceFramerHow the stream's bytes become frames.
remoteAddressstringThe address the stream reached, for errors and the trace.
maxFrameBytesintThe most bytes a receive buffers before it fails without a whole frame.
ownerIAsyncDisposableWhat 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
Properties
RemoteAddress
Gets the address the connection reached, when the transport can report it.
public string? RemoteAddress { get; }
Property Value
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
cancellationTokenCancellationToken
Returns
SendAsync(DeviceFrame, CancellationToken)
Sends one frame.
public ValueTask SendAsync(DeviceFrame frame, CancellationToken cancellationToken = default)
Parameters
frameDeviceFramecancellationTokenCancellationToken