From b3b9d91eccd3f54be112ac5389b49969fea93b4c Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期三, 21 四月 2021 13:22:55 +0800 Subject: [PATCH] trivial. --- src/proto.cpp | 16 ++++++++++++++-- 1 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/proto.cpp b/src/proto.cpp index 0ec894f..b1e8207 100644 --- a/src/proto.cpp +++ b/src/proto.cpp @@ -17,12 +17,20 @@ */ #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 + +std::string NewMsgId() { return RandId(); } BHMsgHead InitMsgHead(const MsgType type, const std::string &proc_id) { @@ -35,7 +43,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