aboutsummaryrefslogtreecommitdiffstats
path: root/http_server.h
diff options
context:
space:
mode:
authoripkn <ipknhama@gmail.com>2014-04-17 02:50:28 -0400
committeripkn <ipknhama@gmail.com>2014-04-17 02:50:28 -0400
commit9ee37ce4bf664166807ff02b61d2e18181c4c1f9 (patch)
treef4c7e41952952f9eaea0db77a73adb0f30341f1b /http_server.h
parentaaf3e525032a54f062395c0f5f057aa6b97f4638 (diff)
downloadcrow-9ee37ce4bf664166807ff02b61d2e18181c4c1f9.tar.gz
crow-9ee37ce4bf664166807ff02b61d2e18181c4c1f9.zip
add concurrency; add server header
Diffstat (limited to 'http_server.h')
-rw-r--r--http_server.h14
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";
};
}