Class BaseBluetoothRemoteL2CapChannel
Abstract base class for platform-specific L2CAP channel implementations. Provides common functionality for opening, closing, reading, and writing to L2CAP channels.
public abstract class BaseBluetoothRemoteL2CapChannel : BaseBindableObject, IBluetoothRemoteL2CapChannel, INotifyPropertyChanged, IAsyncDisposable
- Inheritance
-
BaseBluetoothRemoteL2CapChannel
- Implements
- Inherited Members
Constructors
BaseBluetoothRemoteL2CapChannel(IBluetoothRemoteDevice, int, L2CapChannelOptions?, ILogger?)
Initializes a new instance of the BaseBluetoothRemoteL2CapChannel class with options.
protected BaseBluetoothRemoteL2CapChannel(IBluetoothRemoteDevice parentDevice, int psm, L2CapChannelOptions? options, ILogger? logger = null)
Parameters
parentDeviceIBluetoothRemoteDeviceThe Bluetooth device this channel belongs to.
psmintThe Protocol/Service Multiplexer (PSM) for this channel.
optionsL2CapChannelOptionsOptional L2CAP channel configuration options.
loggerILoggerOptional logger for logging channel operations.
Exceptions
- ArgumentNullException
Thrown when device is null.
- ArgumentOutOfRangeException
Thrown when PSM is not positive.
BaseBluetoothRemoteL2CapChannel(IBluetoothRemoteDevice, int, ILogger?)
Initializes a new instance of the BaseBluetoothRemoteL2CapChannel class.
protected BaseBluetoothRemoteL2CapChannel(IBluetoothRemoteDevice parentDevice, int psm, ILogger? logger = null)
Parameters
parentDeviceIBluetoothRemoteDeviceThe Bluetooth device this channel belongs to.
psmintThe Protocol/Service Multiplexer (PSM) for this channel.
loggerILoggerOptional logger for logging channel operations.
Exceptions
- ArgumentNullException
Thrown when device is null.
- ArgumentOutOfRangeException
Thrown when PSM is not positive.
Properties
Device
Gets the device associated with this L2CAP channel.
public IBluetoothRemoteDevice Device { get; }
Property Value
IsOpen
Gets a value indicating whether the channel is currently open.
public bool IsOpen { get; protected set; }
Property Value
Mtu
Gets or sets the negotiated MTU for this channel. Updated after the channel is opened.
public int Mtu { get; protected set; }
Property Value
Options
Gets the L2CAP channel options.
protected L2CapChannelOptions Options { get; }
Property Value
Psm
Gets the Protocol Service Multiplexer (PSM) value for this channel.
public int Psm { get; }
Property Value
Methods
CloseAsync(TimeSpan?, CancellationToken)
Closes the L2CAP channel asynchronously.
public ValueTask CloseAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
timeoutTimeSpan?The timeout for this operation.
cancellationTokenCancellationTokenA cancellation token to cancel this operation.
Returns
- ValueTask
A task that represents the asynchronous close operation.
Exceptions
- InvalidOperationException
Thrown when the channel is not open.
- TimeoutException
Thrown when the operation times out.
- OperationCanceledException
Thrown when the operation is cancelled.
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.
DisposeAsyncCore()
Performs asynchronous cleanup of resources used by this channel.
protected virtual ValueTask DisposeAsyncCore()
Returns
- ValueTask
A task representing the asynchronous dispose operation.
NativeCloseAsync()
Platform-specific implementation for closing the L2CAP channel.
protected abstract ValueTask NativeCloseAsync()
Returns
- ValueTask
A task representing the asynchronous operation.
NativeOpenAsync()
Platform-specific implementation for opening the L2CAP channel.
protected abstract ValueTask NativeOpenAsync()
Returns
- ValueTask
A task representing the asynchronous operation.
NativeReadAsync(Memory<byte>)
Platform-specific implementation for reading data from the L2CAP channel.
protected abstract ValueTask<int> NativeReadAsync(Memory<byte> buffer)
Parameters
Returns
NativeWriteAsync(ReadOnlyMemory<byte>)
Platform-specific implementation for writing data to the L2CAP channel.
protected abstract ValueTask NativeWriteAsync(ReadOnlyMemory<byte> data)
Parameters
dataReadOnlyMemory<byte>The data to write.
Returns
- ValueTask
A task representing the asynchronous operation.
OnDataReceived(ReadOnlyMemory<byte>)
Raises the DataReceived event when data is received on the channel.
protected void OnDataReceived(ReadOnlyMemory<byte> data)
Parameters
dataReadOnlyMemory<byte>The data that was received.
OpenAsync(TimeSpan?, CancellationToken)
Opens the L2CAP channel asynchronously.
public ValueTask OpenAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
timeoutTimeSpan?The timeout for this operation.
cancellationTokenCancellationTokenA cancellation token to cancel this operation.
Returns
- ValueTask
A task that represents the asynchronous open operation.
Exceptions
- InvalidOperationException
Thrown when the channel is already open.
- TimeoutException
Thrown when the operation times out.
- OperationCanceledException
Thrown when the operation is cancelled.
ReadAsync(Memory<byte>, TimeSpan?, CancellationToken)
Reads data from the L2CAP channel asynchronously.
public ValueTask<int> ReadAsync(Memory<byte> buffer, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
bufferMemory<byte>The buffer to read data into.
timeoutTimeSpan?The timeout for this operation.
cancellationTokenCancellationTokenA cancellation token to cancel this operation.
Returns
- ValueTask<int>
A task that represents the asynchronous read operation. The task result contains the number of bytes read.
WriteAsync(ReadOnlyMemory<byte>, TimeSpan?, CancellationToken)
Writes data to the L2CAP channel asynchronously.
public ValueTask WriteAsync(ReadOnlyMemory<byte> data, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
dataReadOnlyMemory<byte>The data to write.
timeoutTimeSpan?The timeout for this operation.
cancellationTokenCancellationTokenA cancellation token to cancel this operation.
Returns
- ValueTask
A task that represents the asynchronous write operation.
Exceptions
- ArgumentNullException
Thrown when
datais null.- InvalidOperationException
Thrown when the channel is not open.
- TimeoutException
Thrown when the operation times out.
- OperationCanceledException
Thrown when the operation is cancelled.
Events
DataReceived
Event raised when data is received on the channel.
public event EventHandler<L2CapDataReceivedEventArgs>? DataReceived