From ae1a2b8b0149b473190623910a98096c3f117328 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 26 Feb 2014 13:45:15 +0100 Subject: Utilize new QBluetoothSocket::OperationError on QNX and Bluez Task-number: QTBUG-36817 Change-Id: I17f7d57537f7f1a5cedd01ce6043cfd6aac26db4 Reviewed-by: Nedim Hadzic Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothsocket_bluez.cpp | 19 +++++++++++++++++-- src/bluetooth/qbluetoothsocket_qnx.cpp | 17 ++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/bluetooth/qbluetoothsocket_bluez.cpp b/src/bluetooth/qbluetoothsocket_bluez.cpp index 232f8942..825c6cd7 100644 --- a/src/bluetooth/qbluetoothsocket_bluez.cpp +++ b/src/bluetooth/qbluetoothsocket_bluez.cpp @@ -442,6 +442,13 @@ quint16 QBluetoothSocketPrivate::peerPort() const qint64 QBluetoothSocketPrivate::writeData(const char *data, qint64 maxSize) { Q_Q(QBluetoothSocket); + + if (state != QBluetoothSocket::ConnectedState) { + errorString = QBluetoothSocket::tr("Cannot write while not connected"); + q->setSocketError(QBluetoothSocket::OperationError); + return -1; + } + if (q->openMode() & QIODevice::Unbuffered) { if (::write(socket, data, maxSize) != maxSize) { errorString = QBluetoothSocket::tr("Network Error"); @@ -471,11 +478,19 @@ qint64 QBluetoothSocketPrivate::writeData(const char *data, qint64 maxSize) qint64 QBluetoothSocketPrivate::readData(char *data, qint64 maxSize) { - if(!buffer.isEmpty()){ + Q_Q(QBluetoothSocket); + + if (state != QBluetoothSocket::ConnectedState) { + errorString = QBluetoothSocket::tr("Cannot read while not connected"); + q->setSocketError(QBluetoothSocket::OperationError); + return -1; + } + + if (!buffer.isEmpty()) { int i = buffer.read(data, maxSize); return i; - } + return 0; } diff --git a/src/bluetooth/qbluetoothsocket_qnx.cpp b/src/bluetooth/qbluetoothsocket_qnx.cpp index e8350723..f60ba97a 100644 --- a/src/bluetooth/qbluetoothsocket_qnx.cpp +++ b/src/bluetooth/qbluetoothsocket_qnx.cpp @@ -214,6 +214,13 @@ quint16 QBluetoothSocketPrivate::peerPort() const qint64 QBluetoothSocketPrivate::writeData(const char *data, qint64 maxSize) { Q_Q(QBluetoothSocket); + + if (state != QBluetoothSocket::ConnectedState) { + errorString = QBluetoothSocket::tr("Cannot write while not connected"); + q->setSocketError(QBluetoothSocket::OperationError); + return -1; + } + if (q->openMode() & QIODevice::Unbuffered) { if (::write(socket, data, maxSize) != maxSize) { errorString = QBluetoothSocket::tr("Network Error"); @@ -242,7 +249,15 @@ qint64 QBluetoothSocketPrivate::writeData(const char *data, qint64 maxSize) qint64 QBluetoothSocketPrivate::readData(char *data, qint64 maxSize) { - if (!buffer.isEmpty()){ + Q_Q(QBluetoothSocket); + + if (state != QBluetoothSocket::ConnectedState) { + errorString = QBluetoothSocket::tr("Cannot read while not connected"); + q->setSocketError(QBluetoothSocket::OperationError); + return -1; + } + + if (!buffer.isEmpty()) { int i = buffer.read(data, maxSize); return i; } -- cgit v1.2.3