Skip to content

Commit

Permalink
fix(v5): send last_will and login info with connect
Browse files Browse the repository at this point in the history
  • Loading branch information
henil committed Dec 21, 2022
1 parent 306efe6 commit d49f8c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion rumqttc/src/v5/eventloop.rs
Expand Up @@ -298,7 +298,7 @@ async fn mqtt_connect(
};

// send mqtt connect packet
network.connect(connect).await?;
network.connect(connect, options).await?;

// validate connack
match network.read().await? {
Expand Down
13 changes: 9 additions & 4 deletions rumqttc/src/v5/framed.rs
Expand Up @@ -2,8 +2,8 @@ use bytes::BytesMut;
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};

use super::mqttbytes::v5::Packet;
use super::mqttbytes::{self, Connect};
use super::{Incoming, MqttState, StateError};
use super::mqttbytes::{self, Connect, Login};
use super::{Incoming, MqttOptions, MqttState, StateError};
use std::io;

/// Network transforms packets <-> frames efficiently. It takes
Expand Down Expand Up @@ -96,9 +96,14 @@ impl Network {
}
}

pub async fn connect(&mut self, connect: Connect) -> io::Result<usize> {
pub async fn connect(&mut self, connect: Connect, options: &MqttOptions) -> io::Result<usize> {
let mut write = BytesMut::new();
let len = match Packet::Connect(connect, None, None, None, None).write(&mut write) {
let last_will = options.last_will();
let login = options.credentials().map(|l| Login {
username: l.0,
password: l.1,
});
let len = match Packet::Connect(connect, None, last_will, None, login).write(&mut write) {
Ok(size) => size,
Err(e) => return Err(io::Error::new(io::ErrorKind::InvalidData, e.to_string())),
};
Expand Down

0 comments on commit d49f8c1

Please sign in to comment.