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>
This commit is contained in:
Lubomir I. Ivanov 2020-01-27 05:35:35 +02:00 committed by Dirk Hohndel
parent aceb8a547f
commit e69f5c4e28

View file

@ -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;
}