summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorChris Adams <chris.adams@qinetic.com.au>2023-05-26 00:11:53 +1000
committerMaurice Kalinowski <maurice.kalinowski@qt.io>2023-05-26 06:23:14 +0000
commitc9c49bdf474bbeaf9df7f688753e694fe07b4e90 (patch)
treec508c660e1fa8cc45a8100e57833ed38d90f3082 /examples
parentdcc684359d979aa08da3ef00014c7e633ca4551c (diff)
Examples: websocket IO device must be sequential
When using a websocket as the underlying IO device we must specify that the device is sequential, to avoid spurious protocol violation condition when packets are split across websocket frame boundaries. The standard specifically states: "The receiver MUST NOT assume that MQTT Control Packets are aligned on WebSocket frame boundaries." New MQTT brokers like FlashMQ rely on well-behaved receivers. Change-Id: Ia8e7fb0cf1cc518b364625b1955fb6b9ee44b7ef Pick-to: 6.5 Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/mqtt/websocketsubscription/websocketiodevice.cpp10
-rw-r--r--examples/mqtt/websocketsubscription/websocketiodevice.h3
2 files changed, 13 insertions, 0 deletions
diff --git a/examples/mqtt/websocketsubscription/websocketiodevice.cpp b/examples/mqtt/websocketsubscription/websocketiodevice.cpp
index 479688a..ce01e48 100644
--- a/examples/mqtt/websocketsubscription/websocketiodevice.cpp
+++ b/examples/mqtt/websocketsubscription/websocketiodevice.cpp
@@ -14,6 +14,16 @@ WebSocketIODevice::WebSocketIODevice(QObject *parent)
connect(&m_socket, &QWebSocket::binaryMessageReceived, this, &WebSocketIODevice::handleBinaryMessage);
}
+bool WebSocketIODevice::isSequential() const
+{
+ return true;
+}
+
+qint64 WebSocketIODevice::bytesAvailable() const
+{
+ return static_cast<qint64>(m_buffer.size()) + QIODevice::bytesAvailable();
+}
+
bool WebSocketIODevice::open(QIODevice::OpenMode mode)
{
QWebSocketHandshakeOptions options;
diff --git a/examples/mqtt/websocketsubscription/websocketiodevice.h b/examples/mqtt/websocketsubscription/websocketiodevice.h
index 05dbfa1..16071bf 100644
--- a/examples/mqtt/websocketsubscription/websocketiodevice.h
+++ b/examples/mqtt/websocketsubscription/websocketiodevice.h
@@ -13,6 +13,9 @@ class WebSocketIODevice : public QIODevice
public:
WebSocketIODevice(QObject *parent = nullptr);
+ bool isSequential() const override;
+ qint64 bytesAvailable() const override;
+
bool open(OpenMode mode) override;
void close() override;