Fix: corebluetooth write without response #441
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
I've run into issue with
WriteType::WithoutResponse
on macos.im trying to send ~2MB of data in shortest time possible however corebluetooth keeps loosing the packects shortly after the start.
while looking up for solutions in other bluetooth libs i came across this technical document and this guide
i belive the ultimate fix would be to use
peripheral.peripheralIsReadyToSendWriteWithoutResponse
as described in the guide but i dont see a easy way how to implement this method (missing CBPeripheralDelegate reference)so i decided to use attempts loop and check every 15ms (
Interval Min
stated in the document) if it is safe to send another packet. the loop ends if true or after 100 retries (1500ms <connSupervisionTimeout
stated in the document)The only problem is that
canSendWriteWithoutResponse
was introduced in macos 11.0 (Big Sur) but it behaves unreliably until 11.2 - returning false until the first write is performed. That is why i've addedcan_send_without_response_supported
flag which is set from theNSProcessInfo
.if you dont care about older OS releases (Big Sur was released in november 2020) i can drop the the second commit