From 7f6e22c0e91ab3a4ec6651c4eacc59860e2f9d30 Mon Sep 17 00:00:00 2001 From: Eldar Shalev Date: Wed, 3 Aug 2022 19:29:15 +0300 Subject: [PATCH] issue 2935075: Add preprocessor definition for windows --- src/client.cpp | 14 ++++----- src/common.cpp | 2 +- src/common.h | 4 +-- src/defs.h | 8 +++--- src/input_handlers.h | 2 +- src/iohandlers.cpp | 2 +- src/iohandlers.h | 2 +- src/ip_address.cpp | 2 +- src/ip_address.h | 2 +- src/os_abstract.cpp | 55 ++++++++++++++++++------------------ src/os_abstract.h | 20 ++++++------- src/port_descriptor.h | 4 +-- src/server.cpp | 2 +- src/sockperf.cpp | 38 ++++++++++++------------- src/ticks.cpp | 2 +- src/ticks_os.h | 6 ++-- win/project/sockperf.vcxproj | 10 +++---- 17 files changed, 88 insertions(+), 87 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 29d3c9ee..df49c702 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -204,7 +204,7 @@ void printHistogram(uint32_t binSize, std::map &activeBins, std::map::iterator itr; // Scale to terminal -#ifndef WIN32 +#ifndef __windows__ struct winsize size; ioctl(STDOUT_FILENO, TIOCGWINSZ, &size); terminalWidth = size.ws_col; @@ -824,7 +824,7 @@ static int _connect_check(int ifd) { #define POLL_TIMEOUT_MS 1 -#ifdef WIN32 +#ifdef __windows__ fd_set rfds, wfds; struct timeval tv; tv.tv_sec = 0; @@ -841,7 +841,7 @@ static int _connect_check(int ifd) { struct pollfd fds = { .fd = ifd, .events = POLLIN | POLLOUT, }; pollrc = poll(&fds, 1, POLL_TIMEOUT_MS); avail = pollrc > 0 && (fds.revents & (POLLIN | POLLOUT)); -#endif /* WIN32 */ +#endif /* __windows__ */ if (pollrc < 0) { log_err("Failed to poll for events during connection establishment"); @@ -884,11 +884,11 @@ int Clientss_family == AF_UNIX && g_pApp->m_const_params.sock_type == SOCK_DGRAM) { // Need to bind localy -#ifdef WIN32 +#ifdef __windows__ log_err("AF_UNIX with DGRAM isn't supported in windows"); rc = SOCKPERF_ERR_SOCKET; break; -#else +#else // __windows__ if (p_client_bind_addr->addr_un.sun_path[0] == 0) { // no specific addr client_info was provoided std::string sun_path = build_client_socket_name(&s_user_params.addr.addr_un, getpid(), ifd); log_dbg("No client name was provided, setting addr_un.sun_path to %s\n", @@ -906,7 +906,7 @@ int Client(p_info->fd_min, p_info->fd_max, p_info->fd_num); break; } -#ifndef WIN32 +#ifndef __windows__ case POLL: { client_handler(p_info->fd_min, p_info->fd_max, p_info->fd_num); break; diff --git a/src/common.cpp b/src/common.cpp index c7a9812e..8ddaeda6 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -231,7 +231,7 @@ void hexdump(void *ptr, int buflen) { const char *handler2str(fd_block_handler_t type) { // must be coordinated with fd_block_handler_t in defs.h static const char *s_fds_handle_desc[FD_HANDLE_MAX] = { "recvfrom", "recvfrom", "select" -#ifndef WIN32 +#ifndef __windows__ , "poll", "epoll", #ifdef USING_VMA_EXTRA_API diff --git a/src/common.h b/src/common.h index 423ec54b..1d00e85d 100644 --- a/src/common.h +++ b/src/common.h @@ -82,7 +82,7 @@ static inline int msg_sendto(int fd, uint8_t *buf, int nbytes, * the MSG_NOSIGNAL flag. * Note: another way is call signal (SIGPIPE,SIG_IGN); */ -#ifndef WIN32 +#ifndef __windows__ flags = MSG_NOSIGNAL; /* @@ -94,7 +94,7 @@ static inline int msg_sendto(int fd, uint8_t *buf, int nbytes, if (g_pApp->m_const_params.is_nonblocked_send) { flags |= MSG_DONTWAIT; } -#endif +#endif // __windows__ int size = nbytes; if (g_fds_array[fd]->sock_type == SOCK_STREAM) { diff --git a/src/defs.h b/src/defs.h index 0520f6d0..c9194a54 100644 --- a/src/defs.h +++ b/src/defs.h @@ -31,7 +31,7 @@ #define __STDC_FORMAT_MACROS -#ifdef WIN32 +#ifdef __windows__ #include #include #include @@ -96,7 +96,7 @@ typedef unsigned short int sa_family_t; #include "playback.h" #include "ip_address.h" -#if !defined(WIN32) && !defined(__FreeBSD__) +#if !defined(__windows__) && !defined(__FreeBSD__) #include "vma-xlio-redirect.h" #ifdef USING_VMA_EXTRA_API #include @@ -152,7 +152,7 @@ const uint32_t TEST_FIRST_CONNECTION_FIRST_PACKET_TTL_THRESHOLD_MSEC = 50; ":(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[0-5]?[0-9]{1,4})" \ "(:([a-zA-Z0-9\\.\\-]+|\\[([a-fA-F0-9.:]+)\\]))?[\r\n]" -#ifdef WIN32 +#ifdef __windows__ #define UNIX_DOMAIN_SOCKET_FORMAT_REG_EXP \ "^[UuTt]:([A-Za-z]:[\\\\/].*)[\r\n]*" #define RESOLVE_ADDR_FORMAT_SOCKET \ @@ -635,7 +635,7 @@ typedef enum { // must be coordinated with s_fds_handle_desc in common.cpp RECVFROM = 0, RECVFROMMUX, SELECT, -#ifndef WIN32 +#ifndef __windows__ POLL, EPOLL, #endif diff --git a/src/input_handlers.h b/src/input_handlers.h index 4d5f6072..793b1d36 100644 --- a/src/input_handlers.h +++ b/src/input_handlers.h @@ -62,7 +62,7 @@ class RecvFromInputHandler : public MessageParser { the MSG_NOSIGNAL flag. Note: another way is call signal (SIGPIPE,SIG_IGN); */ -#ifndef WIN32 +#ifndef __windows__ flags = MSG_NOSIGNAL; #endif diff --git a/src/iohandlers.cpp b/src/iohandlers.cpp index f3704d23..ffb475ef 100644 --- a/src/iohandlers.cpp +++ b/src/iohandlers.cpp @@ -159,7 +159,7 @@ int IoSelect::prepareNetwork() { return rc; } -#ifndef WIN32 +#ifndef __windows__ //============================================================================== //------------------------------------------------------------------------------ IoPoll::IoPoll(int _fd_min, int _fd_max, int _fd_num) diff --git a/src/iohandlers.h b/src/iohandlers.h index 5b709619..98b3e4f3 100644 --- a/src/iohandlers.h +++ b/src/iohandlers.h @@ -230,7 +230,7 @@ class IoSelect : public IoHandler { fd_set m_readfds, m_save_fds; }; -#ifndef WIN32 +#ifndef __windows__ //============================================================================== class IoPoll : public IoHandler { public: diff --git a/src/ip_address.cpp b/src/ip_address.cpp index 3b65ce2b..994e42b7 100644 --- a/src/ip_address.cpp +++ b/src/ip_address.cpp @@ -29,7 +29,7 @@ #include "ip_address.h" #include "common.h" -#ifdef WIN32 +#ifdef __windows__ #include #else #include diff --git a/src/ip_address.h b/src/ip_address.h index 46f1c8da..b430c0d1 100644 --- a/src/ip_address.h +++ b/src/ip_address.h @@ -29,7 +29,7 @@ #ifndef IP_ADDRESS_H_ #define IP_ADDRESS_H_ -#ifdef WIN32 +#ifdef __windows__ #include #include #include diff --git a/src/os_abstract.cpp b/src/os_abstract.cpp index 7882cb21..d21a8b8b 100644 --- a/src/os_abstract.cpp +++ b/src/os_abstract.cpp @@ -31,7 +31,7 @@ #include void os_printf_backtrace(void) { -#ifdef WIN32 +#ifdef __windows__ unsigned int i; void *stack[100]; unsigned short frames; @@ -69,7 +69,7 @@ void os_printf_backtrace(void) { // Thread functions void os_thread_init(os_thread_t *thr) { -#ifdef WIN32 +#ifdef __windows__ thr->hThread = NULL; thr->tid = 0; #else @@ -78,19 +78,19 @@ void os_thread_init(os_thread_t *thr) { } void os_thread_close(os_thread_t *thr) { -#ifdef WIN32 +#ifdef __windows__ if (thr->hThread) CloseHandle(thr->hThread); #endif } void os_thread_detach(os_thread_t *thr) { -#ifndef WIN32 +#ifndef __windows__ pthread_detach(thr->tid); #endif } int os_thread_exec(os_thread_t *thr, void *(*start)(void *), void *arg) { -#ifdef WIN32 +#ifdef __windows__ if (thr->hThread) CloseHandle(thr->hThread); thr->hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start, arg, 0, &thr->tid); if (thr->hThread == INVALID_HANDLE_VALUE) { @@ -111,7 +111,7 @@ int os_thread_exec(os_thread_t *thr, void *(*start)(void *), void *arg) { } void os_thread_kill(os_thread_t *thr) { -#ifdef WIN32 +#ifdef __windows__ DWORD exit_code; if (GetExitCodeThread(thr, &exit_code)) TerminateThread(thr, exit_code); // kill thread #else @@ -120,7 +120,7 @@ void os_thread_kill(os_thread_t *thr) { } void os_thread_join(os_thread_t *thr) { -#ifdef WIN32 +#ifdef __windows__ WaitForSingleObject(thr, INFINITE); #else pthread_join(thr->tid, 0); @@ -129,7 +129,7 @@ void os_thread_join(os_thread_t *thr) { os_thread_t os_getthread(void) { os_thread_t mythread; -#ifdef WIN32 +#ifdef __windows__ mythread.tid = GetCurrentThreadId(); mythread.hThread = GetCurrentThread(); #elif __FreeBSD__ @@ -143,7 +143,7 @@ os_thread_t os_getthread(void) { // Mutex functions void os_mutex_init(os_mutex_t *lock) { -#ifdef WIN32 +#ifdef __windows__ lock->mutex = CreateMutex(NULL, FALSE, NULL); #else pthread_mutex_init(&lock->mutex, NULL); @@ -151,7 +151,7 @@ void os_mutex_init(os_mutex_t *lock) { } void os_mutex_close(os_mutex_t *lock) { -#ifdef WIN32 +#ifdef __windows__ CloseHandle(lock->mutex); #else pthread_mutex_destroy(&lock->mutex); @@ -159,7 +159,7 @@ void os_mutex_close(os_mutex_t *lock) { } void os_mutex_lock(os_mutex_t *lock) { -#ifdef WIN32 +#ifdef __windows__ WaitForSingleObject(lock->mutex, INFINITE); #else pthread_mutex_lock(&lock->mutex); @@ -167,7 +167,7 @@ void os_mutex_lock(os_mutex_t *lock) { } void os_mutex_unlock(os_mutex_t *lock) { -#ifdef WIN32 +#ifdef __windows__ ReleaseMutex(lock->mutex); #else pthread_mutex_unlock(&lock->mutex); @@ -175,7 +175,7 @@ void os_mutex_unlock(os_mutex_t *lock) { } int os_set_nonblocking_socket(int fd) { -#ifdef WIN32 +#ifdef __windows__ int iResult; u_long iMode = 1; // = Non-blocking iResult = ioctlsocket(fd, FIONBIO, &iMode); @@ -202,7 +202,7 @@ int os_set_nonblocking_socket(int fd) { } void os_set_signal_action(int signum, sig_handler handler) { -#ifdef WIN32 +#ifdef __windows__ // Meny: No SIGALRM on Windows, A different thread handles test duration timer. signal(signum, handler); #else @@ -217,7 +217,7 @@ void os_set_signal_action(int signum, sig_handler handler) { } int os_daemonize() { -#ifdef WIN32 +#ifdef __windows__ printf("ERROR: daemonize is not supported!\n"); return -1; #else @@ -229,7 +229,7 @@ int os_daemonize() { #endif } -#ifdef WIN32 +#ifdef __windows__ struct TimeHandler { itimerval myTimer; sig_handler *handler; @@ -243,7 +243,7 @@ struct TimeHandler { int os_set_duration_timer(const itimerval &timer, sig_handler handler) { int ret; -#ifdef WIN32 +#ifdef __windows__ // Creating a new thread to handle timer logic os_thread_t timer_thread; os_thread_init(&timer_thread); @@ -267,7 +267,7 @@ int os_set_duration_timer(const itimerval &timer, sig_handler handler) { } void os_set_disarm_timer(const itimerval& timer) { -#ifdef WIN32 +#ifdef __windows__ if (SetTimer(NULL, 0, 0, NULL) == 0) { printf("ERROR: SetTimer() failed when disarming"); } @@ -279,8 +279,9 @@ void os_set_disarm_timer(const itimerval& timer) { } + const char* os_get_error(int res) { -#ifdef WIN32 +#ifdef __windows__ return gai_strerrorA(res); #else return gai_strerror(res); @@ -288,14 +289,14 @@ const char* os_get_error(int res) { } void os_unlink_unix_path(char* path) { -#ifdef WIN32 +#ifdef __windows__ remove(path); #else unlink(path); #endif } -#ifdef WIN32 +#ifdef __windows__ // Meny: This function contains test duration timer logic void *win_set_timer(void *_pTimeHandler) { TimeHandler *pTimeHandler = (TimeHandler *)_pTimeHandler; @@ -332,7 +333,7 @@ void *win_set_timer(void *_pTimeHandler) { #endif bool os_sock_startup() { -#ifdef WIN32 +#ifdef __windows__ WSADATA wsaData; if (WSAStartup(0x202, &wsaData) != 0) { return false; @@ -344,7 +345,7 @@ bool os_sock_startup() { } bool os_sock_cleanup() { -#ifdef WIN32 +#ifdef __windows__ if (WSACleanup() != 0) { return false; } @@ -355,7 +356,7 @@ bool os_sock_cleanup() { } void os_init_cpuset(os_cpuset_t *_mycpuset) { -#ifdef WIN32 +#ifdef __windows__ _mycpuset->cpuset = 0; #else CPU_ZERO(&_mycpuset->cpuset); @@ -365,7 +366,7 @@ void os_init_cpuset(os_cpuset_t *_mycpuset) { void os_cpu_set(os_cpuset_t *_mycpuset, long _cpu_from, long _cpu_cur) { while ((_cpu_from <= _cpu_cur)) { -#ifdef WIN32 +#ifdef __windows__ _mycpuset->cpuset = (int)(1 << _cpu_from); #else CPU_SET(_cpu_from, &(_mycpuset->cpuset)); @@ -375,7 +376,7 @@ void os_cpu_set(os_cpuset_t *_mycpuset, long _cpu_from, long _cpu_cur) { } int os_set_affinity(const os_thread_t &thread, const os_cpuset_t &_mycpuset) { -#ifdef WIN32 +#ifdef __windows__ if (0 == SetThreadAffinityMask(thread.hThread, _mycpuset.cpuset)) return -1; #else // Can't use thread.tid since it's syscall and not pthread_t @@ -386,7 +387,7 @@ int os_set_affinity(const os_thread_t &thread, const os_cpuset_t &_mycpuset) { } int os_get_max_active_fds_num() { -#ifdef WIN32 +#ifdef __windows__ return MAX_OPEN_FILES; #else static int max_active_fd_num = 0; diff --git a/src/os_abstract.h b/src/os_abstract.h index 61c577e1..2804f373 100644 --- a/src/os_abstract.h +++ b/src/os_abstract.h @@ -43,10 +43,10 @@ #include "ticks_os.h" /*********************************************************************************** -* WIN32 +* __windows__ ***********************************************************************************/ -#ifdef WIN32 +#ifdef __windows__ #include #include // backtrace @@ -164,7 +164,7 @@ void *win_set_timer(void *p_timer); ***********************************************************************************/ typedef struct os_thread_t { -#ifdef WIN32 +#ifdef __windows__ HANDLE hThread; DWORD tid; #else @@ -173,7 +173,7 @@ typedef struct os_thread_t { } os_thread_t; typedef struct os_mutex_t { -#ifndef WIN32 +#ifndef __windows__ pthread_mutex_t mutex; #else HANDLE mutex; @@ -181,7 +181,7 @@ typedef struct os_mutex_t { } os_mutex_t; typedef struct os_cpuset_t { -#ifdef WIN32 +#ifdef __windows__ DWORD_PTR cpuset; #elif __FreeBSD__ cpuset_t cpuset; @@ -204,7 +204,7 @@ const char* os_get_error(int res); void os_unlink_unix_path(char* path); // Colors -#ifdef WIN32 +#ifdef __windows__ #define MAGNETA "" #define RED "" #define ENDCOLOR "" @@ -240,7 +240,7 @@ int os_set_affinity(const os_thread_t &thread, const os_cpuset_t &_mycpuset); // ERRORS inline bool os_err_in_progress() { -#ifdef WIN32 +#ifdef __windows__ // In Windows it's WSAEINPROGRESS for blocking sockets and WSAEWOULDBLOCK for non-vlocking // sockets return (WSAGetLastError() == WSAEWOULDBLOCK || WSAGetLastError() == WSAEINPROGRESS); @@ -250,7 +250,7 @@ inline bool os_err_in_progress() { } inline bool os_err_eagain() { -#ifdef WIN32 +#ifdef __windows__ return (WSAGetLastError() == WSAEWOULDBLOCK); #else return (errno == EAGAIN); @@ -258,14 +258,14 @@ inline bool os_err_eagain() { } inline bool os_err_conn_reset() { -#ifdef WIN32 +#ifdef __windows__ return (WSAGetLastError() == WSAECONNRESET); #else return (errno == ECONNRESET); #endif } -#ifdef WIN32 +#ifdef __windows__ #define _max(x, y) max(x, y) #define _min(x, y) min(x, y) #else diff --git a/src/port_descriptor.h b/src/port_descriptor.h index 3dff1844..3ea6b435 100644 --- a/src/port_descriptor.h +++ b/src/port_descriptor.h @@ -31,7 +31,7 @@ #include -#ifdef WIN32 +#ifdef __windows__ typedef uint16_t in_port_t; @@ -39,7 +39,7 @@ typedef uint16_t in_port_t; #include /* internet address manipulation */ -#endif // WIN32 +#endif // __windows__ typedef struct port_descriptor { int sock_type; /**< SOCK_STREAM (tcp), SOCK_DGRAM (udp), SOCK_RAW (ip) */ diff --git a/src/server.cpp b/src/server.cpp index cbfbbfed..f6ab3cbc 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -411,7 +411,7 @@ void server_handler(handler_info *p_info) { server_handler(p_info->fd_min, p_info->fd_max, p_info->fd_num); break; } -#ifndef WIN32 +#ifndef __windows__ case POLL: { server_handler(p_info->fd_min, p_info->fd_max, p_info->fd_num); break; diff --git a/src/sockperf.cpp b/src/sockperf.cpp index 0b1f6ffb..fd55d703 100644 --- a/src/sockperf.cpp +++ b/src/sockperf.cpp @@ -101,7 +101,7 @@ #include #include -#ifndef WIN32 +#ifndef __windows__ #include #endif @@ -188,7 +188,7 @@ static const AOPT_DESC common_opt_desc[] = { AOPT_ARG, aopt_set_literal('F'), aopt_set_string("iomux-type"), -#ifdef WIN32 +#ifdef __windows__ "Type of multiple file descriptors handle [s|select|r|recvfrom](default select)." #elif __FreeBSD__ "Type of multiple file descriptors handle [s|select|p|poll|r|recvfrom](default select)." @@ -201,7 +201,7 @@ static const AOPT_DESC common_opt_desc[] = { AOPT_ARG, aopt_set_literal(0), aopt_set_string("timeout"), -#ifdef WIN32 +#ifdef __windows__ "Set select timeout to , -1 for infinite (default is 10 msec)." #elif __FreeBSD__ "Set select/poll timeout to , -1 for infinite (default is 10 msec)." @@ -266,7 +266,7 @@ static const AOPT_DESC common_opt_desc[] = { { OPT_PREWARMUPWAIT, AOPT_ARG, aopt_set_literal(0), aopt_set_string("pre-warmup-wait"), "Time to wait before sending warm up messages (seconds)." }, -#ifndef WIN32 +#ifndef __windows__ { OPT_ZCOPYREAD, AOPT_NOARG, aopt_set_literal(0), aopt_set_string("zcopyread", "vmazcopyread"), "Use VMA's zero copy reads API (See VMA's readme)." }, @@ -1518,7 +1518,7 @@ static int proc_mode_server(int id, int argc, const char **argv) { aopt_set_literal(0), aopt_set_string("cpu-affinity"), "Set threads affinity to the given core ids in list format (see: cat /proc/cpuinfo)." }, -#ifndef WIN32 +#ifndef __windows__ { OPT_RXFILTERCB, AOPT_NOARG, aopt_set_literal(0), @@ -1613,7 +1613,7 @@ static int proc_mode_server(int id, int argc, const char **argv) { rc = SOCKPERF_ERR_BAD_ARGUMENT; } } -#ifndef WIN32 +#ifndef __windows__ if (!rc && aopt_check(server_obj, OPT_RXFILTERCB)) { s_user_params.is_rxfiltercb = true; } @@ -1659,7 +1659,7 @@ static int proc_mode_server(int id, int argc, const char **argv) { printf(" " MODULE_NAME " %s [-i ip / --addr address] [-p port] [--mc-rx-if ip] [--mc-tx-if ip] [--mc-source-filter ip]\n", sockperf_modes[id].name); -#ifndef WIN32 +#ifndef __windows__ printf(" " MODULE_NAME " %s -f file [-F s/p/e] [--mc-rx-if ip] [--mc-tx-if ip] [--mc-source-filter ip]\n", sockperf_modes[id].name); @@ -1815,7 +1815,7 @@ static int parse_common_opt(const AOPT_OBJECT *common_obj) { if (optarg) { strncpy(feedfile_name, optarg, MAX_ARGV_SIZE); feedfile_name[MAX_PATH_LENGTH - 1] = '\0'; -#if defined(WIN32) || defined(__FreeBSD__) +#if defined(__windows__) || defined(__FreeBSD__) s_user_params.fd_handler_type = SELECT; #else s_user_params.fd_handler_type = EPOLL; @@ -1838,7 +1838,7 @@ static int parse_common_opt(const AOPT_OBJECT *common_obj) { strncpy(fd_handle_type, optarg, MAX_ARGV_SIZE); fd_handle_type[MAX_ARGV_SIZE - 1] = '\0'; -#ifndef WIN32 +#ifndef __windows__ #ifndef __FreeBSD__ if (!strcmp(fd_handle_type, "epoll") || !strcmp(fd_handle_type, "e")) { s_user_params.fd_handler_type = EPOLL; @@ -1953,7 +1953,7 @@ static int parse_common_opt(const AOPT_OBJECT *common_obj) { errno = 0; int value = strtol(optarg, NULL, 0); if (errno != 0 || value < -1) { -#ifdef WIN32 +#ifdef __windows__ log_msg("'-%d' Invalid select timeout val: %s", OPT_SELECT_TIMEOUT, optarg); #elif __FreeBSD__ log_msg("'-%d' Invalid select/poll timeout val: %s", OPT_SELECT_TIMEOUT, @@ -2004,7 +2004,7 @@ static int parse_common_opt(const AOPT_OBJECT *common_obj) { if (!rc && aopt_check(common_obj, OPT_TOS)) { const char *optarg = aopt_value(common_obj, OPT_TOS); if (optarg) { -#if defined(WIN32) || defined(_WIN32) +#if defined(__windows__) || defined(___windows__) log_msg("TOS option not supported for Windows"); rc = SOCKPERF_ERR_UNSUPPORTED; #else @@ -2017,7 +2017,7 @@ static int parse_common_opt(const AOPT_OBJECT *common_obj) { if (!rc && aopt_check(common_obj, OPT_LLS)) { const char *optarg = aopt_value(common_obj, OPT_LLS); if (optarg) { -#if defined(WIN32) || defined(_WIN32) +#if defined(__windows__) || defined(___windows__) log_msg("LLS option not supported for Windows"); rc = SOCKPERF_ERR_UNSUPPORTED; #else @@ -2093,7 +2093,7 @@ static int parse_common_opt(const AOPT_OBJECT *common_obj) { if (!rc && aopt_check(common_obj, OPT_SOCK_ACCL)) { s_user_params.withsock_accl = true; } -#ifndef WIN32 +#ifndef __windows__ if (!rc && aopt_check(common_obj, OPT_ZCOPYREAD)) { s_user_params.is_zcopyread = true; @@ -2150,7 +2150,7 @@ static int parse_common_opt(const AOPT_OBJECT *common_obj) { } } #endif // !defined(__FreeBSD__) -#endif // !defined(WIN32) +#endif // !defined(__windows__) if (!rc && aopt_check(common_obj, OPT_TCP)) { if (!aopt_check(common_obj, 'f')) { @@ -2365,13 +2365,13 @@ void cleanup() { } if (s_user_params.addr.ss_family == AF_UNIX) { os_unlink_unix_path(s_user_params.client_bind_info.addr_un.sun_path); -#ifndef WIN32 // AF_UNIX with DGRAM isn't supported in Win32 +#ifndef __windows__ // AF_UNIX with DGRAM isn't supported in __windows__ if (s_user_params.mode == MODE_CLIENT && s_user_params.sock_type == SOCK_DGRAM) { // unlink binded client std::string sun_path = build_client_socket_name(&s_user_params.addr.addr_un, getpid(), ifd); log_dbg("unlinking %s", sun_path.c_str()); unlink(sun_path.c_str()); } -#endif +#endif // __windows__ if (s_user_params.mode == MODE_SERVER) os_unlink_unix_path(g_fds_array[ifd]->server_addr.addr_un.sun_path); } @@ -2431,14 +2431,14 @@ static void set_select_timeout(int time_out_msec) { //------------------------------------------------------------------------------ void set_defaults() { -#if !defined(WIN32) && !defined(__FreeBSD__) +#if !defined(__windows__) && !defined(__FreeBSD__) bool success = vma_xlio_try_set_func_pointers(); if (!success) { log_dbg("Failed to set function pointers for system functions."); log_dbg("Check vma-xlio-redirect.cpp for functions which your OS implementation is missing. " "Re-compile sockperf without them."); } -#elif defined WIN32 +#elif defined __windows__ int rc = 0; if (os_sock_startup() == false) { // Only relevant for Windows log_err("Failed to initialize WSA"); @@ -2985,7 +2985,7 @@ static int set_sockets_from_feedfile(const char *feedfile_name) { log_msg("Can't open file: %s\n", feedfile_name); return SOCKPERF_ERR_NOT_EXIST; } -#ifndef WIN32 +#ifndef __windows__ if (!S_ISREG(st_buf.st_mode)) { log_msg("Can't open file: %s -not a regular file.\n", feedfile_name); return SOCKPERF_ERR_NOT_EXIST; diff --git a/src/ticks.cpp b/src/ticks.cpp index 4d863ea3..6a30c71b 100644 --- a/src/ticks.cpp +++ b/src/ticks.cpp @@ -37,7 +37,7 @@ #include #include "clock.h" -#ifndef WIN32 +#ifndef __windows__ #include // for usleep #endif /** diff --git a/src/ticks_os.h b/src/ticks_os.h index faf9b05f..0f23b2c6 100644 --- a/src/ticks_os.h +++ b/src/ticks_os.h @@ -48,7 +48,7 @@ typedef int64_t ticks_t; -#ifdef WIN32 +#ifdef __windows__ #include #include @@ -75,7 +75,7 @@ inline ticks_t timespec2nsec(const struct timespec &_val) { } inline ticks_t os_gettimeoftsc() { -#ifdef WIN32 +#ifdef __windows__ LARGE_INTEGER lp; double PCFreq = 0.0; QueryPerformanceFrequency(&lp); @@ -109,7 +109,7 @@ inline ticks_t os_gettimeoftsc() { } inline void os_ts_gettimeofclock(struct timespec *pts) { -#ifdef WIN32 +#ifdef __windows__ ticks_t val = os_gettimeoftsc(); // probably just NSEC_IN_SEC pts->tv_sec = val / NSEC_IN_SEC; pts->tv_nsec = val % NSEC_IN_SEC; diff --git a/win/project/sockperf.vcxproj b/win/project/sockperf.vcxproj index 2544101f..2468e4b9 100644 --- a/win/project/sockperf.vcxproj +++ b/win/project/sockperf.vcxproj @@ -85,7 +85,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + __windows__;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) Console @@ -99,7 +99,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + __windows__;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) Console @@ -115,7 +115,7 @@ MaxSpeed true true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + __windows__;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) Console @@ -133,7 +133,7 @@ MaxSpeed true true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + __windows__;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true @@ -182,4 +182,4 @@ - \ No newline at end of file +