Rework the server to remove rest_xxx classes.

This commit is contained in:
Chunting Gu
2019-06-21 13:53:00 +08:00
parent 43aadee885
commit 4140b4f94c
24 changed files with 311 additions and 318 deletions
+19 -6
View File
@@ -7,25 +7,35 @@
#include "boost/asio/ip/tcp.hpp"
#include "boost/asio/signal_set.hpp"
#include "webcc/globals.h"
#include "webcc/connection.h"
#include "webcc/connection_pool.h"
#include "webcc/request_handler.h"
#include "webcc/service.h"
namespace webcc {
class RequestHandler;
// HTTP server accepts TCP connections from TCP clients.
// NOTE: Only support IPv4.
class Server {
public:
Server(std::uint16_t port, std::size_t workers);
Server(std::uint16_t port, std::size_t workers,
const std::string& doc_root = "");
virtual ~Server() = default;
Server(const Server&) = delete;
Server& operator=(const Server&) = delete;
// Bind a service to the given URL path.
// The URL should start with "/" and it will be treated as a regular
// expression if |is_regex| is true.
// Examples:
// - "/instances"
// - "/instances/(\\d+)"
// Binding to the same URL multiple times is allowed, but only the last one
// takes effect.
bool Bind(ServicePtr service, const std::string& url, bool is_regex);
// Run the server's io_service loop.
void Run();
@@ -40,7 +50,7 @@ private:
void DoAwaitStop();
// Get the handler for incoming requests.
virtual RequestHandler* GetRequestHandler() = 0;
//virtual RequestHandler* GetRequestHandler();
// The io_context used to perform asynchronous operations.
boost::asio::io_context io_context_;
@@ -51,11 +61,14 @@ private:
// The connection pool which owns all live connections.
ConnectionPool pool_;
// The signal_set is used to register for process termination notifications.
// The signals for processing termination notifications.
boost::asio::signal_set signals_;
// The number of worker threads.
std::size_t workers_;
// The handler for incoming requests.
RequestHandler request_handler_;
};
} // namespace webcc