diff options
Diffstat (limited to 'utils/src')
-rw-r--r-- | utils/src/hiperf.cc | 34 | ||||
-rw-r--r-- | utils/src/ping_client.cc | 15 | ||||
-rw-r--r-- | utils/src/ping_server.cc | 23 |
3 files changed, 67 insertions, 5 deletions
diff --git a/utils/src/hiperf.cc b/utils/src/hiperf.cc index 221a8746b..65ee315f5 100644 --- a/utils/src/hiperf.cc +++ b/utils/src/hiperf.cc @@ -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> @@ -25,6 +27,10 @@ #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; } diff --git a/utils/src/ping_client.cc b/utils/src/ping_client.cc index 24f7bd7c9..a99652b9c 100644 --- a/utils/src/ping_client.cc +++ b/utils/src/ping_client.cc @@ -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 };
+ 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; } diff --git a/utils/src/ping_server.cc b/utils/src/ping_server.cc index 19de34fec..9d68aec34 100644 --- a/utils/src/ping_server.cc +++ b/utils/src/ping_server.cc @@ -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; } |