Skip to content

Commit

Permalink
Update to the latest oatpp API
Browse files Browse the repository at this point in the history
  • Loading branch information
lganzzzo committed Sep 29, 2020
1 parent 11f212f commit 934e9ad
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ add_library(${project_name}-lib

## link libs

find_package(oatpp 1.1.0 REQUIRED)
find_package(oatpp-websocket 1.1.0 REQUIRED)
find_package(oatpp 1.2.0 REQUIRED)
find_package(oatpp-websocket 1.2.0 REQUIRED)

target_link_libraries(${project_name}-lib
PUBLIC oatpp::oatpp
Expand Down
10 changes: 5 additions & 5 deletions client/src/AppComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "oatpp/core/async/Executor.hpp"

#include "oatpp/network/client/SimpleTCPConnectionProvider.hpp"
#include "oatpp/network/tcp/client/ConnectionProvider.hpp"
#include "oatpp/core/macro/component.hpp"

#include "oatpp/core/base/CommandLineArguments.hpp"
Expand Down Expand Up @@ -53,11 +53,11 @@ class AppComponent {
auto providers = std::make_shared<std::list<std::shared_ptr<oatpp::network::ClientConnectionProvider>>>();

const char* host = m_cmdArgs.getNamedArgumentValue("-h", "127.0.0.1");
v_int32 basePort = oatpp::utils::conversion::strToInt32(m_cmdArgs.getNamedArgumentValue("--bp", "8000"));
v_int32 portsCount = oatpp::utils::conversion::strToInt32(m_cmdArgs.getNamedArgumentValue("--pc", "100"));
v_uint16 basePort = oatpp::utils::conversion::strToInt32(m_cmdArgs.getNamedArgumentValue("--bp", "8000"));
v_uint16 portsCount = oatpp::utils::conversion::strToInt32(m_cmdArgs.getNamedArgumentValue("--pc", "100"));

for(v_int32 i = 0; i < portsCount; i++) {
auto provider = oatpp::network::client::SimpleTCPConnectionProvider::createShared(host, basePort + i);
for(v_uint16 i = 0; i < portsCount; i++) {
auto provider = oatpp::network::tcp::client::ConnectionProvider::createShared({host, (v_uint16)(basePort + i)});
providers->push_back(provider);
}

Expand Down
4 changes: 2 additions & 2 deletions server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ add_library(${project_name}-lib

## link libs

find_package(oatpp 1.1.0 REQUIRED)
find_package(oatpp-websocket 1.1.0 REQUIRED)
find_package(oatpp 1.2.0 REQUIRED)
find_package(oatpp-websocket 1.2.0 REQUIRED)

target_link_libraries(${project_name}-lib
PUBLIC oatpp::oatpp
Expand Down
6 changes: 3 additions & 3 deletions server/src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "./Logger.hpp"
#include "./Meter.hpp"

#include "oatpp/network/server/Server.hpp"
#include "oatpp/network/Server.hpp"

#include <iostream>
#include <thread>
Expand Down Expand Up @@ -66,8 +66,8 @@ void run(const oatpp::base::CommandLineArguments& args) {

for(auto& provider : *connectionProviders) {
threads.push_back(std::thread([provider]{
OATPP_COMPONENT(std::shared_ptr<oatpp::network::server::ConnectionHandler>, handler);
oatpp::network::server::Server server(provider, handler);
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, handler);
oatpp::network::Server server(provider, handler);
server.run();
}));
}
Expand Down
12 changes: 6 additions & 6 deletions server/src/AppComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include "oatpp/web/server/AsyncHttpConnectionHandler.hpp"
#include "oatpp/web/server/HttpRouter.hpp"
#include "oatpp/network/server/SimpleTCPConnectionProvider.hpp"
#include "oatpp/network/tcp/server/ConnectionProvider.hpp"

#include "oatpp/parser/json/mapping/ObjectMapper.hpp"

Expand Down Expand Up @@ -44,11 +44,11 @@ class AppComponent {
*/
OATPP_CREATE_COMPONENT(std::shared_ptr<std::list<std::shared_ptr<oatpp::network::ServerConnectionProvider>>>, connectionProviders)([this] {
auto providers = std::make_shared<std::list<std::shared_ptr<oatpp::network::ServerConnectionProvider>>>();
v_int32 basePort = oatpp::utils::conversion::strToInt32(m_cmdArgs.getNamedArgumentValue("--bp", "8000"));
v_int32 portsCount = oatpp::utils::conversion::strToInt32(m_cmdArgs.getNamedArgumentValue("--pc", "100"));
for(v_int32 i = 0; i < portsCount; i++) {
v_uint16 basePort = oatpp::utils::conversion::strToInt32(m_cmdArgs.getNamedArgumentValue("--bp", "8000"));
v_uint16 portsCount = oatpp::utils::conversion::strToInt32(m_cmdArgs.getNamedArgumentValue("--pc", "100"));
for(v_uint16 i = 0; i < portsCount; i++) {
OATPP_LOGD("AppComponent", "Connection Provider for port: %d", basePort + i);
auto provider = oatpp::network::server::SimpleTCPConnectionProvider::createShared(basePort + i);
auto provider = oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", (v_uint16)(basePort + i)});
providers->push_back(provider);
}
return providers;
Expand All @@ -64,7 +64,7 @@ class AppComponent {
/**
* Create HTTP ConnectionHandler component which uses Router component to route requests
*/
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::server::ConnectionHandler>, serverConnectionHandler)([] {
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, serverConnectionHandler)([] {
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router); // get Router component
return oatpp::web::server::AsyncHttpConnectionHandler::createShared(router, 4);
}());
Expand Down
4 changes: 2 additions & 2 deletions server/test/WebSocketTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class TestComponent {
/**
* Create ConnectionHandler component which uses Router component to route requests
*/
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::server::ConnectionHandler>, serverConnectionHandler)([] {
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, serverConnectionHandler)([] {
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router); // get Router component
OATPP_COMPONENT(std::shared_ptr<oatpp::async::Executor>, executor);
return oatpp::web::server::AsyncHttpConnectionHandler::createShared(router, executor);
Expand Down Expand Up @@ -80,7 +80,7 @@ class TestComponent {

OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ClientConnectionProvider>, clientConnectionProvider)([this] {
#ifdef OATPP_TEST_USE_PORT
return oatpp::network::client::SimpleTCPConnectionProvider::createShared("127.0.0.1", OATPP_TEST_USE_PORT);
return oatpp::network::tcp::client::ConnectionProvider::createShared("127.0.0.1", OATPP_TEST_USE_PORT);
#else
OATPP_COMPONENT(std::shared_ptr<oatpp::network::virtual_::Interface>, interface);
return oatpp::network::virtual_::client::ConnectionProvider::createShared(interface);
Expand Down

0 comments on commit 934e9ad

Please sign in to comment.