aboutsummaryrefslogtreecommitdiffstats
path: root/src/direct_bt
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-06-24 23:29:40 +0200
committerSven Gothel <[email protected]>2020-06-24 23:29:40 +0200
commit8693aa160c4c4f7b72c34c99e7550a224a856644 (patch)
tree838af3484bc253279bb2140468a6cd1e3617b7f5 /src/direct_bt
parentbb5e23e940be93b10f983a97c6b3ffb04ea6d729 (diff)
L2CAPComm: connect/disconnect: Don't fail if connect and _dd doesn't match -> intended
It is intended to allow e.g. disconnect from multiple threads at the 'same time', hence we utilize the 'atomic<bool> connect' to bail out early if already called. In this case and if _dd (l2cap device descriptor) is still valid, a concurrent thread is still about to close the _dd.
Diffstat (limited to 'src/direct_bt')
-rw-r--r--src/direct_bt/L2CAPComm.cpp19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/direct_bt/L2CAPComm.cpp b/src/direct_bt/L2CAPComm.cpp
index bdaa9265..908e5786 100644
--- a/src/direct_bt/L2CAPComm.cpp
+++ b/src/direct_bt/L2CAPComm.cpp
@@ -103,15 +103,12 @@ bool L2CAPComm::connect() {
if( !isConnected.compare_exchange_strong(expConn, true) ) {
// already connected
DBG_PRINT("L2CAPComm::connect: Already connected: %s, dd %d, %s, psm %u, cid %u, pubDevice %d",
- getStateString(), _dd.load(), device->getAddress().toString().c_str(), psm, cid, pubaddr);
- if( 0 > _dd ) {
- throw InternalError("connected but _dd "+std::to_string(_dd.load())+" < 0", E_FILE_LINE);
- }
+ getStateString().c_str(), _dd.load(), device->getAddress().toString().c_str(), psm, cid, pubaddr);
return true;
}
hasIOError = false;
DBG_PRINT("L2CAPComm::connect: Start: %s, dd %d, %s, psm %u, cid %u, pubDevice %d",
- getStateString(), _dd.load(), device->getAddress().toString().c_str(), psm, cid, pubaddr);
+ getStateString().c_str(), _dd.load(), device->getAddress().toString().c_str(), psm, cid, pubaddr);
sockaddr_l2 req;
int err, res;
@@ -122,9 +119,6 @@ bool L2CAPComm::connect() {
goto failure; // open failed
}
- DBG_PRINT("L2CAPComm::connect: Connect %s, psm %u, cid %u, pubDevice %d",
- device->getAddress().toString().c_str(), psm, cid, pubaddr);
-
tid_connect = pthread_self(); // temporary safe tid to allow interruption
// actual request to connect to remote device
@@ -140,7 +134,7 @@ bool L2CAPComm::connect() {
res = ::connect(_dd, (struct sockaddr*)&req, sizeof(req));
DBG_PRINT("L2CAPComm::connect: Result %d, errno 0%X %s, %s",
- res, errno, strerror(errno), device->getAddress().toString().c_str());
+ res, errno, strerror(errno), device->getAddress().toString().c_str());
if( !res )
{
@@ -178,15 +172,12 @@ bool L2CAPComm::disconnect() {
bool expConn = true; // C++11, exp as value since C++20
if( !isConnected.compare_exchange_strong(expConn, false) ) {
DBG_PRINT("L2CAPComm::disconnect: Not connected: %s, dd %d, %s, psm %u, cid %u, pubDevice %d",
- getStateString().c_str(), _dd.load(), device->getAddress().toString().c_str(), psm, cid, pubaddr);
- if( 0 <= _dd ) {
- throw InternalError("!connected but _dd "+std::to_string(_dd.load())+" >= 0", E_FILE_LINE);
- }
+ getStateString().c_str(), _dd.load(), device->getAddress().toString().c_str(), psm, cid, pubaddr);
return false;
}
hasIOError = false;
DBG_PRINT("L2CAPComm::disconnect: Start: %s, dd %d, %s, psm %u, cid %u, pubDevice %d",
- getStateString().c_str(), _dd.load(), device->getAddress().toString().c_str(), psm, cid, pubaddr);
+ getStateString().c_str(), _dd.load(), device->getAddress().toString().c_str(), psm, cid, pubaddr);
interruptFlag = true;
// interrupt L2CAP ::connect(..), avoiding prolonged hang