From 02a9f1bf35d73eebbc1daf1fcd81a40e9b638589 Mon Sep 17 00:00:00 2001 From: amokfa Date: Tue, 12 Mar 2024 09:18:22 +0530 Subject: [PATCH 1/2] make Connect::write return correct value for rumqttd --- rumqttd/CHANGELOG.md | 1 + rumqttd/src/protocol/v4/connect.rs | 2 +- rumqttd/src/protocol/v4/publish.rs | 1 - rumqttd/src/protocol/v5/connect.rs | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rumqttd/CHANGELOG.md b/rumqttd/CHANGELOG.md index e05da5cea..189971f9a 100644 --- a/rumqttd/CHANGELOG.md +++ b/rumqttd/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - MQTT keep alive interval - record client id for remote link's span - session present flag in connack +- Make Connect::write return the number of bytes written correctly everywhere ### Security diff --git a/rumqttd/src/protocol/v4/connect.rs b/rumqttd/src/protocol/v4/connect.rs index 5b8bbbe7d..5064da6e5 100644 --- a/rumqttd/src/protocol/v4/connect.rs +++ b/rumqttd/src/protocol/v4/connect.rs @@ -92,7 +92,7 @@ pub fn write( // update connect flags buffer[flags_index] = connect_flags; - Ok(len) + Ok(1 + count + len) } mod will { diff --git a/rumqttd/src/protocol/v4/publish.rs b/rumqttd/src/protocol/v4/publish.rs index e9bcd2c85..b64cb3143 100644 --- a/rumqttd/src/protocol/v4/publish.rs +++ b/rumqttd/src/protocol/v4/publish.rs @@ -63,6 +63,5 @@ pub fn write(publish: &Publish, buffer: &mut BytesMut) -> Result { buffer.extend_from_slice(&publish.payload); - // TODO: Returned length is wrong in other packets. Fix it Ok(1 + count + len) } diff --git a/rumqttd/src/protocol/v5/connect.rs b/rumqttd/src/protocol/v5/connect.rs index f6dbdc4bc..be348e8aa 100644 --- a/rumqttd/src/protocol/v5/connect.rs +++ b/rumqttd/src/protocol/v5/connect.rs @@ -122,7 +122,7 @@ pub fn write( // update connect flags buffer[flags_index] = connect_flags; - Ok(len) + Ok(1 + count + len) } mod will { From 67d46b7270a01433a01499105327edab76b531a0 Mon Sep 17 00:00:00 2001 From: amokfa Date: Tue, 12 Mar 2024 09:24:10 +0530 Subject: [PATCH 2/2] fix changelog --- rumqttd/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rumqttd/CHANGELOG.md b/rumqttd/CHANGELOG.md index 189971f9a..ba5c627eb 100644 --- a/rumqttd/CHANGELOG.md +++ b/rumqttd/CHANGELOG.md @@ -25,7 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - MQTT keep alive interval - record client id for remote link's span - session present flag in connack -- Make Connect::write return the number of bytes written correctly everywhere +- Make write method return the number of bytes written correctly everywhere ### Security