summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothserver_android.cpp
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-02-20 11:39:09 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-27 13:00:40 +0100
commit9d6057f3fa0b51ee2d36ad931072d2a3c816d0a6 (patch)
treeabd3b315377daadd57f2c5356c5512b1020fe349 /src/bluetooth/qbluetoothserver_android.cpp
parentae1a2b8b0149b473190623910a98096c3f117328 (diff)
Android: Fix crash in QBluetoothServer::close()
Java's BluetoothSocketServer.accept() is meant to be interrupted via BluetoothSocketServer.close(). Unfortunately if the surrounding thread is a QThread the returning accept call crashes the thread. This does not happen if it is a Java Thread. This commit changes the server's private backend to a Java thread. Task-number: QTBUG-36754 Change-Id: I5aacc5444bbcd1275a11743b6aa04d2b11a5b22b Reviewed-by: Nedim Hadzic <nedimhadzija@gmail.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Diffstat (limited to 'src/bluetooth/qbluetoothserver_android.cpp')
-rw-r--r--src/bluetooth/qbluetoothserver_android.cpp42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/bluetooth/qbluetoothserver_android.cpp b/src/bluetooth/qbluetoothserver_android.cpp
index a2d08757..c7c798d3 100644
--- a/src/bluetooth/qbluetoothserver_android.cpp
+++ b/src/bluetooth/qbluetoothserver_android.cpp
@@ -59,8 +59,8 @@ QBluetoothServerPrivate::QBluetoothServerPrivate(QBluetoothServiceInfo::Protocol
: socket(0),maxPendingConnections(1), securityFlags(QBluetooth::NoSecurity), serverType(sType),
m_lastError(QBluetoothServer::NoError)
{
- thread = new ServerAcceptanceThread();
- thread->setMaxPendingConnections(maxPendingConnections);
+ thread = new ServerAcceptanceThread();
+ thread->setMaxPendingConnections(maxPendingConnections);
}
QBluetoothServerPrivate::~QBluetoothServerPrivate()
@@ -71,10 +71,6 @@ QBluetoothServerPrivate::~QBluetoothServerPrivate()
__fakeServerPorts.remove(this);
- if (thread->isRunning()) {
- thread->stop();
- thread->wait();
- }
thread->deleteLater();
thread = 0;
}
@@ -82,33 +78,33 @@ QBluetoothServerPrivate::~QBluetoothServerPrivate()
bool QBluetoothServerPrivate::initiateActiveListening(
const QBluetoothUuid& uuid, const QString &serviceName)
{
- Q_UNUSED(uuid);
- Q_UNUSED(serviceName);
qCDebug(QT_BT_ANDROID) << "Initiate active listening" << uuid.toString() << serviceName;
if (uuid.isNull() || serviceName.isEmpty())
return false;
//no change of SP profile details -> do nothing
- if (uuid == m_uuid && serviceName == m_serviceName)
+ if (uuid == m_uuid && serviceName == m_serviceName && thread->isRunning())
return true;
m_uuid = uuid;
m_serviceName = serviceName;
thread->setServiceDetails(m_uuid, m_serviceName, securityFlags);
- Q_ASSERT(!thread->isRunning());
- thread->start();
- Q_ASSERT(thread->isRunning());
+ thread->run();
+ if (!thread->isRunning())
+ return false;
return true;
}
bool QBluetoothServerPrivate::deactivateActiveListening()
{
- thread->stop();
- thread->wait();
-
+ if (isListening()) {
+ //suppress last error signal due to intended closure
+ thread->disconnect();
+ thread->stop();
+ }
return true;
}
@@ -121,12 +117,12 @@ void QBluetoothServer::close()
{
Q_D(QBluetoothServer);
- d->thread->stop();
- d->thread->wait();
-
- if (d->thread)
- d->thread->disconnect();
__fakeServerPorts.remove(d);
+ if (d->thread->isRunning()) {
+ //suppress last error signal due to intended closure
+ d->thread->disconnect();
+ d->thread->stop();
+ }
}
bool QBluetoothServer::listen(const QBluetoothAddress &localAdapter, quint16 port)
@@ -202,7 +198,11 @@ bool QBluetoothServer::listen(const QBluetoothAddress &localAdapter, quint16 por
return false;
}
- connect(d->thread, SIGNAL(newConnection()), this, SIGNAL(newConnection()));
+ connect(d->thread, SIGNAL(newConnection()),
+ this, SIGNAL(newConnection()));
+ connect(d->thread, SIGNAL(error(QBluetoothServer::Error)),
+ this, SIGNAL(error(QBluetoothServer::Error)), Qt::QueuedConnection);
+
return true;
}