Skip to content

Commit

Permalink
release v0.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Mar 29, 2021
1 parent 8c8766d commit d961861
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Y. T. Chung <[email protected]>"]
name = "mqtt-protocol"
version = "0.10.0"
version = "0.11.0"
license = "MIT/Apache-2.0"
description = "MQTT Protocol Library"
keywords = ["mqtt", "protocol"]
Expand All @@ -21,8 +21,7 @@ thiserror = "1.0"

[dev-dependencies]
clap = "2"
env_logger = "0.7"
time = "0.1"
env_logger = "0.8"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread", "net", "time", "io-util"] }
futures = { version = "0.3" }
uuid = { version = "0.8", features = ["v4"] }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MQTT protocol library for Rust

```toml
[dependencies]
mqtt-protocol = "0.8"
mqtt-protocol = "0.11"
```

## Usage
Expand Down
14 changes: 6 additions & 8 deletions examples/sub-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ extern crate mqtt;
extern crate log;
extern crate clap;
extern crate env_logger;
extern crate time;
extern crate uuid;

use std::env;
use std::io::Write;
use std::net::TcpStream;
use std::str;
use std::thread;
use std::time::{Duration, Instant};

use clap::{App, Arg};

Expand All @@ -20,9 +21,6 @@ use mqtt::packet::*;
use mqtt::TopicFilter;
use mqtt::{Decodable, Encodable, QualityOfService};

use std::thread;
use std::time::Duration;

fn generate_client_id() -> String {
format!("/MQTT/rust/{}", Uuid::new_v4())
}
Expand Down Expand Up @@ -138,10 +136,10 @@ fn main() {

let mut stream_clone = stream.try_clone().unwrap();
thread::spawn(move || {
let mut last_ping_time = 0;
let mut next_ping_time = last_ping_time + (keep_alive as f32 * 0.9) as i64;
let mut last_ping_time = Instant::now();
let mut next_ping_time = last_ping_time + Duration::from_secs((keep_alive as f32 * 0.9) as u64);
loop {
let current_timestamp = time::get_time().sec;
let current_timestamp = Instant::now();
if keep_alive > 0 && current_timestamp >= next_ping_time {
info!("Sending PINGREQ to broker");

Expand All @@ -152,7 +150,7 @@ fn main() {
stream_clone.write_all(&buf[..]).unwrap();

last_ping_time = current_timestamp;
next_ping_time = last_ping_time + (keep_alive as f32 * 0.9) as i64;
next_ping_time = last_ping_time + Duration::from_secs((keep_alive as f32 * 0.9) as u64);
thread::sleep(Duration::new((keep_alive / 2) as u64, 0));
}
}
Expand Down

0 comments on commit d961861

Please sign in to comment.