Skip to content

Commit

Permalink
updated to oatpp veraion 0.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
lganzzzo committed Apr 29, 2019
1 parent b6e061d commit 8fbb757
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ target_include_directories(${project_name}-lib

## link libs

find_package(oatpp 0.19.1 REQUIRED)
find_package(oatpp 0.19.4 REQUIRED)

target_link_libraries(${project_name}-lib
PUBLIC oatpp::oatpp
Expand Down
19 changes: 15 additions & 4 deletions main/src/AppComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,24 @@
*/
class AppComponent {
public:


/**
* Create Async Executor
*/
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::async::Executor>, executor)([] {
return std::make_shared<oatpp::async::Executor>(
4 /* Data-Processing threads */,
1 /* I/O threads */,
1 /* Timer threads */
);
}());

/**
* Create ConnectionProvider component which listens on the port
*/
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, serverConnectionProvider)([] {
/* non_blocking connections should be used with AsyncHttpConnectionHandler for AsyncIO */
return oatpp::network::server::SimpleTCPConnectionProvider::createShared(8000, true /* true for non_blocking */);
return oatpp::network::server::SimpleTCPConnectionProvider::createShared(8000);
}());

/**
Expand All @@ -47,8 +58,8 @@ class AppComponent {
*/
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::server::ConnectionHandler>, serverConnectionHandler)([] {
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router); // get Router component
/* Async ConnectionHandler for Async IO and Coroutine based endpoints */
return oatpp::web::server::AsyncHttpConnectionHandler::createShared(router);
OATPP_COMPONENT(std::shared_ptr<oatpp::async::Executor>, executor); // get Async executor component
return oatpp::web::server::AsyncHttpConnectionHandler::createShared(router, executor);
}());

/**
Expand Down
2 changes: 1 addition & 1 deletion main/src/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
#include <iostream>

void Logger::log(v_int32 priority, const std::string& tag, const std::string& message) {
oatpp::concurrency::SpinLock lock(m_atom);
std::lock_guard<oatpp::concurrency::SpinLock> lock(m_lock);
std::cout << tag << ":" << message << "\n";
}
6 changes: 1 addition & 5 deletions main/src/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@
*/
class Logger : public oatpp::base::Logger {
private:
oatpp::concurrency::SpinLock::Atom m_atom;
oatpp::concurrency::SpinLock m_lock;
public:

Logger()
: m_atom(false)
{}

void log(v_int32 priority, const std::string& tag, const std::string& message) override;

};
Expand Down
1 change: 1 addition & 0 deletions main/src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ oatpp::String StaticFilesManager::getFile(const oatpp::String& path) {
if(!path) {
return nullptr;
}
std::lock_guard<oatpp::concurrency::SpinLock> lock(m_lock);
auto& file = m_cache [path];
if(file) {
return file;
Expand Down
3 changes: 1 addition & 2 deletions main/src/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
class StaticFilesManager {
private:
oatpp::String m_basePath;
oatpp::concurrency::SpinLock::Atom m_atom;
oatpp::concurrency::SpinLock m_lock;
std::unordered_map<oatpp::String, oatpp::String> m_cache;
private:
oatpp::String getExtension(const oatpp::String& filename);
public:

StaticFilesManager(const oatpp::String& basePath)
: m_basePath(basePath)
, m_atom(false)
{}

oatpp::String getFile(const oatpp::String& path);
Expand Down

0 comments on commit 8fbb757

Please sign in to comment.