diff --git a/Cargo.toml b/Cargo.toml index 72507e9..0dc9b71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Y. T. Chung "] name = "mqtt-protocol" -version = "0.10.0" +version = "0.11.0" license = "MIT/Apache-2.0" description = "MQTT Protocol Library" keywords = ["mqtt", "protocol"] @@ -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"] } diff --git a/README.md b/README.md index a742b39..78ae7c1 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ MQTT protocol library for Rust ```toml [dependencies] -mqtt-protocol = "0.8" +mqtt-protocol = "0.11" ``` ## Usage diff --git a/examples/sub-client.rs b/examples/sub-client.rs index eeb9937..5aceaae 100644 --- a/examples/sub-client.rs +++ b/examples/sub-client.rs @@ -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}; @@ -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()) } @@ -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"); @@ -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)); } }