[PATCH 2/2] qtbluetooth: Break read/write loops on bad state

Anton Lundin glance at acc.umu.se
Tue Sep 22 14:33:15 PDT 2015


This introduces a state check to only continue to try to read/write from
the bluetooth device while its in a sane state.

Signed-off-by: Anton Lundin <glance at acc.umu.se>
---
 qtserialbluetooth.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/qtserialbluetooth.cpp b/qtserialbluetooth.cpp
index ee8b2b7..6f93d8c 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);
 
@@ -293,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);
 
-- 
2.1.4



More information about the subsurface mailing list