You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bb...@apache.org on 2022/02/17 22:22:12 UTC

[geode-native] branch develop updated: GEODE-9326: Replace ACE_Get_Opt (#814)

This is an automated email from the ASF dual-hosted git repository.

bbender pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new 9405612  GEODE-9326: Replace ACE_Get_Opt (#814)
9405612 is described below

commit 94056127cab636168f9ea502d742f72f645cbf9a
Author: Mario Salazar de Torres <ma...@est.tech>
AuthorDate: Thu Feb 17 23:22:07 2022 +0100

    GEODE-9326: Replace ACE_Get_Opt (#814)
    
     - Replaced ACE_GET_Opt by Boost alternative.
     - Due to the include changes there was a compilation error in fw_spawn,
       which is solved by this commit.
     - Fixed FD_SETSIZE to 1024 for Win32 to avoid coredump in ACE_Process
---
 cppcache/integration-test/CMakeLists.txt |  1 +
 cppcache/integration-test/fw_dunit.cpp   | 66 ++++++++++++++++----------------
 cppcache/integration-test/fw_spawn.hpp   |  6 ---
 dependencies/boost/CMakeLists.txt        |  2 +
 4 files changed, 37 insertions(+), 38 deletions(-)

diff --git a/cppcache/integration-test/CMakeLists.txt b/cppcache/integration-test/CMakeLists.txt
index 66dede7..901dff2 100644
--- a/cppcache/integration-test/CMakeLists.txt
+++ b/cppcache/integration-test/CMakeLists.txt
@@ -112,6 +112,7 @@ foreach(FILE ${SOURCES})
       ACE::ACE
       Boost::boost
       Boost::iostreams
+      Boost::program_options
       test-cppcache-utils
       _WarningsAsError
       _CppCodeCoverage
diff --git a/cppcache/integration-test/fw_dunit.cpp b/cppcache/integration-test/fw_dunit.cpp
index c102be7..a6d927b 100644
--- a/cppcache/integration-test/fw_dunit.cpp
+++ b/cppcache/integration-test/fw_dunit.cpp
@@ -16,6 +16,11 @@
  * limitations under the License.
  */
 
+#ifdef _WIN32
+// TODO. Remove this whenever ACE_Process is removed
+#define FD_SETSIZE 1024
+#endif
+
 #ifdef USE_SMARTHEAP
 #include <smrtheap.h>
 #endif
@@ -26,10 +31,8 @@
 #include <list>
 #include <map>
 
-#include <ace/Get_Opt.h>
-
-#include <boost/asio.hpp>
 #include <boost/process.hpp>
+#include <boost/program_options.hpp>
 #include <boost/interprocess/mapped_region.hpp>
 
 #ifdef _WIN32
@@ -48,6 +51,7 @@
 
 namespace bp = boost::process;
 namespace bip = boost::interprocess;
+namespace bpo = boost::program_options;
 
 static std::string g_programName;
 static uint32_t g_coordinatorPid = 0;
@@ -729,42 +733,39 @@ int dmain(int argc, char *argv[]) {
 #ifdef USE_SMARTHEAP
   MemRegisterTask();
 #endif
+
   setupCRTOutput();
   auto timebomb = std::chrono::seconds{std::stoi(Utils::getEnv("TIMEBOMB"))};
   TimeBomb tb(timebomb, []() { gClientCleanup.trigger(); });
   tb.arm();
 
-  try {
-    g_programName = argv[0];
-    const ACE_TCHAR options[] = ACE_TEXT("s:m:");
-    ACE_Get_Opt cmd_opts(argc, argv, options);
-
-    int result = 0;
-
-    int workerId = 0;
-    int option = 0;
-    while ((option = cmd_opts()) != EOF) {
-      switch (option) {
-        case 's':
-          workerId = std::stoul(cmd_opts.opt_arg());
-          std::cout << "Using process id: " << workerId << "\n" << std::flush;
-          break;
-        case 'm':
-          g_coordinatorPid = std::stoul(cmd_opts.opt_arg());
-          std::cout << "Using coordinator id: " << g_coordinatorPid << "\n"
-                    << std::flush;
-          break;
-        default:
-          std::cout << "ignoring option: " << cmd_opts.last_option()
-                    << " with value " << cmd_opts.opt_arg() << "\n"
-                    << std::flush;
-      }
-    }
+  g_programName = argv[0];
+  bpo::options_description generic("Options");
+  auto &&options = generic.add_options();
+  options("worker,s", bpo::value<int>(), "Set worker ID");
+  options("coordinator,m", bpo::value<int>(), "Set coordinator PID");
+  options("help", "Shows this help");
 
-    if (g_coordinatorPid == 0) {
-      g_coordinatorPid = boost::this_process::get_id();
-    }
+  bpo::variables_map vm;
+  bpo::store(bpo::parse_command_line(argc, argv, generic), vm);
+  bpo::notify(vm);
 
+  int result = 0;
+  int workerId = 0;
+
+  auto iter = vm.find("worker");
+  if (iter != vm.end()) {
+    workerId = iter->second.as<int>();
+  }
+
+  iter = vm.find("coordinator");
+  if (iter != vm.end()) {
+    g_coordinatorPid = iter->second.as<int>();
+  } else {
+    g_coordinatorPid = boost::this_process::get_id();
+  }
+
+  try {
     if (workerId > 0) {
       dunit::TestWorker worker(workerId);
       worker.begin();
@@ -783,6 +784,7 @@ int dmain(int argc, char *argv[]) {
     std::cout << "final worker id " << workerId << ", result " << result
               << "\n";
     std::cout << "before calling cleanup " << workerId << "\n";
+
     gClientCleanup.trigger();
     std::cout << "after calling cleanup\n";
     return result;
diff --git a/cppcache/integration-test/fw_spawn.hpp b/cppcache/integration-test/fw_spawn.hpp
index c40bc25..8ebee0e 100644
--- a/cppcache/integration-test/fw_spawn.hpp
+++ b/cppcache/integration-test/fw_spawn.hpp
@@ -23,12 +23,6 @@
 
 // @TODO, this out this include list..
 
-#if defined(_WIN32)
-#if (FD_SETSIZE != 1024)
-+++bad fdsetsize...
-#endif
-#endif
-
 #include <ace/Process.h>
 #include <ace/Log_Msg.h>
 #include <boost/iostreams/device/file_descriptor.hpp>
diff --git a/dependencies/boost/CMakeLists.txt b/dependencies/boost/CMakeLists.txt
index 97dc3f2..000770c 100644
--- a/dependencies/boost/CMakeLists.txt
+++ b/dependencies/boost/CMakeLists.txt
@@ -29,6 +29,7 @@ set(B2_FLAGS
   --with-system
   --with-log
   --with-iostreams
+  --with-program_options
   --layout=system
   address-model=${BUILD_BITS}
   link=static
@@ -149,6 +150,7 @@ add_boost_library(chrono DEPENDENCIES Boost::chrono)
 add_boost_library(stacktrace LIBRARIES "" DEPENDENCIES Boost::boost)
 add_boost_library(asio LIBRARIES "" DEPENDENCIES Boost::boost)
 add_boost_library(process LIBRARIES "" DEPENDENCIES Boost::system)
+add_boost_library(program_options DEPENDENCIES Boost::system)
 add_boost_library(regex DEPENDENCIES Boost::boost)
 
 target_compile_definitions(boost_stacktrace INTERFACE