diff --git a/examples/static_link_example/main.cc b/examples/static_link_example/main.cc index d2f6bb01..df7cb4b4 100755 --- a/examples/static_link_example/main.cc +++ b/examples/static_link_example/main.cc @@ -28,7 +28,8 @@ int main() { std::cout< &filters= diff --git a/lib/src/HttpAppFramework.cc b/lib/src/HttpAppFramework.cc index d7385759..2f41a786 100755 --- a/lib/src/HttpAppFramework.cc +++ b/lib/src/HttpAppFramework.cc @@ -19,13 +19,14 @@ #include #include #include +#include namespace drogon { class HttpAppFrameworkImpl:public HttpAppFramework { public: - virtual void setListening(const std::string &ip,uint16_t port) override; + virtual void addListener(const std::string &ip,uint16_t port) override; virtual void run() override ; virtual void registerHttpSimpleController(const std::string &pathName,const std::string &crtlName,const std::vector &filters= std::vector())override ; @@ -33,8 +34,7 @@ namespace drogon virtual void disableSession() override { _useSession=false;} ~HttpAppFrameworkImpl(){} private: - std::string _ip; - uint16_t _port; + std::vector> _listeners; void onAsyncRequest(const HttpRequest& req,std::functioncallback); void readSendFile(const std::string& filePath,const HttpRequest& req, HttpResponse* resp); @@ -84,19 +84,23 @@ void HttpAppFrameworkImpl::registerHttpSimpleController(const std::string &pathN _simpCtrlMap[path].controllerName=crtlName; _simpCtrlMap[path].filtersName=filters; } -void HttpAppFrameworkImpl::setListening(const std::string &ip,uint16_t port) +void HttpAppFrameworkImpl::addListener(const std::string &ip, uint16_t port) { - _ip=ip; - _port=port; + _listeners.push_back(std::make_pair(ip,port)); } void HttpAppFrameworkImpl::run() { trantor::EventLoop loop; - HttpServer httpServer(&loop,InetAddress(_ip,_port),""); - httpServer.setHttpAsyncCallback(std::bind(&HttpAppFrameworkImpl::onAsyncRequest,this,_1,_2)); + std::vector> servers; + for(auto listener:_listeners) + { + auto serverPtr=std::make_shared(&loop,InetAddress(listener.first,listener.second),"drogon"); + serverPtr->setHttpAsyncCallback(std::bind(&HttpAppFrameworkImpl::onAsyncRequest,this,_1,_2)); + serverPtr->start(); + servers.push_back(serverPtr); + } _sessionMapPtr=std::unique_ptr>(new CacheMap(&loop,1,1200)); - httpServer.start(); loop.loop(); }