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
+6 -9
View File
@@ -6,18 +6,15 @@
#include "webcc/connection_pool.h"
#include "webcc/logger.h"
#include "webcc/server.h"
using boost::asio::ip::tcp;
namespace webcc {
Connection::Connection(tcp::socket socket, ConnectionPool* pool,
Server* server)
: socket_(std::move(socket)),
pool_(pool),
buffer_(kBufferSize),
server_(server) {
Queue<ConnectionPtr>* queue)
: socket_(std::move(socket)), pool_(pool), queue_(queue),
buffer_(kBufferSize) {
}
void Connection::Start() {
@@ -122,9 +119,9 @@ void Connection::OnRead(boost::system::error_code ec, std::size_t length) {
LOG_VERB("HTTP request:\n%s", request_->Dump().c_str());
// Enqueue this connection.
// Some worker thread will handle it later.
server_->Enqueue(shared_from_this());
// Enqueue this connection once the request has been read.
// Some worker thread will handle the request later.
queue_->Push(shared_from_this());
}
void Connection::DoWrite() {