diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index 9435d479..5cb18678 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -3034,7 +3034,15 @@ void QLowEnergyControllerPrivate::handleConnectionRequest() qCWarning(QT_BT_BLUEZ) << "Received client connection, but no connection complete event"; closeServerSocket(); + + if (l2cpSocket) { + // old instance .. maybe relese some resources ?? + delete l2cpSocket; + l2cpSocket = nullptr; + } l2cpSocket = new QBluetoothSocket(QBluetoothServiceInfo::L2capProtocol, this); + int tmp_fd = l2cpSocket->socketDescriptor(); // tmp file descriptor, it will be overwritten with: l2cpSocket->setSocketDescriptor + connect(l2cpSocket, &QBluetoothSocket::disconnected, this, &QLowEnergyControllerPrivate::l2cpDisconnected); connect(l2cpSocket, static_cast @@ -3047,6 +3055,12 @@ void QLowEnergyControllerPrivate::handleConnectionRequest() restoreClientConfigurations(); loadSigningDataIfNecessary(RemoteSigningKey); + qCDebug(QT_BT_BLUEZ) << __FUNCTION__ << "open client socket: " << l2cpSocket->socketDescriptor(); + if (0 < tmp_fd && (tmp_fd != l2cpSocket->socketDescriptor())) + qCDebug(QT_BT_BLUEZ) << __FUNCTION__ << "close old socket: " << tmp_fd; + if (close(tmp_fd) < 0) // close unused descriptor + qCWarning(QT_BT_BLUEZ) << __FUNCTION__ << "close client socket error: " << qt_error_string(errno); + Q_Q(QLowEnergyController); setState(QLowEnergyController::ConnectedState); emit q->connected(); @@ -3057,7 +3071,9 @@ void QLowEnergyControllerPrivate::closeServerSocket() if (!serverSocketNotifier) return; serverSocketNotifier->disconnect(); - close(serverSocketNotifier->socket()); + qCDebug(QT_BT_BLUEZ) << __FUNCTION__ << "close socket: " << serverSocketNotifier->socket(); + if (close(serverSocketNotifier->socket()) < 0) + qCWarning(QT_BT_BLUEZ) << __FUNCTION__ << "close socket error: " << qt_error_string(errno); serverSocketNotifier->deleteLater(); serverSocketNotifier = nullptr; }