[HICN-20] This source upgrade allows to compile ping_client, ping_server and hiperf... 99/17199/13
authorAngelo Mantellini <manangel@cisco.com>
Thu, 31 Jan 2019 09:36:54 +0000 (10:36 +0100)
committerAngelo Mantellini <manangel@cisco.com>
Thu, 31 Jan 2019 10:17:49 +0000 (11:17 +0100)
Change-Id: I8253aa9aa640644b0daffd95dff202956371d814
Signed-off-by: Angelo Mantellini <manangel@cisco.com>
libtransport/src/hicn/transport/utils/CMakeLists.txt
libtransport/src/hicn/transport/utils/daemonizator.cc
libtransport/src/hicn/transport/utils/daemonizator.h
utils/CMakeLists.txt
utils/src/hiperf.cc
utils/src/ping_client.cc
utils/src/ping_server.cc

index 088fb58..a5daf78 100644 (file)
@@ -16,8 +16,6 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
 list(APPEND SOURCE_FILES
   ${CMAKE_CURRENT_SOURCE_DIR}/string_tokenizer.cc
   ${CMAKE_CURRENT_SOURCE_DIR}/uri.cc
-  ${CMAKE_CURRENT_SOURCE_DIR}/daemonizator.cc
-  ${CMAKE_CURRENT_SOURCE_DIR}/min_filter.h
   ${CMAKE_CURRENT_SOURCE_DIR}/signer.cc
   ${CMAKE_CURRENT_SOURCE_DIR}/verifier.cc
   ${CMAKE_CURRENT_SOURCE_DIR}/identity.cc
@@ -32,7 +30,6 @@ list(APPEND HEADER_FILES
   ${CMAKE_CURRENT_SOURCE_DIR}/string_tokenizer.h
   ${CMAKE_CURRENT_SOURCE_DIR}/hash.h
   ${CMAKE_CURRENT_SOURCE_DIR}/uri.h
-  ${CMAKE_CURRENT_SOURCE_DIR}/daemonizator.h
   ${CMAKE_CURRENT_SOURCE_DIR}/sharable_vector.h
   ${CMAKE_CURRENT_SOURCE_DIR}/branch_prediction.h
   ${CMAKE_CURRENT_SOURCE_DIR}/event_reactor.h
@@ -72,5 +69,14 @@ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
   )
 endif()
 
+if(NOT WIN32)
+  list(APPEND HEADER_FILES
+    ${CMAKE_CURRENT_SOURCE_DIR}/daemonizator.h
+  )
+  list(APPEND SOURCE_FILES
+    ${CMAKE_CURRENT_SOURCE_DIR}/daemonizator.cc
+  )
+endif()
+
 set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE)
-set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE)
+set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE)
\ No newline at end of file
index d9b3109..c51a68d 100644 (file)
@@ -13,6 +13,7 @@
  * limitations under the License.
  */
 
+#ifndef _WIN32
 #include <hicn/transport/errors/runtime_exception.h>
 #include <hicn/transport/utils/daemonizator.h>
 #include <hicn/transport/utils/log.h>
@@ -71,3 +72,5 @@ void Daemonizator::daemonize(bool close_fds) {
 }
 
 }  // namespace utils
+
+#endif
index a21ce8a..028d748 100644 (file)
@@ -14,6 +14,9 @@
  */
 
 #pragma once
+
+#ifndef _WIN32
+
 #include <cstdlib>
 namespace utils {
 
@@ -22,4 +25,6 @@ class Daemonizator {
   static void daemonize(bool close_fds = true);
 };
 
-}  // namespace utils
\ No newline at end of file
+}  // namespace utils
+
+#endif
\ No newline at end of file
index 9d05942..a377132 100644 (file)
@@ -23,6 +23,7 @@ set(CMAKE_MODULE_PATH
 )
 
 include(BuildMacros)
+include(WindowsMacros)
 
 if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
   find_package(Libtransport REQUIRED)
@@ -51,5 +52,6 @@ foreach(util ${UTILS_SRC})
     DEPENDS ${LIBTRANSPORT}
     COMPONENT hicn-utils
     DEFINITIONS ${COMPILER_DEFINITIONS}
+    LINK_LIBRARIES ${WSOCK32_LIBRARY} ${WS2_32_LIBRARY}
   )
 endforeach()
\ No newline at end of file
index 221a874..65ee315 100644 (file)
@@ -15,7 +15,9 @@
 
 #include <hicn/transport/interfaces/socket_consumer.h>
 #include <hicn/transport/interfaces/socket_producer.h>
+#ifndef _WIN32
 #include <hicn/transport/utils/daemonizator.h>
+#endif
 #include <hicn/transport/utils/literals.h>
 
 #include <fstream>
 #include <mcheck.h>
 #endif
 
+#ifdef _WIN32
+#include <hicn/transport/portability/win_portability.h>
+#endif
+
 namespace transport {
 
 namespace interface {
@@ -492,8 +498,10 @@ void usage() {
             << std::endl;
   std::cerr << "usage: hiperf [-S|-C] [options] [prefix|name]" << std::endl;
   std::cerr << "Server or Client:" << std::endl;
+#ifndef _WIN32
   std::cerr << "-D\t\t\t\t\t"
             << "Run as a daemon" << std::endl;
+#endif
   std::cerr << std::endl;
   std::cerr << "Server specific:" << std::endl;
   std::cerr << "-s\t<content_size>\t\t\tSize of the content to publish"
@@ -538,8 +546,14 @@ void usage() {
 }
 
 int main(int argc, char *argv[]) {
+
+#ifndef _WIN32
   // Common
   bool daemon = false;
+#else
+  WSADATA wsaData = { 0 };
+  WSAStartup(MAKEWORD(2, 2), &wsaData);
+#endif
 
   // -1 server, 0 undefined, 1 client
   int role = 0;
@@ -554,12 +568,17 @@ int main(int argc, char *argv[]) {
   ServerConfiguration server_configuration;
 
   int opt;
+#ifndef _WIN32
   while ((opt = getopt(argc, argv, "DSCf:b:d:W:c:vs:rmlk:y:p:hi:x")) != -1) {
     switch (opt) {
       // Common
       case 'D':
         daemon = true;
         break;
+#else
+  while ((opt = getopt(argc, argv, "SCf:b:d:W:c:vs:rmlk:y:p:hi:x")) != -1) {
+    switch (opt) {
+#endif
       case 'f':
         log_file = optarg;
         break;
@@ -685,15 +704,27 @@ int main(int argc, char *argv[]) {
   }
 
   if (log_file) {
+#ifndef _WIN32
     int fd = open(log_file, O_WRONLY | O_APPEND | O_CREAT, S_IWUSR | S_IRUSR);
     dup2(fd, STDOUT_FILENO);
     dup2(STDOUT_FILENO, STDERR_FILENO);
     close(fd);
+#else
+    int fd = _open(log_file, _O_WRONLY | _O_APPEND | _O_CREAT, _S_IWRITE | _S_IREAD);
+    _dup2(fd, STDOUT_FILENO);
+    _dup2(STDOUT_FILENO, STDERR_FILENO);
+    _close(fd);
+#endif
+    dup2(fd, STDOUT_FILENO);
+    dup2(STDOUT_FILENO, STDERR_FILENO);
+    close(fd);
   }
 
+#ifndef _WIN32
   if (daemon) {
     utils::Daemonizator::daemonize(false);
   }
+#endif
 
   if (role > 0) {
     HIperfClient c(client_configuration);
@@ -712,6 +743,9 @@ int main(int argc, char *argv[]) {
 
   std::cout << "Bye bye" << std::endl;
 
+#ifdef _WIN32
+  WSACleanup();
+#endif
   return 0;
 }
 
index 24f7bd7..a99652b 100644 (file)
@@ -76,10 +76,10 @@ class Configuration {
 
 class Client : interface::BasePortal::ConsumerCallback {
  public:
-  Client(Configuration *c) 
+  Client(Configuration *c)
     : portal_(),
-      signals_(portal_.getIoService(), SIGINT, SIGQUIT) {
-    // Let the main thread to catch SIGINT and SIGQUIT
+      signals_(portal_.getIoService(), SIGINT) {
+    // Let the main thread to catch SIGINT
     portal_.connect();
     portal_.setConsumerCallback(this);
 
@@ -341,6 +341,12 @@ void help() {
 }
 
 int main(int argc, char *argv[]) {
+
+#ifdef _WIN32
+  WSADATA wsaData = { 0 };\r
+  WSAStartup(MAKEWORD(2, 2), &wsaData);
+#endif
+
   Configuration *c = new Configuration();
   int opt;
   std::string producer_certificate = "";
@@ -419,6 +425,9 @@ int main(int argc, char *argv[]) {
       << std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count()
       << std::endl;
 
+#ifdef _WIN32
+  WSACleanup();
+#endif
   return 0;
 }
 
index 19de34f..9d68aec 100644 (file)
@@ -14,7 +14,9 @@
  */
 
 #include <hicn/transport/interfaces/socket_producer.h>
+#ifndef _WIN32
 #include <hicn/transport/utils/daemonizator.h>
+#endif
 #include <hicn/transport/utils/signer.h>
 #include <hicn/transport/utils/string_tokenizer.h>
 
@@ -183,14 +185,21 @@ void help() {
   std::cout << "-D        dump, dumps sent and received packets (default false)"
             << std::endl;
   std::cout << "-q        quite, not prints (default false)" << std::endl;
+#ifndef _WIN32
   std::cout << "-d        daemon mode" << std::endl;
+#endif
   std::cout << "-H        prints this message" << std::endl;
 }
 
 int main(int argc, char **argv) {
+#ifdef _WIN32
+  WSADATA wsaData = { 0 };
+  WSAStartup(MAKEWORD(2, 2), &wsaData);
+#else
+  bool daemon = false;
+#endif
   std::string name_prefix = "b001::0/64";
   std::string delimiter = "/";
-  bool daemon = false;
   bool verbose = false;
   bool dump = false;
   bool quite = false;
@@ -203,7 +212,11 @@ int main(int argc, char **argv) {
   bool sign = false;
 
   int opt;
+#ifndef _WIN32
   while ((opt = getopt(argc, argv, "s:n:t:qfrVDdHk:p:")) != -1) {
+#else
+  while ((opt = getopt(argc, argv, "s:n:t:qfrVDHk:p:")) != -1) {
+#endif
     switch (opt) {
       case 's':
         object_size = std::stoi(optarg);
@@ -225,9 +238,11 @@ int main(int argc, char **argv) {
         dump = false;
         quite = true;
         break;
+#ifndef _WIN32
       case 'd':
         daemon = true;
         break;
+#endif
       case 'f':
         flags = true;
         break;
@@ -248,9 +263,11 @@ int main(int argc, char **argv) {
     }
   }
 
+#ifndef _WIN32
   if (daemon) {
     utils::Daemonizator::daemonize();
   }
+#endif
 
   core::Prefix producer_namespace(name_prefix);
 
@@ -287,7 +304,9 @@ int main(int argc, char **argv) {
   p.connect();
 
   p.serveForever();
-
+#ifdef _WIN32
+  WSACleanup();
+#endif
   return 0;
 }