Allow to stop server and restart server; allow to run loop in multiple threads.

This commit is contained in:
Chunting Gu
2019-07-30 10:35:51 +08:00
parent 0f0f6fdf8e
commit 673a98cffb
16 changed files with 465 additions and 287 deletions
+18 -3
View File
@@ -6,17 +6,32 @@ namespace webcc {
void ConnectionPool::Start(ConnectionPtr c) {
LOG_VERB("Starting connection...");
connections_.insert(c);
{
// Lock the container only.
std::lock_guard<std::mutex> lock(mutex_);
connections_.insert(c);
}
c->Start();
}
void ConnectionPool::Close(ConnectionPtr c) {
LOG_VERB("Closing connection...");
connections_.erase(c);
{
// Lock the container only.
std::lock_guard<std::mutex> lock(mutex_);
connections_.erase(c);
}
c->Close();
}
void ConnectionPool::CloseAll() {
void ConnectionPool::Clear() {
// Lock all since we are going to stop anyway.
std::lock_guard<std::mutex> lock(mutex_);
if (!connections_.empty()) {
LOG_VERB("Closing all (%u) connections...", connections_.size());
for (auto& c : connections_) {