summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2020-01-27 05:35:35 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-01-27 09:51:31 -0800
commite69f5c4e28759d13541c1f35c321d25e2a10c5c3 (patch)
tree3cdfb0a2f88a4aef71089132782c954d32f7a472 /core
parentaceb8a547f1ea70b71ab609c6e406928dee74b88 (diff)
downloadsubsurface-e69f5c4e28759d13541c1f35c321d25e2a10c5c3.tar.gz
core/qtserialbluetooth.cpp: use QEventLoop for polling
The Qt docs here: https://doc.qt.io/qt-5/qbluetoothsocket.html#details and here: https://doc.qt.io/qt-5/qabstractsocket.html#waitForReadyRead say that waitForReadyRead() does not work for QBluetoothSocket and that it's flaky on Windows for the underlying QAbstractSocket. Use a QEventLoop and a QTimer to poll the readyRead() signal. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'core')
-rw-r--r--core/qtserialbluetooth.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/core/qtserialbluetooth.cpp b/core/qtserialbluetooth.cpp
index 9d79d863b..6b47524de 100644
--- a/core/qtserialbluetooth.cpp
+++ b/core/qtserialbluetooth.cpp
@@ -212,7 +212,16 @@ static dc_status_t qt_serial_poll(void *io, int timeout)
if (!device->socket)
return DC_STATUS_INVALIDARGS;
- if (device->socket->waitForReadyRead(timeout))
+
+ QEventLoop loop;
+ QTimer timer;
+ timer.setSingleShot(true);
+ loop.connect(&timer, SIGNAL(timeout()), SLOT(quit()));
+ loop.connect(device->socket, SIGNAL(readyRead()), SLOT(quit()));
+ timer.start(timeout);
+ loop.exec();
+
+ if (!timer.isActive())
return DC_STATUS_SUCCESS;
return DC_STATUS_TIMEOUT;
}