From 7f307880a58012077833061b5ff18ba63c1a2269 Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期二, 13 四月 2021 19:04:37 +0800 Subject: [PATCH] change timestamp to steady seconds. --- src/proto.cpp | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/proto.cpp b/src/proto.cpp index 0ec894f..287924b 100644 --- a/src/proto.cpp +++ b/src/proto.cpp @@ -17,12 +17,18 @@ */ #include "proto.h" #include <boost/uuid/uuid_generators.hpp> +#include <chrono> + +namespace +{ std::string RandId() { boost::uuids::uuid id = boost::uuids::random_generator()(); return std::string((char *) &id, sizeof(id)); } + +} // namespace BHMsgHead InitMsgHead(const MsgType type, const std::string &proc_id) { @@ -35,7 +41,11 @@ msg.set_msg_id(msgid); msg.set_type(type); msg.set_proc_id(proc_id); - time_t tm = 0; - msg.set_timestamp(time(&tm)); + msg.set_timestamp(NowSec()); return msg; } + +bool IsMsgExpired(const BHMsgHead &head) +{ + return NowSec() > head.timestamp() + 10; +} \ No newline at end of file -- Gitblit v1.8.0