aboutsummaryrefslogtreecommitdiffstats
path: root/include/http_server.h
diff options
context:
space:
mode:
authorJaeseung Ha <ipknhama@gmail.com>2016-05-23 21:51:30 +0900
committerJaeseung Ha <ipknhama@gmail.com>2016-05-23 21:51:30 +0900
commiteb5a3b55f9e9b4077be7caeac67b403d345dc2d1 (patch)
tree75ed1a09a3d8504381f780e7b94a4b06e75098fc /include/http_server.h
parentf96f65938dcf4d6ad7e6fd95a0cf5c3537970015 (diff)
parent1b1210685efc252e5e9053cb75e8e8ade7dc4371 (diff)
downloadcrow-eb5a3b55f9e9b4077be7caeac67b403d345dc2d1.tar.gz
crow-eb5a3b55f9e9b4077be7caeac67b403d345dc2d1.zip
Merge pull request #126 from gmaisto/master
Added support to bind to a specific interface
Diffstat (limited to 'include/http_server.h')
-rw-r--r--include/http_server.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/include/http_server.h b/include/http_server.h
index 80ef7a4..4696450 100644
--- a/include/http_server.h
+++ b/include/http_server.h
@@ -20,16 +20,17 @@ namespace crow
{
using namespace boost;
using tcp = asio::ip::tcp;
-
+
template <typename Handler, typename Adaptor = SocketAdaptor, typename ... Middlewares>
class Server
{
public:
- Server(Handler* handler, uint16_t port, std::tuple<Middlewares...>* middlewares = nullptr, uint16_t concurrency = 1, typename Adaptor::context* adaptor_ctx = nullptr)
- : acceptor_(io_service_, tcp::endpoint(asio::ip::address(), port)),
+ Server(Handler* handler, std::string bindaddr, uint16_t port, std::tuple<Middlewares...>* middlewares = nullptr, uint16_t concurrency = 1, typename Adaptor::context* adaptor_ctx = nullptr)
+ : acceptor_(io_service_, tcp::endpoint(boost::asio::ip::address::from_string(bindaddr), port)),
signals_(io_service_, SIGINT, SIGTERM),
- handler_(handler),
+ handler_(handler),
concurrency_(concurrency),
+ bindaddr_(bindaddr),
port_(port),
middlewares_(middlewares),
adaptor_ctx_(adaptor_ctx)
@@ -145,7 +146,7 @@ namespace crow
is, handler_, server_name_, middlewares_,
get_cached_date_str_pool_[roundrobin_index_], *timer_queue_pool_[roundrobin_index_],
adaptor_ctx_);
- acceptor_.async_accept(p->socket(),
+ acceptor_.async_accept(p->socket(),
[this, p, &is](boost::system::error_code ec)
{
if (!ec)
@@ -171,6 +172,7 @@ namespace crow
uint16_t concurrency_{1};
std::string server_name_ = "Crow/0.1";
uint16_t port_;
+ std::string bindaddr_;
unsigned int roundrobin_index_{};
std::tuple<Middlewares...>* middlewares_;