ws cobra to sentry / simplify sent and received message statistic reporting
This commit is contained in:
parent
91a95dc5f6
commit
7e67598360
@ -41,13 +41,23 @@ namespace ix
|
|||||||
std::atomic<bool> errorSending(false);
|
std::atomic<bool> errorSending(false);
|
||||||
std::atomic<bool> stop(false);
|
std::atomic<bool> stop(false);
|
||||||
|
|
||||||
std::mutex conditionVariableMutex;
|
|
||||||
std::condition_variable condition;
|
std::condition_variable condition;
|
||||||
std::condition_variable progressCondition;
|
std::mutex conditionVariableMutex;
|
||||||
std::queue<Json::Value> queue;
|
std::queue<Json::Value> queue;
|
||||||
|
|
||||||
|
auto timer = [&sentCount, &receivedCount] {
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
spdlog::info("messages received {} sent {}", receivedCount, sentCount);
|
||||||
|
|
||||||
|
auto duration = std::chrono::seconds(1);
|
||||||
|
std::this_thread::sleep_for(duration);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::thread t1(timer);
|
||||||
|
|
||||||
auto sentrySender = [&condition,
|
auto sentrySender = [&condition,
|
||||||
&progressCondition,
|
|
||||||
&conditionVariableMutex,
|
&conditionVariableMutex,
|
||||||
&queue,
|
&queue,
|
||||||
verbose,
|
verbose,
|
||||||
@ -83,8 +93,6 @@ namespace ix
|
|||||||
++sentCount;
|
++sentCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
progressCondition.notify_one();
|
|
||||||
|
|
||||||
if (stop) return;
|
if (stop) return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -106,7 +114,6 @@ namespace ix
|
|||||||
&sentCount,
|
&sentCount,
|
||||||
&condition,
|
&condition,
|
||||||
&conditionVariableMutex,
|
&conditionVariableMutex,
|
||||||
&progressCondition,
|
|
||||||
&queue](ix::CobraConnectionEventType eventType,
|
&queue](ix::CobraConnectionEventType eventType,
|
||||||
const std::string& errMsg,
|
const std::string& errMsg,
|
||||||
const ix::WebSocketHttpHeaders& headers,
|
const ix::WebSocketHttpHeaders& headers,
|
||||||
@ -136,7 +143,6 @@ namespace ix
|
|||||||
&receivedCount,
|
&receivedCount,
|
||||||
&condition,
|
&condition,
|
||||||
&conditionVariableMutex,
|
&conditionVariableMutex,
|
||||||
&progressCondition,
|
|
||||||
&queue](const Json::Value& msg) {
|
&queue](const Json::Value& msg) {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
@ -152,7 +158,6 @@ namespace ix
|
|||||||
spdlog::warn("message dropped: sending is backlogged !");
|
spdlog::warn("message dropped: sending is backlogged !");
|
||||||
|
|
||||||
condition.notify_one();
|
condition.notify_one();
|
||||||
progressCondition.notify_one();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +169,6 @@ namespace ix
|
|||||||
}
|
}
|
||||||
|
|
||||||
condition.notify_one();
|
condition.notify_one();
|
||||||
progressCondition.notify_one();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (eventType == ix::CobraConnection_EventType_Subscribed)
|
else if (eventType == ix::CobraConnection_EventType_Subscribed)
|
||||||
@ -185,13 +189,10 @@ namespace ix
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
std::mutex progressConditionVariableMutex;
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(progressConditionVariableMutex);
|
auto duration = std::chrono::seconds(1);
|
||||||
progressCondition.wait(lock);
|
std::this_thread::sleep_for(duration);
|
||||||
|
|
||||||
spdlog::info("messages received {} sent {}", receivedCount, sentCount);
|
|
||||||
|
|
||||||
if (strict && errorSending) break;
|
if (strict && errorSending) break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user