From 8092f1bcf0edcdfb8cd3cb842bab2a23dce0fc2e Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 19 Sep 2020 03:44:07 +0200 Subject: GATTHandler::ioErrorCause: Use in l2capReaderThreadImpl (drop local var) and in sendWithReply(..) like in send(..) validateConnected() propagates l2capHasIOError -> has_ioerror We might just drop this atomic state, however, it is still relevant in validateConnected(), being called concurrently. It is cleared within disconnect(..). --- src/direct_bt/GATTHandler.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/direct_bt/GATTHandler.cpp b/src/direct_bt/GATTHandler.cpp index 14543e2f..18fa45b4 100644 --- a/src/direct_bt/GATTHandler.cpp +++ b/src/direct_bt/GATTHandler.cpp @@ -83,6 +83,7 @@ bool GATTHandler::validateConnected() noexcept { bool l2capHasIOError = l2cap.hasIOError(); if( has_ioerror || l2capHasIOError ) { + has_ioerror = true; // propagate l2capHasIOError -> has_ioerror ERR_PRINT("IOError state: GattHandler %s, l2cap %s: %s", getStateString().c_str(), l2cap.getStateString().c_str(), deviceString.c_str()); return false; @@ -176,7 +177,6 @@ bool GATTHandler::getSendIndicationConfirmation() noexcept { } void GATTHandler::l2capReaderThreadImpl() { - bool ioErrorCause = false; { const std::lock_guard lock(mtx_l2capReaderInit); // RAII-style acquire and relinquish via destructor l2capReaderShallStop = false; @@ -257,14 +257,14 @@ void GATTHandler::l2capReaderThreadImpl() { } else if( ETIMEDOUT != errno && !l2capReaderShallStop ) { // expected exits IRQ_PRINT("GATTHandler::l2capReaderThread: l2cap read error -> Stop"); l2capReaderShallStop = true; - ioErrorCause = true; + has_ioerror = true; } } WORDY_PRINT("l2capReaderThreadImpl Ended. Ring has %d entries flushed", attPDURing.getSize()); l2capReaderRunning = false; attPDURing.clear(); - disconnect(true /* disconnectDevice */, ioErrorCause); + disconnect(true /* disconnectDevice */, has_ioerror); } GATTHandler::GATTHandler(const std::shared_ptr &device) noexcept @@ -415,6 +415,7 @@ std::shared_ptr GATTHandler::sendWithReply(const AttPDUMsg & ms if( nullptr == res ) { errno = ETIMEDOUT; IRQ_PRINT("GATTHandler::sendWithReply: nullptr result (timeout %d): req %s to %s", timeout, msg.toString().c_str(), deviceString.c_str()); + has_ioerror = true; disconnect(true /* disconnectDevice */, true /* ioErrorCause */); throw BluetoothException("GATTHandler::sendWithReply: nullptr result (timeout "+std::to_string(timeout)+"): req "+msg.toString()+" to "+deviceString, E_FILE_LINE); } -- cgit v1.2.3