Skip to content

Commit

Permalink
reordering config. removed workers restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Kraynyukhov committed Apr 14, 2018
1 parent 9b19df8 commit 522ef0a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 61 deletions.
2 changes: 1 addition & 1 deletion include/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace LAppS
{"listeners",3},
{"ip","0.0.0.0"},
{"port",5083},
{"workers",{ {"workers",3}, {"max_connections", 100 }}},
#ifdef LAPPS_TLS_ENABLE
{"tls",true},
#else
Expand Down Expand Up @@ -87,7 +88,6 @@ namespace LAppS
{"internal", false},
{"request_target", "/echo"},
{"protocol", "raw"},
{"workers",{ {"workers",3}, {"max_connections", 100 }}},
{"instances", 3}
}}}/*,
{{"console", {
Expand Down
2 changes: 1 addition & 1 deletion include/IOWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace LAppS
typedef WebSocket<TLSEnable,StatsEnable> WSType;
typedef std::shared_ptr<WSType> WSSPtr;

explicit IOWorker(const uint8_t id, const size_t maxConnections)
explicit IOWorker(const size_t id, const size_t maxConnections)
: Worker(id,maxConnections), mMayRun(true),mCanStop(false),
mConnectionsMutex(), mInboundMutex(), mOutMutex(),
mShakespeer(),
Expand Down
4 changes: 2 additions & 2 deletions include/TaggedEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

struct TaggedEvent
{
uint8_t wid;
int sockfd;
size_t wid;
int sockfd;
WSEvent event;
};

Expand Down
4 changes: 2 additions & 2 deletions include/WebSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ template <bool TLSEnable=false, bool StatsEnable=false> class WebSocket

ApplicationSPtr mApplication;

uint8_t mWorkerId;
size_t mWorkerId;

WSConnectionStats mStats;

Expand Down Expand Up @@ -213,7 +213,7 @@ template <bool TLSEnable=false, bool StatsEnable=false> class WebSocket
mApplication=ptr;
}

void setWorkerId(const uint8_t id)
void setWorkerId(const size_t id)
{
mWorkerId=id;
}
Expand Down
4 changes: 2 additions & 2 deletions include/abstract/Worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ namespace abstract
class Worker : public ::itc::abstract::IRunnable, public ::itc::TCPListener::ViewType
{
protected:
const uint8_t ID;
const size_t ID;
size_t mMaxConnections;
WorkerStats mStats;
public:
explicit Worker(const uint8_t id, const size_t maxConnections)
explicit Worker(const size_t id, const size_t maxConnections)
: itc::abstract::IRunnable(), ID(id),mMaxConnections(maxConnections),
mStats{0,0,0,0,0,0,0}
{
Expand Down
93 changes: 40 additions & 53 deletions include/wsServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ class wsServer
{
try
{
size_t workers=0;
size_t max_connections=0;

auto it=LAppSConfig::getInstance()->getLAppSConfig().find("services");
if(it!=LAppSConfig::getInstance()->getLAppSConfig().end())
{
Expand Down Expand Up @@ -122,32 +119,6 @@ class wsServer
app_target.clear();
}

found=service.value().find("workers");
if(found != service.value().end())
{
workers=found.value()["workers"];

if(workers>255)
{
throw std::system_error(EINVAL,std::system_category(),"Configuration of service "+service.key()+" error: workers > 255. Max Workers hard limit is 255");
}

auto max_connections_found=found.value().find("max_connections");

if(max_connections_found != found.value().end())
{
max_connections=max_connections_found.value();
}
else
{
max_connections=100;
}
}
else {
workers=1;
max_connections=100;
}

if((!app_target.empty())&&(!proto.empty()))
{
std::regex request_target("^[/][[:alpha:][:digit:]_-]*([/]?[[:alpha:][:digit:]_-]+)*$");
Expand Down Expand Up @@ -190,11 +161,6 @@ class wsServer
}else{
throw std::system_error(EINVAL,std::system_category(), "Incorrect protocol is specified for target "+app_target+" in service "+service_name+". Only two protocols are supported: raw, LAppS");
}

for(size_t i=0;i<workers;++i)
{
WorkersPool::getInstance()->spawn(max_connections);
}
} else throw std::system_error(EINVAL,std::system_category(), "Incorrect request target: "+app_target+" in configuration of service "+service.key());
} else throw std::system_error(EINVAL,std::system_category(), "Undefined request_target or protocol keyword which are both mandatory");
}
Expand Down Expand Up @@ -245,26 +211,47 @@ class wsServer
wsServer()
: enableTLS(), enableStatsUpdate(), mAllStats{0,0,0,0,0,0,0}
{
itc::getLog()->debug(__FILE__,__LINE__,"Starting WS Server");

const bool is_tls_enabled=LAppSConfig::getInstance()->getWSConfig()["tls"];
itc::getLog()->debug(__FILE__,__LINE__,"Starting WS Server");

const bool is_tls_enabled=LAppSConfig::getInstance()->getWSConfig()["tls"];

if(TLSEnable&&(!is_tls_enabled))
{
throw std::system_error(EINVAL,std::system_category(),"WS Server is build TLS support, tls option MUST BE enabled in config to start LAppS");
}

if(TLSEnable&&(!is_tls_enabled))
{
throw std::system_error(EINVAL,std::system_category(),"WS Server is build TLS support, tls option MUST BE enabled in config to start LAppS");
}

if(is_tls_enabled&&(!TLSEnable))
throw std::system_error(EINVAL,std::system_category(),"WS Server is build without TLS support, disable tls option in config to start LAppS (insecure)");
else if(is_tls_enabled)
{
auto tls_server_context=TLS::SharedServerContext::getInstance()->getContext();
if(tls_server_context == nullptr)
{
throw std::logic_error("Can't continue, TLS Server Context is NULL");
}
}
prepareServices();
if(is_tls_enabled&&(!TLSEnable))
throw std::system_error(EINVAL,std::system_category(),"WS Server is build without TLS support, disable tls option in config to start LAppS (insecure)");
else if(is_tls_enabled)
{
auto tls_server_context=TLS::SharedServerContext::getInstance()->getContext();
if(tls_server_context == nullptr)
{
throw std::logic_error("Can't continue, TLS Server Context is NULL");
}
}

auto found=LAppSConfig::getInstance()->getWSConfig().find("workers");
size_t max_connections=1000;
size_t workers=1;

if(found != LAppSConfig::getInstance()->getWSConfig().end())
{
auto workers=found.value()["workers"];

auto max_connections_found=found.value().find("max_connections");

if(max_connections_found != found.value().end())
{
max_connections=max_connections_found.value();
}
}

for(size_t i=0;i<workers;++i)
{
WorkersPool::getInstance()->spawn(max_connections);
}
prepareServices();
};

void run()
Expand Down

0 comments on commit 522ef0a

Please # to comment.