Browse Source

okay, move the port probing into JsonAdapter::prepare_run()

old_session_management
Roker 2 years ago
parent
commit
a0d949af74
3 changed files with 20 additions and 4 deletions
  1. +2
    -2
      server/ev_server.cc
  2. +1
    -1
      server/ev_server.hh
  3. +17
    -1
      server/json-adapter.cc

+ 2
- 2
server/ev_server.cc View File

@ -161,8 +161,8 @@ const FunctionMap functions = {
} // end of anonymous namespace
ev_server::ev_server(const std::string& address, unsigned short start_port, unsigned short end_port, bool deliver_html, const std::string& base_url)
: pEp::Webserver(pEp::net::ip::address::from_string(address), start_port, end_port)
ev_server::ev_server(const std::string& address, unsigned short port, bool deliver_html, const std::string& base_url)
: pEp::Webserver(pEp::net::ip::address::from_string(address), port)
{
this->add_url_handler(base_url + "callFunction", ev_server::OnApiRequest);
if(deliver_html)


+ 1
- 1
server/ev_server.hh View File

@ -13,7 +13,7 @@ class Logger;
class ev_server : public pEp::Webserver
{
public:
ev_server(const std::string& address, unsigned short start_port, unsigned short end_port, bool deliver_html, const std::string& base_url);
ev_server(const std::string& address, unsigned short start_port, bool deliver_html, const std::string& base_url);
protected:
static


+ 17
- 1
server/json-adapter.cc View File

@ -208,7 +208,23 @@ void JsonAdapter::prepare_run(const std::string& address, unsigned start_port, u
// delayed after constructor, so virtual functions are working:
i->session_registry.reset(new SessionRegistry(this->getMessageToSend(), this->getInjectSyncEvent()));
i->webserver = std::make_unique<ev_server>(address, start_port, end_port, i->deliver_html, BaseUrl);
for(unsigned short port = start_port; port<=end_port; ++port)
{
try{
i->webserver = std::make_unique<ev_server>(address, port, i->deliver_html, BaseUrl);
break;
}catch(...)
{
// okay, next port!
}
}
if(!i->webserver)
{
throw std::runtime_error("Cannot bind to a port between " + std::to_string(start_port)
+ " and " + std::to_string(end_port) + "." );
}
i->token = create_security_token(address, i->webserver->port(), BaseUrl);
Log() << "Bound to port " << i->webserver->port() << ", sec_token=\"" << i->token << "\".";


Loading…
Cancel
Save