From bb9a7e348892eb5c4fccb063380aa6fcd9612b71 Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期二, 06 四月 2021 17:32:35 +0800 Subject: [PATCH] server resend failed; rename msgs; refactor. --- src/socket.cpp | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/socket.cpp b/src/socket.cpp index 73681f1..b9def0c 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -49,15 +49,15 @@ Stop(); //TODO should stop in sub class, incase thread access sub class data. } -bool ShmSocket::Start(const RecvCB &onData, int nworker) +bool ShmSocket::Start(const RecvCB &onData, const IdleCB &onIdle, int nworker) { - if (!mq_) { - return false; + if (!mq_ || !onData) { + return false; // TODO error code. } std::lock_guard<std::mutex> lock(mutex_); StopNoLock(); - auto RecvProc = [this, onData]() { + auto RecvProc = [this, onData, onIdle]() { while (run_) { try { MsgI imsg; @@ -67,6 +67,8 @@ if (imsg.Unpack(msg)) { onData(*this, imsg, msg); } + } else if (onIdle) { + onIdle(*this); } } catch (...) { } -- Gitblit v1.8.0