Allow to stop server and restart server; allow to run loop in multiple threads.
This commit is contained in:
@@ -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_) {
|
||||
|
||||
Reference in New Issue
Block a user