aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2020-03-13 12:57:15 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-14 11:34:46 -0700
commit5e89d81d9d6b8b1101b1482620b3f85968eb3b47 (patch)
tree984eb35e4d28c16b3904bb4b7f8ccdc3e862830f /core
parent4ee4bbdb58d7dabae1be1fa6e62622caa5a4fcbc (diff)
downloadsubsurface-5e89d81d9d6b8b1101b1482620b3f85968eb3b47.tar.gz
iostream: fix incorrect rfcomm error case when writing
This is the exact same case as the previous commit, just for the writing side. Once again, it's the subsurface rfcomm iostream code that can return DC_STATUS_SUCCESS with a byte count of zero when something goes wrong with the write. And once again, our libdivecomputer iostream code didn't try to be robust and protect itself from that case. The fix is equivalent, although slightly simpler, since the write side doesn't have the whole timeout issue. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'core')
-rw-r--r--core/qtserialbluetooth.cpp29
1 files changed, 12 insertions, 17 deletions
diff --git a/core/qtserialbluetooth.cpp b/core/qtserialbluetooth.cpp
index f6bbcafdf..1c0270ff9 100644
--- a/core/qtserialbluetooth.cpp
+++ b/core/qtserialbluetooth.cpp
@@ -172,32 +172,27 @@ static dc_status_t qt_serial_write(void *io, const void* data, size_t size, size
{
qt_serial_t *device = (qt_serial_t*) io;
- if (device == NULL || device->socket == NULL)
+ if (device == NULL || device->socket == NULL || !actual)
return DC_STATUS_INVALIDARGS;
- size_t nbytes = 0;
- int rc;
+ *actual = 0;
+ for (;;) {
+ int rc;
+
+ if (device->socket->state() != QBluetoothSocket::ConnectedState)
+ return DC_STATUS_IO;
- while(nbytes < size && device->socket->state() == QBluetoothSocket::ConnectedState)
- {
- rc = device->socket->write((char *) data + nbytes, size - nbytes);
+ rc = device->socket->write((char *) data, size);
if (rc < 0) {
if (errno == EINTR || errno == EAGAIN)
- continue; // Retry.
-
- return DC_STATUS_IO; // Something really bad happened :-(
- } else if (rc == 0) {
- break;
+ continue;
+ return DC_STATUS_IO;
}
- nbytes += rc;
+ *actual = rc;
+ return rc ? DC_STATUS_SUCCESS : DC_STATUS_IO;
}
-
- if (actual)
- *actual = nbytes;
-
- return DC_STATUS_SUCCESS;
}
static dc_status_t qt_serial_poll(void *io, int timeout)