diff options
Diffstat (limited to 'http_server.h')
-rw-r--r-- | http_server.h | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/http_server.h b/http_server.h index 64dff94..10e335b 100644 --- a/http_server.h +++ b/http_server.h @@ -16,15 +16,19 @@ namespace flask class Server { public: - Server(Handler* handler, uint16_t port) - : acceptor_(io_service_, tcp::endpoint(asio::ip::address(), port)), socket_(io_service_), handler_(handler) + Server(Handler* handler, uint16_t port, uint16_t concurrency = 1) + : acceptor_(io_service_, tcp::endpoint(asio::ip::address(), port)), socket_(io_service_), handler_(handler), concurrency_(concurrency) { do_accept(); } void run() { - auto _ = std::async(std::launch::async, [this]{io_service_.run();}); + std::vector<std::future<void>> v; + for(uint16_t i = 0; i < concurrency_; i ++) + v.push_back( + std::async(std::launch::async, [this]{io_service_.run();}) + ); } void stop() @@ -39,7 +43,7 @@ namespace flask [this](boost::system::error_code ec) { if (!ec) - (new Connection<Handler>(std::move(socket_), handler_))->start(); + (new Connection<Handler>(std::move(socket_), handler_, server_name_))->start(); do_accept(); }); } @@ -49,5 +53,7 @@ namespace flask tcp::acceptor acceptor_; tcp::socket socket_; Handler* handler_; + uint16_t concurrency_ = 1; + std::string server_name_ = "Flask++/0.1"; }; } |