qtbluetooth: add a read timeout

This adds a read timeout to the qt serial bluetooth code. This is needed
for error handling and error recovery purposes.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Anton Lundin 2015-09-22 23:33:14 +02:00 committed by Dirk Hohndel
parent 34da4801f4
commit 8417e84e82

View file

@ -248,8 +248,15 @@ static int qt_serial_read(serial_t *device, void* data, unsigned int size)
} else if (rc == 0) {
// Wait until the device is available for read operations
QEventLoop loop;
QTimer timer;
timer.setSingleShot(true);
loop.connect(&timer, SIGNAL(timeout()), SLOT(quit()));
loop.connect(device->socket, SIGNAL(readyRead()), SLOT(quit()));
timer.start(device->timeout);
loop.exec();
if (!timer.isActive())
return nbytes;
}
nbytes += rc;