embassy-rs / nrf-softdevice

Apache License 2.0
256 stars 76 forks source link

L2CAP Channel API Design Flaws #206

Open kext opened 7 months ago

kext commented 7 months ago

Right now ble::l2cap::Channel is Clone and the rx, tx and try_tx methods take self as shared reference.

I think this should be changed to mutable references and removing Clone because it is not possible to use a channel in two different tasks without triggering a panic in the long run. Doing that results in "Multiple tasks waiting on same portal". I tried having one task read from the channel and the other write to it.

To support that use case maybe we should implement a split method to split the channel into a reading and a writing half.

In my case I worked around that issue by using two different channels, one for reading and one for writing, but this requires more resources for the softdevice.

kext commented 7 months ago

Turns out this doesn't help at all. Since the portal is associated with the connection instead of the channel the current API design does not allow using even multiple independent channels at the same time.

Right now only the following works: Waiting for data on only one channel at a time with rx and only using try_tx or ensuring that tx never overlaps with rx.