diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-02-26 13:45:15 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-27 10:38:30 +0100 |
commit | ae1a2b8b0149b473190623910a98096c3f117328 (patch) | |
tree | ff39958aea7e521bb1cec4be6b01ccc404845995 | |
parent | ed49b5cda6d84793ffdfd433b2d2cea0583de219 (diff) |
Utilize new QBluetoothSocket::OperationError on QNX and Bluez
Task-number: QTBUG-36817
Change-Id: I17f7d57537f7f1a5cedd01ce6043cfd6aac26db4
Reviewed-by: Nedim Hadzic <nedimhadzija@gmail.com>
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
-rw-r--r-- | src/bluetooth/qbluetoothsocket_bluez.cpp | 19 | ||||
-rw-r--r-- | 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; } |