Support persistent connection for server.
parent
6c4ac75c35
commit
6c5dedb807
@ -0,0 +1,30 @@
|
||||
#include "webcc/http_connection_pool.h"
|
||||
|
||||
#include "webcc/logger.h"
|
||||
|
||||
namespace webcc {
|
||||
|
||||
HttpConnectionPool::HttpConnectionPool() {
|
||||
}
|
||||
|
||||
void HttpConnectionPool::Start(HttpConnectionPtr c) {
|
||||
LOG_VERB("Starting connection...");
|
||||
connections_.insert(c);
|
||||
c->Start();
|
||||
}
|
||||
|
||||
void HttpConnectionPool::Close(HttpConnectionPtr c) {
|
||||
LOG_VERB("Closing connection...");
|
||||
connections_.erase(c);
|
||||
c->Close();
|
||||
}
|
||||
|
||||
void HttpConnectionPool::CloseAll() {
|
||||
LOG_VERB("Closing all (%u) connections...", connections_.size());
|
||||
for (auto& c : connections_) {
|
||||
c->Close();
|
||||
}
|
||||
connections_.clear();
|
||||
}
|
||||
|
||||
} // namespace webcc
|
@ -0,0 +1,33 @@
|
||||
#ifndef WEBCC_HTTP_CONNECTION_POOL_H_
|
||||
#define WEBCC_HTTP_CONNECTION_POOL_H_
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "webcc/http_connection.h"
|
||||
|
||||
namespace webcc {
|
||||
|
||||
class HttpConnectionPool {
|
||||
public:
|
||||
HttpConnectionPool(const HttpConnectionPool&) = delete;
|
||||
HttpConnectionPool& operator=(const HttpConnectionPool&) = delete;
|
||||
|
||||
HttpConnectionPool();
|
||||
|
||||
// Add a connection to the pool and start it.
|
||||
void Start(HttpConnectionPtr c);
|
||||
|
||||
// Close a connection.
|
||||
void Close(HttpConnectionPtr c);
|
||||
|
||||
// Close all connections.
|
||||
void CloseAll();
|
||||
|
||||
private:
|
||||
/// The managed connections.
|
||||
std::set<HttpConnectionPtr> connections_;
|
||||
};
|
||||
|
||||
} // namespace webcc
|
||||
|
||||
#endif // WEBCC_HTTP_CONNECTION_POOL_H_
|
Loading…
Reference in New Issue