Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v5): send last_will and login info with connect #478

Merged
merged 1 commit into from Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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