diff options
Diffstat (limited to 'qtserialbluetooth.cpp')
| -rw-r--r-- | qtserialbluetooth.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/qtserialbluetooth.cpp b/qtserialbluetooth.cpp index 442702da7..6f93d8cab 100644 --- a/qtserialbluetooth.cpp +++ b/qtserialbluetooth.cpp @@ -234,7 +234,7 @@ static int qt_serial_read(serial_t *device, void* data, unsigned int size) unsigned int nbytes = 0; int rc; - while(nbytes < size) + while(nbytes < size && device->socket->state() == QBluetoothSocket::ConnectedState) { device->socket->waitForReadyRead(device->timeout); @@ -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; @@ -286,7 +293,7 @@ static int qt_serial_write(serial_t *device, const void* data, unsigned int size unsigned int nbytes = 0; int rc; - while(nbytes < size) + while(nbytes < size && device->socket->state() == QBluetoothSocket::ConnectedState) { device->socket->waitForBytesWritten(device->timeout); |