diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-02-04 13:43:57 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-07 12:59:57 +0100 |
commit | 85e9ce386d2d931617f3c0d76acd4ca4165cb81d (patch) | |
tree | 404fd9907a34f62801c918195b41c8816d23fdda /src/bluetooth/qbluetoothserver_bluez.cpp | |
parent | 477d9f450a1e9767dbf10f4c040e994231674a1f (diff) |
QBluetoothServer fixes
1.) If QBluetoothServer::listen(QBluetoothUuid,QString) fails during
service registration we have to ensure that the Server doesn't remain
in listening state.
2.) 29de876f55dc96748fdca8dd3fef0c873791796f sets the socket descriptor
to -1 when closing the QBluetoothSocket. QBluetothServer treats a value
of -1 as error and aborts any call to listen(). This implies that any
call to listen() after the first close() would always fail. This patch
adds some redundancy and first tries to recreate the socket and only if
the re-creation failed exists with an error.
3.) Catch case when user calls listen() on an already listening server.
Documentation has been updated to document the behavior.
Change-Id: I2df13500e74a9741017f7404f0e0c477c96d5356
Reviewed-by: Aaron McCarthy <mccarthy.aaron@gmail.com>
Diffstat (limited to 'src/bluetooth/qbluetoothserver_bluez.cpp')
-rw-r--r-- | src/bluetooth/qbluetoothserver_bluez.cpp | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/bluetooth/qbluetoothserver_bluez.cpp b/src/bluetooth/qbluetoothserver_bluez.cpp index 0b504d9a..8acd8e20 100644 --- a/src/bluetooth/qbluetoothserver_bluez.cpp +++ b/src/bluetooth/qbluetoothserver_bluez.cpp @@ -105,11 +105,32 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port) { Q_D(QBluetoothServer); + if (d->socket->state() == QBluetoothSocket::ListeningState) { + qCWarning(QT_BT_BLUEZ) << "Socket already in listen mode, close server first"; + return false; //already listening, nothing to do + } + int sock = d->socket->socketDescriptor(); if (sock < 0) { - d->m_lastError = InputOutputError; - emit error(d->m_lastError); - return false; + /* Negative socket descriptor is not always an error case + * Another cause could be a call to close()/abort() + * Check whether we can recover by re-creating the socket + * we should really call Bluez::QBluetoothSocketPrivate::ensureNativeSocket + * but a re-creation of the socket will do as well. + */ + + delete d->socket; + if (serverType() == QBluetoothServiceInfo::RfcommProtocol) + d->socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol); + else + d->socket = new QBluetoothSocket(QBluetoothServiceInfo::L2capProtocol); + + sock = d->socket->socketDescriptor(); + if (sock < 0) { + d->m_lastError = InputOutputError; + emit error(d->m_lastError); + return false; + } } if (d->serverType == QBluetoothServiceInfo::RfcommProtocol) { |