summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-10-15 00:32:53 +0200
committerSven Gothel <[email protected]>2020-10-15 00:32:53 +0200
commit24a1fc01ea95e1a5612312a17388e7bbf2728d93 (patch)
tree456a4736d1afb6aaa328cf667c4aa6d3cd743de5 /src
parent9a03a1cf1a508c1a9eb620d9d2c261acbd283377 (diff)
HCIHandler::clearTrackerConnections(): Clear tracked connections on close(), reset() and stopAdapter() (resetAdapter()).
Diffstat (limited to 'src')
-rw-r--r--src/direct_bt/HCIHandler.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/direct_bt/HCIHandler.cpp b/src/direct_bt/HCIHandler.cpp
index 81fb4636..dd8460b4 100644
--- a/src/direct_bt/HCIHandler.cpp
+++ b/src/direct_bt/HCIHandler.cpp
@@ -153,6 +153,11 @@ HCIConnectionRef HCIHandler::removeTrackerConnection(const uint16_t handle) noex
return nullptr;
}
+void HCIHandler::clearTrackerConnections() noexcept {
+ const std::lock_guard<std::recursive_mutex> lock(mtx_connectionList); // RAII-style acquire and relinquish via destructor
+ connectionList.clear();
+}
+
MgmtEvent::Opcode HCIHandler::translate(HCIEventType evt, HCIMetaEventType met) noexcept {
if( HCIEventType::LE_META == evt ) {
switch( met ) {
@@ -526,6 +531,7 @@ void HCIHandler::close() noexcept {
// not open
DBG_PRINT("HCIHandler::close: Not open");
clearAllMgmtEventCallbacks();
+ clearTrackerConnections();
comm.close();
return;
}
@@ -533,6 +539,7 @@ void HCIHandler::close() noexcept {
const std::lock_guard<std::recursive_mutex> lock(mtx); // RAII-style acquire and relinquish via destructor
DBG_PRINT("HCIHandler::close: Start");
clearAllMgmtEventCallbacks();
+ clearTrackerConnections();
// Interrupt HCIHandler's HCIComm::read(..), avoiding prolonged hang
// and pull all underlying hci read operations!
@@ -582,17 +589,23 @@ HCIStatusCode HCIHandler::startAdapter() {
}
HCIStatusCode HCIHandler::stopAdapter() {
+ HCIStatusCode status;
#ifdef __linux__
int res;
if( ( res = ioctl(comm.getSocketDescriptor(), HCIDEVDOWN, dev_id) ) < 0) {
ERR_PRINT("HCIHandler::stopAdapter(dev_id %d): FAILED: %d", dev_id, res);
- return HCIStatusCode::INTERNAL_FAILURE;
+ status = HCIStatusCode::INTERNAL_FAILURE;
+ } else {
+ status = HCIStatusCode::SUCCESS;
}
- return HCIStatusCode::SUCCESS;
#else
#warning add implementation
+ status = HCIStatusCode::INTERNAL_FAILURE;
#endif
- return HCIStatusCode::INTERNAL_FAILURE;
+ if( HCIStatusCode::SUCCESS == status ) {
+ clearTrackerConnections();
+ }
+ return status;
}
HCIStatusCode HCIHandler::resetAdapter() {
@@ -618,7 +631,11 @@ HCIStatusCode HCIHandler::reset() noexcept {
if( nullptr == ev || nullptr == ev_cc ) {
return HCIStatusCode::INTERNAL_TIMEOUT; // timeout
}
- return ev_cc->getReturnStatus(0);
+ const HCIStatusCode status = ev_cc->getReturnStatus(0);
+ if( HCIStatusCode::SUCCESS == status ) {
+ clearTrackerConnections();
+ }
+ return status;
}
HCIStatusCode HCIHandler::getLocalVersion(HCILocalVersion &version) noexcept {