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
+9 -7
View File
@@ -8,19 +8,23 @@
#include "boost/asio/ip/tcp.hpp"
#include "webcc/globals.h"
#include "webcc/queue.h"
#include "webcc/request.h"
#include "webcc/request_parser.h"
#include "webcc/response.h"
namespace webcc {
class Connection;
class ConnectionPool;
class Server;
using ConnectionPtr = std::shared_ptr<Connection>;
class Connection : public std::enable_shared_from_this<Connection> {
public:
Connection(boost::asio::ip::tcp::socket socket, ConnectionPool* pool,
Server* server);
Queue<ConnectionPtr>* queue);
~Connection() = default;
@@ -61,15 +65,15 @@ private:
// The socket for the connection.
boost::asio::ip::tcp::socket socket_;
// The pool for this connection.
// The connection pool.
ConnectionPool* pool_;
// The connection queue.
Queue<ConnectionPtr>* queue_;
// The buffer for incoming data.
std::vector<char> buffer_;
// The server.
Server* server_;
// The incoming request.
RequestPtr request_;
@@ -80,8 +84,6 @@ private:
ResponsePtr response_;
};
using ConnectionPtr = std::shared_ptr<Connection>;
} // namespace webcc
#endif // WEBCC_CONNECTION_H_