From b7c40964db93eb3df46b6aa8a5fb66ffbbc84dcc Mon Sep 17 00:00:00 2001 From: Pieter P Date: Sun, 1 Sep 2024 16:19:21 +0200 Subject: [PATCH] Check USB connection status while writing --- src/MIDI_Interfaces/USBMIDI/LowLevel/BulkTX.ipp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/MIDI_Interfaces/USBMIDI/LowLevel/BulkTX.ipp b/src/MIDI_Interfaces/USBMIDI/LowLevel/BulkTX.ipp index 673efbf0ea..a4a691a20d 100644 --- a/src/MIDI_Interfaces/USBMIDI/LowLevel/BulkTX.ipp +++ b/src/MIDI_Interfaces/USBMIDI/LowLevel/BulkTX.ipp @@ -51,7 +51,14 @@ void BulkTX::write( return; } const uint32_t *end = msgs + num_msgs; - while (msgs != end) msgs += write_impl(msgs, end - msgs); + while (msgs != end) { + auto sent = write_impl(msgs, end - msgs); + if (sent == 0 && !wait_connect()) { + writing.error.fetch_add(end - msgs, mo_rlx); + return; + } + msgs += sent; + } } template