diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-08-20 10:31:09 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-08-21 07:18:30 -0700 |
| commit | 6305e16ab64e42fd9791819d416a6e3534439b0b (patch) | |
| tree | 8dbb42a07140f0c12a61bf6d6bcf9590f8678ae6 | |
| parent | dd2eda5a90ab86bbde1a9da481a423d367586a73 (diff) | |
| download | nng-6305e16ab64e42fd9791819d416a6e3534439b0b.tar.gz nng-6305e16ab64e42fd9791819d416a6e3534439b0b.tar.bz2 nng-6305e16ab64e42fd9791819d416a6e3534439b0b.zip | |
Conditional platform inclusion cleanups.
We only compile files that are appropriate for the platform. (We
still have guards in place, to allow for a future single .C file
to be built from all the sources.) We also remove the subsystem defines;
if a new platform needs to deviate from POSIX in ways beyond what we
intended here, then that platform should just copy those parts into
a new platform directory, rather than cross including portions from
POSIX.
32 files changed, 222 insertions, 309 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 529e5f48..d7d05c56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,14 +115,17 @@ if (NNG_ENABLE_COVERAGE) endif() endif() +find_package (Threads REQUIRED) + if (CMAKE_SYSTEM_NAME MATCHES "Linux") - find_package (Threads REQUIRED) - add_definitions (-DPLATFORM_POSIX) + add_definitions (-DNNG_PLATFORM_POSIX) + add_definitions (-DNNG_PLATFORM_LINUX) add_definitions (-DNNG_USE_EVENTFD) + set(NNG_PLATFORM_POSIX ON) elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin") - find_package (Threads REQUIRED) - add_definitions (-DPLATFORM_POSIX) + add_definitions (-DNNG_PLATFORM_POSIX) + add_definitions (-DNNG_PLATFORM_POSIX) # macOS 10.12 and later have getentropy, but the older releases # have ARC4_RANDOM, and that is sufficient to our needs. add_definitions (-DNNG_USE_ARC4_RANDOM) @@ -130,27 +133,32 @@ elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin") # macOS added some of CLOCK_MONOTONIC, but the implementation is # broken and unreliable, so don't use it. add_definitions (-DNNG_USE_CLOCKID=CLOCK_REALTIME) + set(NNG_PLATFORM_POSIX ON) elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") - find_package (Threads REQUIRED) - add_definitions (-DPLATFORM_POSIX) + add_definitions (-DNNG_PLATFORM_POSIX) + add_definitions (-DNNG_PLATFORM_FREEBSD) + set(NNG_PLATFORM_POSIX ON) elseif (CMAKE_SYSTEM_NAME MATCHES "NetBSD") - find_package (Threads REQUIRED) - add_definitions (-DPLATFORM_POSIX) + add_definitions (-DNNG_PLATFORM_POSIX) + add_definitions (-DNNG_PLATFORM_NETBSD) + set(NNG_PLATFORM_POSIX ON) elseif (CMAKE_SYSTEM_NAME MATCHES "OpenBSD") - find_package (Threads REQUIRED) - add_definitions (-DPLATFORM_POSIX) + add_definitions (-DNNG_PLATFORM_POSIX) + add_definitions (-DNNG_PLATFORM_OPENBSD) + set(NNG_PLATFORM_POSIX ON) elseif (CMAKE_SYSTEM_NAME MATCHES "SunOS") - find_package (Threads REQUIRED) - add_definitions (-DPLATFORM_POSIX) + add_definitions (-DNNG_PLATFORM_POSIX) + add_definitions (-DNNG_PLATFORM_SUNOS) elseif (CMAKE_SYSTEM_NAME MATCHES "Windows") - add_definitions (-DPLATFORM_WINDOWS) + add_definitions (-DNNG_PLATFORM_WINDOWS) add_definitions (-D_CRT_SECURE_NO_WARNINGS) add_definitions (-D_CRT_RAND_S) + set(NNG_PLATFORM_WINDOWS ON) # Target Windows Vista and later add_definitions (-D_WIN32_WINNT=0x0600) @@ -214,7 +222,7 @@ if (WIN32) endif() else () # Unconditionally declare the following feature test macros. These are - # needed for some platforms (glibc and SunOS/illumos) and should be harmless + # needed for some platforms (glibc and SunOS/illumos) and are harmless # on the others. add_definitions (-D_GNU_SOURCE) add_definitions (-D_REENTRANT) @@ -226,26 +234,11 @@ else () nng_check_lib (nsl gethostbyname NNG_HAVE_LIBNSL) nng_check_lib (socket socket NNG_HAVE_LIBSOCKET) -# nng_check_sym (atomic_cas_32 atomic.h NNG_HAVE_ATOMIC_SOLARIS) nng_check_sym (AF_UNIX sys/socket.h NNG_HAVE_UNIX_SOCKETS) nng_check_sym (backtrace_symbols_fd execinfo.h NNG_HAVE_BACKTRACE) nng_check_struct_member(msghdr msg_control sys/socket.h NNG_HAVE_MSG_CONTROL) endif () -#check_c_source_compiles (" -# #include <stdint.h> -# int main() -# { -# volatile uint32_t n = 0; -# __sync_fetch_and_add (&n, 1); -# __sync_fetch_and_sub (&n, 1); -# return 0; -# } -#" NNG_HAVE_GCC_ATOMIC_BUILTINS) -#if (NNG_HAVE_GCC_ATOMIC_BUILTINS) -# add_definitions (-DNNG_HAVE_GCC_ATOMIC_BUILTINS) -#endif () - add_subdirectory (src) if (NNG_TESTS) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9ecce72c..1510d633 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -75,37 +75,6 @@ set (NNG_SOURCES core/transport.c core/transport.h - platform/posix/posix_impl.h - platform/posix/posix_config.h - platform/posix/posix_aio.h - platform/posix/posix_pollq.h - - platform/posix/posix_alloc.c - platform/posix/posix_clock.c - platform/posix/posix_debug.c - platform/posix/posix_epdesc.c - platform/posix/posix_ipc.c - platform/posix/posix_pipe.c - platform/posix/posix_pipedesc.c - platform/posix/posix_pollq_poll.c - platform/posix/posix_rand.c - platform/posix/posix_resolv_gai.c - platform/posix/posix_sockaddr.c - platform/posix/posix_tcp.c - platform/posix/posix_thread.c - platform/posix/posix_udp.c - - platform/windows/win_impl.h - platform/windows/win_clock.c - platform/windows/win_debug.c - platform/windows/win_iocp.c - platform/windows/win_ipc.c - platform/windows/win_net.c - platform/windows/win_pipe.c - platform/windows/win_rand.c - platform/windows/win_resolv.c - platform/windows/win_thread.c - protocol/bus/bus.c protocol/pair/pair_v0.c @@ -130,6 +99,45 @@ set (NNG_SOURCES transport/tcp/tcp.c ) +if (NNG_PLATFORM_POSIX) + set (NNG_SOURCES ${NNG_SOURCES} + platform/posix/posix_impl.h + platform/posix/posix_config.h + platform/posix/posix_aio.h + platform/posix/posix_pollq.h + + platform/posix/posix_alloc.c + platform/posix/posix_clock.c + platform/posix/posix_debug.c + platform/posix/posix_epdesc.c + platform/posix/posix_ipc.c + platform/posix/posix_pipe.c + platform/posix/posix_pipedesc.c + platform/posix/posix_pollq_poll.c + platform/posix/posix_rand.c + platform/posix/posix_resolv_gai.c + platform/posix/posix_sockaddr.c + platform/posix/posix_tcp.c + platform/posix/posix_thread.c + platform/posix/posix_udp.c + ) +endif() + +if (NNG_PLATFORM_WINDOWS) + set (NNG_SOURCES ${NNG_SOURCES} + platform/windows/win_impl.h + platform/windows/win_clock.c + platform/windows/win_debug.c + platform/windows/win_iocp.c + platform/windows/win_ipc.c + platform/windows/win_net.c + platform/windows/win_pipe.c + platform/windows/win_rand.c + platform/windows/win_resolv.c + platform/windows/win_thread.c + ) +endif() + include_directories(AFTER SYSTEM ${PROJECT_SOURCE_DIR}/src) # Provide same folder structure in IDE as on disk diff --git a/src/core/platform.h b/src/core/platform.h index f6f0b974..6e049bb3 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -345,9 +345,9 @@ extern void nni_plat_pipe_close(int, int); // Actual platforms we support. This is included up front so that we can // get the specific types that are supplied by the platform. -#if defined(PLATFORM_POSIX) +#if defined(NNG_PLATFORM_POSIX) #include "platform/posix/posix_impl.h" -#elif defined(PLATFORM_WINDOWS) +#elif defined(NNG_PLATFORM_WINDOWS) #include "platform/windows/win_impl.h" #else #error "unknown platform" diff --git a/src/platform/posix/posix_alloc.c b/src/platform/posix/posix_alloc.c index a3cd29b9..3321f49c 100644 --- a/src/platform/posix/posix_alloc.c +++ b/src/platform/posix/posix_alloc.c @@ -9,7 +9,7 @@ #include "core/nng_impl.h" -#ifdef PLATFORM_POSIX_ALLOC +#ifdef NNG_PLATFORM_POSIX #include <stdlib.h> @@ -27,9 +27,4 @@ nni_free(void *ptr, size_t size) free(ptr); } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_posix_alloc_not_used = 0; - -#endif +#endif // NNG_PLATFORM_POSIX diff --git a/src/platform/posix/posix_clock.c b/src/platform/posix/posix_clock.c index 93e0978c..3e46f787 100644 --- a/src/platform/posix/posix_clock.c +++ b/src/platform/posix/posix_clock.c @@ -10,7 +10,7 @@ // POSIX clock stuff. #include "core/nng_impl.h" -#ifdef PLATFORM_POSIX_CLOCK +#ifdef NNG_PLATFORM_POSIX #include <errno.h> #include <string.h> @@ -121,9 +121,4 @@ nni_plat_usleep(nni_duration usec) #endif // NNG_USE_GETTIMEOFDAY -#else - -// Suppress empty symbols warnings in ranlib. -int nni_posix_clock_not_used = 0; - -#endif // PLATFORM_POSIX_CLOCK +#endif // NNG_PLATFORM_POSIX diff --git a/src/platform/posix/posix_config.h b/src/platform/posix/posix_config.h index 8ed6387c..e22c033a 100644 --- a/src/platform/posix/posix_config.h +++ b/src/platform/posix/posix_config.h @@ -42,7 +42,7 @@ #include <time.h> -#ifdef PLATFORM_POSIX +#ifdef NNG_PLATFORM_POSIX // It should never hurt to use DEVURANDOM, since if the device does not // exist then we won't open it. (Provided: it would be bad if the device @@ -63,4 +63,4 @@ #define NNG_USE_POSIX_POLLQ_POLL 1 #define NNG_USE_POSIX_RESOLV_GAI 1 -#endif // PLATFORM_POSIX +#endif // NNG_PLATFORM_POSIX diff --git a/src/platform/posix/posix_debug.c b/src/platform/posix/posix_debug.c index 4af224c4..7619e8e8 100644 --- a/src/platform/posix/posix_debug.c +++ b/src/platform/posix/posix_debug.c @@ -9,7 +9,7 @@ #include "core/nng_impl.h" -#ifdef PLATFORM_POSIX_DEBUG +#ifdef NNG_PLATFORM_POSIX #include <errno.h> #include <stdio.h> @@ -112,9 +112,4 @@ nni_plat_errno(int errnum) return (NNG_ESYSERR + errnum); } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_posix_debug_not_used = 0; - -#endif // PLATFORM_POSIX_DEBUG +#endif // NNG_PLATFORM_POSIX diff --git a/src/platform/posix/posix_epdesc.c b/src/platform/posix/posix_epdesc.c index f511f35f..867f57a7 100644 --- a/src/platform/posix/posix_epdesc.c +++ b/src/platform/posix/posix_epdesc.c @@ -10,7 +10,7 @@ #include "core/nng_impl.h" -#ifdef PLATFORM_POSIX_EPDESC +#ifdef NNG_PLATFORM_POSIX #include "platform/posix/posix_aio.h" #include "platform/posix/posix_pollq.h" @@ -524,9 +524,4 @@ nni_posix_epdesc_fini(nni_posix_epdesc *ed) NNI_FREE_STRUCT(ed); } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_posix_epdesc_not_used = 0; - -#endif // PLATFORM_POSIX_EPDESC +#endif // NNG_PLATFORM_POSIX diff --git a/src/platform/posix/posix_impl.h b/src/platform/posix/posix_impl.h index 81fbd48b..0f238e45 100644 --- a/src/platform/posix/posix_impl.h +++ b/src/platform/posix/posix_impl.h @@ -12,41 +12,41 @@ // Some dependency notes: // -// PLATFORM_POSIX_THREAD depends on PLATFORM_POSIX_CLOCK. Furthermore, -// when using PLATFORM_POSIX_CLOCK, your condition variable timeouts need +// NNG_PLATFORM_POSIX_THREAD depends on NNG_PLATFORM_POSIX_CLOCK. Also, +// when using NNG_PLATFORM_POSIX_CLOCK, your condition variable timeouts need // to use the same base clock values. Normally these should be used -// together. Almost everything depends on PLATFORM_POSIX_DEBUG. -#ifdef PLATFORM_POSIX -#define PLATFORM_POSIX_ALLOC -#define PLATFORM_POSIX_DEBUG -#define PLATFORM_POSIX_CLOCK -#define PLATFORM_POSIX_IPC -#define PLATFORM_POSIX_TCP -#define PLATFORM_POSIX_PIPE -#define PLATFORM_POSIX_RANDOM -#define PLATFORM_POSIX_SOCKET -#define PLATFORM_POSIX_THREAD -#define PLATFORM_POSIX_PIPEDESC -#define PLATFORM_POSIX_EPDESC -#define PLATFORM_POSIX_SOCKADDR -#define PLATFORM_POSIX_UDP +// together. Almost everything depends on NNG_PLATFORM_POSIX_DEBUG. +#ifdef NNG_PLATFORM_POSIX +#define NNG_PLATFORM_POSIX_ALLOC +#define NNG_PLATFORM_POSIX_DEBUG +#define NNG_PLATFORM_POSIX_CLOCK +#define NNG_PLATFORM_POSIX_IPC +#define NNG_PLATFORM_POSIX_TCP +#define NNG_PLATFORM_POSIX_PIPE +#define NNG_PLATFORM_POSIX_RANDOM +#define NNG_PLATFORM_POSIX_SOCKET +#define NNG_PLATFORM_POSIX_THREAD +#define NNG_PLATFORM_POSIX_PIPEDESC +#define NNG_PLATFORM_POSIX_EPDESC +#define NNG_PLATFORM_POSIX_SOCKADDR +#define NNG_PLATFORM_POSIX_UDP #include "platform/posix/posix_config.h" #endif -#ifdef PLATFORM_POSIX_SOCKADDR +#ifdef NNG_PLATFORM_POSIX_SOCKADDR #include <sys/socket.h> extern int nni_posix_sockaddr2nn(nni_sockaddr *, const void *); extern int nni_posix_nn2sockaddr(void *, const nni_sockaddr *); #endif -#ifdef PLATFORM_POSIX_DEBUG +#ifdef NNG_PLATFORM_POSIX_DEBUG extern int nni_plat_errno(int); #endif // Define types that this platform uses. -#ifdef PLATFORM_POSIX_THREAD +#ifdef NNG_PLATFORM_POSIX_THREAD #include <pthread.h> diff --git a/src/platform/posix/posix_ipc.c b/src/platform/posix/posix_ipc.c index a362de6d..3aa9bda3 100644 --- a/src/platform/posix/posix_ipc.c +++ b/src/platform/posix/posix_ipc.c @@ -9,7 +9,7 @@ #include "core/nng_impl.h" -#ifdef PLATFORM_POSIX_IPC +#ifdef NNG_PLATFORM_POSIX #include "platform/posix/posix_aio.h" #include <errno.h> @@ -177,9 +177,4 @@ nni_plat_ipc_pipe_recv(nni_plat_ipc_pipe *p, nni_aio *aio) nni_posix_pipedesc_recv((void *) p, aio); } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_posix_ipc_not_used = 0; - -#endif // PLATFORM_POSIX_IPC +#endif // NNG_PLATFORM_POSIX diff --git a/src/platform/posix/posix_pipe.c b/src/platform/posix/posix_pipe.c index 314e2f5e..bc42abec 100644 --- a/src/platform/posix/posix_pipe.c +++ b/src/platform/posix/posix_pipe.c @@ -10,7 +10,7 @@ // POSIX pipes. #include "core/nng_impl.h" -#ifdef PLATFORM_POSIX_PIPE +#ifdef NNG_PLATFORM_POSIX #include <errno.h> @@ -124,9 +124,4 @@ nni_plat_pipe_close(int wfd, int rfd) #endif // NNG_USE_EVENTFD -#else - -// Suppress empty symbols warnings in ranlib. -int nni_posix_pipe_not_used = 0; - -#endif // PLATFORM_POSIX_PIPE +#endif // NNG_PLATFORM_POSIX diff --git a/src/platform/posix/posix_pipedesc.c b/src/platform/posix/posix_pipedesc.c index b2c1cb1f..8a087256 100644 --- a/src/platform/posix/posix_pipedesc.c +++ b/src/platform/posix/posix_pipedesc.c @@ -10,7 +10,7 @@ #include "core/nng_impl.h" -#ifdef PLATFORM_POSIX_PIPEDESC +#ifdef NNG_PLATFORM_POSIX #include "platform/posix/posix_aio.h" #include "platform/posix/posix_pollq.h" @@ -338,9 +338,4 @@ nni_posix_pipedesc_fini(nni_posix_pipedesc *pd) NNI_FREE_STRUCT(pd); } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_posix_pipedesc_not_used = 0; - -#endif // PLATFORM_POSIX_PIPEDESC +#endif // NNG_PLATFORM_POSIX diff --git a/src/platform/posix/posix_pollq.h b/src/platform/posix/posix_pollq.h index c17ee800..258c6580 100644 --- a/src/platform/posix/posix_pollq.h +++ b/src/platform/posix/posix_pollq.h @@ -11,7 +11,7 @@ #ifndef PLATFORM_POSIX_POLLQ_H #define PLATFORM_POSIX_POLLQ_H -#ifdef PLATFORM_POSIX +#ifdef NNG_PLATFORM_POSIX // This file defines structures we will use for emulating asynchronous I/O // on POSIX. POSIX lacks the support for callback based asynchronous I/O @@ -46,6 +46,6 @@ extern void nni_posix_pollq_remove(nni_posix_pollq_node *); extern void nni_posix_pollq_arm(nni_posix_pollq_node *, int); extern void nni_posix_pollq_disarm(nni_posix_pollq_node *, int); -#endif // PLATFORM_POSIX +#endif // NNG_PLATFORM_POSIX #endif // PLATFORM_POSIX_POLLQ_H diff --git a/src/platform/posix/posix_pollq_poll.c b/src/platform/posix/posix_pollq_poll.c index df5a1799..d8252af9 100644 --- a/src/platform/posix/posix_pollq_poll.c +++ b/src/platform/posix/posix_pollq_poll.c @@ -391,9 +391,4 @@ nni_posix_pollq_sysfini(void) nni_posix_pollq_fini(&nni_posix_global_pollq); } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_posix_pollq_poll_used = 0; - #endif // NNG_USE_POSIX_POLLQ_POLL diff --git a/src/platform/posix/posix_rand.c b/src/platform/posix/posix_rand.c index 4322e491..3f353a74 100644 --- a/src/platform/posix/posix_rand.c +++ b/src/platform/posix/posix_rand.c @@ -10,7 +10,7 @@ // POSIX clock stuff. #include "core/nng_impl.h" -#ifdef PLATFORM_POSIX_RANDOM +#ifdef NNG_PLATFORM_POSIX #include <errno.h> #include <fcntl.h> @@ -21,11 +21,9 @@ #include <time.h> #include <unistd.h> -#ifdef NNG_USE_GETRANDOM +#if defined(NNG_USE_GETRANDOM) #include <linux/random.h> -#endif - -#ifdef NNG_USE_GETENTROPY +#elif defined(NNG_USE_GETENTROPY) #include <sys/random.h> #endif @@ -70,7 +68,7 @@ nni_plat_seed_prng(void *buf, size_t bufsz) } #endif - // As a speical extra guard, let's mixin the data from the + // As a special extra guard, let's mixin the data from the // following system calls. This ensures that even on the most // limited of systems, we have at least *some* level of randomness. // The mixing is done in a way to avoid diminishing entropy we may @@ -86,9 +84,4 @@ nni_plat_seed_prng(void *buf, size_t bufsz) } } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_posix_rand_not_used = 0; - -#endif // PLATFORM_POSIX_RANDOM +#endif // NNG_PLATFORM_POSIX diff --git a/src/platform/posix/posix_resolv_gai.c b/src/platform/posix/posix_resolv_gai.c index dce8270a..27c22c4a 100644 --- a/src/platform/posix/posix_resolv_gai.c +++ b/src/platform/posix/posix_resolv_gai.c @@ -295,9 +295,4 @@ nni_posix_resolv_sysfini(void) nni_mtx_fini(&nni_posix_resolv_mtx); } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_posix_resolv_gai_not_used = 0; - #endif // NNG_USE_POSIX_RESOLV_GAI diff --git a/src/platform/posix/posix_sockaddr.c b/src/platform/posix/posix_sockaddr.c index d3ab9c6d..2514ea73 100644 --- a/src/platform/posix/posix_sockaddr.c +++ b/src/platform/posix/posix_sockaddr.c @@ -10,7 +10,7 @@ #include "core/nng_impl.h" -#ifdef PLATFORM_POSIX_SOCKADDR +#ifdef NNG_PLATFORM_POSIX #include <arpa/inet.h> #include <fcntl.h> @@ -85,9 +85,4 @@ nni_posix_sockaddr2nn(nni_sockaddr *na, const void *sa) return (0); } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_posix_sockaddr_not_used = 0; - -#endif // PLATFORM_POSIX_SOCKADDR +#endif // NNG_PLATFORM_POSIX diff --git a/src/platform/posix/posix_tcp.c b/src/platform/posix/posix_tcp.c index 4efbf47d..185c4e2c 100644 --- a/src/platform/posix/posix_tcp.c +++ b/src/platform/posix/posix_tcp.c @@ -9,7 +9,7 @@ #include "core/nng_impl.h" -#ifdef PLATFORM_POSIX_TCP +#ifdef NNG_PLATFORM_POSIX #include "platform/posix/posix_aio.h" #include <errno.h> @@ -160,9 +160,4 @@ nni_plat_tcp_pipe_recv(nni_plat_tcp_pipe *p, nni_aio *aio) nni_posix_pipedesc_recv((void *) p, aio); } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_posix_net_not_used = 0; - -#endif // PLATFORM_POSIX_TCP +#endif // NNG_PLATFORM_POSIX diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c index 44bfbed2..4278a057 100644 --- a/src/platform/posix/posix_thread.c +++ b/src/platform/posix/posix_thread.c @@ -12,7 +12,7 @@ #include "core/nng_impl.h" -#ifdef PLATFORM_POSIX_THREAD +#ifdef NNG_PLATFORM_POSIX #include <errno.h> #include <fcntl.h> @@ -511,9 +511,4 @@ nni_plat_fini(void) pthread_mutex_unlock(&nni_plat_init_lock); } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_posix_thread_not_used = 0; - -#endif +#endif // NNG_PLATFORM_POSIX diff --git a/src/platform/posix/posix_udp.c b/src/platform/posix/posix_udp.c index 2aa16b36..7bad2db4 100644 --- a/src/platform/posix/posix_udp.c +++ b/src/platform/posix/posix_udp.c @@ -10,7 +10,7 @@ #include "core/nng_impl.h" -#ifdef PLATFORM_POSIX_UDP +#ifdef NNG_PLATFORM_POSIX #include "platform/posix/posix_aio.h" #include "platform/posix/posix_pollq.h" @@ -322,9 +322,4 @@ nni_plat_udp_send(nni_plat_udp *udp, nni_aio *aio) nni_mtx_unlock(&udp->udp_mtx); } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_posix_udp_not_used = 0; - -#endif // PLATFORM_POSIX_UDP +#endif // NNG_PLATFORM_POSIX diff --git a/src/platform/windows/win_clock.c b/src/platform/windows/win_clock.c index 5a874a71..949b2dfc 100644 --- a/src/platform/windows/win_clock.c +++ b/src/platform/windows/win_clock.c @@ -9,7 +9,7 @@ #include "core/nng_impl.h" -#ifdef PLATFORM_WINDOWS +#ifdef NNG_PLATFORM_WINDOWS nni_time nni_plat_clock(void) @@ -41,9 +41,4 @@ nni_plat_usleep(nni_duration dur) } } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_win_clock_not_used = 0; - -#endif // PLATFORM_WINDOWS +#endif // NNG_PLATFORM_WINDOWS diff --git a/src/platform/windows/win_debug.c b/src/platform/windows/win_debug.c index cbf0a61c..c6ee3fed 100644 --- a/src/platform/windows/win_debug.c +++ b/src/platform/windows/win_debug.c @@ -9,7 +9,7 @@ #include "core/nng_impl.h" -#ifdef PLATFORM_WINDOWS +#ifdef NNG_PLATFORM_WINDOWS #include <errno.h> #include <stdio.h> @@ -158,9 +158,4 @@ nni_win_error(int errnum) return (NNG_ESYSERR + errnum); } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_win_debug_not_used = 0; - -#endif // PLATFORM_WINDOWS +#endif // NNG_PLATFORM_WINDOWS diff --git a/src/platform/windows/win_impl.h b/src/platform/windows/win_impl.h index 6455fd5c..d1c5b2a2 100644 --- a/src/platform/windows/win_impl.h +++ b/src/platform/windows/win_impl.h @@ -11,7 +11,7 @@ #ifndef PLATFORM_WIN_IMPL_H #define PLATFORM_WIN_IMPL_H -#ifdef PLATFORM_WINDOWS +#ifdef NNG_PLATFORM_WINDOWS #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN @@ -96,6 +96,6 @@ extern void nni_win_tcp_sysfini(void); extern int nni_win_resolv_sysinit(void); extern void nni_win_resolv_sysfini(void); -#endif // PLATFORM_WINDOWS +#endif // NNG_PLATFORM_WINDOWS #endif // PLATFORM_WIN_IMPL_H diff --git a/src/platform/windows/win_iocp.c b/src/platform/windows/win_iocp.c index 9c3343b7..6d2438d3 100644 --- a/src/platform/windows/win_iocp.c +++ b/src/platform/windows/win_iocp.c @@ -10,7 +10,7 @@ #include "core/nng_impl.h" -#ifdef PLATFORM_WINDOWS +#ifdef NNG_PLATFORM_WINDOWS #define NNI_WIN_IOCP_NTHREADS 4 #include <stdio.h> @@ -270,9 +270,4 @@ nni_win_iocp_sysfini(void) nni_mtx_fini(&nni_win_iocp_mtx); } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_win_iocp_not_used = 0; - -#endif // PLATFORM_WINDOWS +#endif // NNG_PLATFORM_WINDOWS diff --git a/src/platform/windows/win_ipc.c b/src/platform/windows/win_ipc.c index a60815fa..20ae81b5 100644 --- a/src/platform/windows/win_ipc.c +++ b/src/platform/windows/win_ipc.c @@ -10,7 +10,7 @@ #include "core/nng_impl.h" -#ifdef PLATFORM_WINDOWS +#ifdef NNG_PLATFORM_WINDOWS #include <stdio.h> @@ -593,9 +593,4 @@ nni_win_ipc_sysfini(void) nni_mtx_fini(&worker->mtx); } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_win_ipc_not_used = 0; - -#endif // PLATFORM_WINDOWS +#endif // NNG_PLATFORM_WINDOWS diff --git a/src/platform/windows/win_net.c b/src/platform/windows/win_net.c index 80e3724d..dee9b745 100644 --- a/src/platform/windows/win_net.c +++ b/src/platform/windows/win_net.c @@ -10,7 +10,7 @@ #include "core/nng_impl.h" -#ifdef PLATFORM_WINDOWS +#ifdef NNG_PLATFORM_WINDOWS #include <stdio.h> @@ -694,9 +694,4 @@ nni_win_tcp_sysfini(void) WSACleanup(); } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_win_net_not_used = 0; - -#endif // PLATFORM_WINDOWS +#endif // NNG_PLATFORM_WINDOWS diff --git a/src/platform/windows/win_pipe.c b/src/platform/windows/win_pipe.c index edc4df3f..c1690991 100644 --- a/src/platform/windows/win_pipe.c +++ b/src/platform/windows/win_pipe.c @@ -10,11 +10,16 @@ #include "core/nng_impl.h" #include <stdio.h> + // Windows named pipes won't work for us; we *MUST* use sockets. This is // a real sadness, but what can you do. We use an anonymous socket bound -// to localhost and a connected peer. +// to localhost and a connected peer. This is because folks that want to +// use notification pipes (ugh) are expecting this to work with select(), +// which only supports real winsock sockets. We use an ephemeral port, +// bound to localhost; some care is taken to prevent other applications on +// the same host from messing us up by accessing the same port. -#ifdef PLATFORM_WINDOWS +#ifdef NNG_PLATFORM_WINDOWS int nni_plat_pipe_open(int *wfdp, int *rfdp) @@ -138,9 +143,4 @@ nni_plat_pipe_close(int wfd, int rfd) closesocket((SOCKET) rfd); } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_win_pipe_not_used = 0; - -#endif // PLATFORM_WINDOWS +#endif // NNG_PLATFORM_WINDOWS diff --git a/src/platform/windows/win_rand.c b/src/platform/windows/win_rand.c index 38c86572..afe703ef 100644 --- a/src/platform/windows/win_rand.c +++ b/src/platform/windows/win_rand.c @@ -9,7 +9,7 @@ #include "core/nng_impl.h" -#ifdef PLATFORM_WINDOWS +#ifdef NNG_PLATFORM_WINDOWS #include <stdlib.h> @@ -29,9 +29,4 @@ nni_plat_seed_prng(void *buf, size_t bufsz) } } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_win_rand_not_used = 0; - -#endif // PLATFORM_WINDOWS +#endif // NNG_PLATFORM_WINDOWS diff --git a/src/platform/windows/win_resolv.c b/src/platform/windows/win_resolv.c index 4ce12d84..d157cf0f 100644 --- a/src/platform/windows/win_resolv.c +++ b/src/platform/windows/win_resolv.c @@ -9,10 +9,13 @@ #include "core/nng_impl.h" -#ifdef PLATFORM_WINDOWS +#ifdef NNG_PLATFORM_WINDOWS // Modern Windows has an asynchronous resolver, but there are problems -// with it -- it only resolves Unicode names, and it does not support +// with it, where looking up names in DNS can poison results for other +// uses, because the asynchronous resolver *only* considers DNS -- ignoring +// host file, WINS, or other naming services. As a result, we just build +// our own limited asynchronous using a taskq. // We use a single resolver taskq - but we allocate a few threads // for it to ensure that names can be looked up concurrently. This isn't @@ -249,6 +252,13 @@ nni_plat_tcp_resolv( nni_win_resolv_ip(host, serv, passive, family, IPPROTO_TCP, aio); } +void +nni_plat_udp_resolv( + const char *host, const char *serv, int family, int passive, nni_aio *aio) +{ + nni_win_resolv_ip(host, serv, passive, family, IPPROTO_UDP, aio); +} + int nni_win_resolv_sysinit(void) { @@ -273,9 +283,4 @@ nni_win_resolv_sysfini(void) nni_mtx_fini(&nni_win_resolv_mtx); } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_win_resolv_not_used = 0; - -#endif // PLATFORM_WINDOWS +#endif // NNG_PLATFORM_WINDOWS diff --git a/src/platform/windows/win_thread.c b/src/platform/windows/win_thread.c index 879cd772..12049139 100644 --- a/src/platform/windows/win_thread.c +++ b/src/platform/windows/win_thread.c @@ -12,7 +12,7 @@ #include "core/nng_impl.h" -#ifdef PLATFORM_WINDOWS +#ifdef NNG_PLATFORM_WINDOWS void * nni_alloc(size_t sz) @@ -188,9 +188,4 @@ nni_plat_fini(void) plat_inited = 0; } -#else - -// Suppress empty symbols warnings in ranlib. -int nni_win_thread_not_used = 0; - #endif diff --git a/tests/resolv.c b/tests/resolv.c index 502f47f1..94108765 100644 --- a/tests/resolv.c +++ b/tests/resolv.c @@ -7,8 +7,8 @@ // found online at https://opensource.org/licenses/MIT. // -#include "core/nng_impl.h" #include "convey.h" +#include "core/nng_impl.h" #include "stubs.h" #include <string.h> @@ -23,25 +23,24 @@ ip4tostr(void *addr) static char buf[256]; #ifdef _WIN32 - return (InetNtop(AF_INET, addr, buf, sizeof (buf))); + return (InetNtop(AF_INET, addr, buf, sizeof(buf))); #else - return (inet_ntop(AF_INET, addr, buf, sizeof (buf))); + return (inet_ntop(AF_INET, addr, buf, sizeof(buf))); #endif } - static const char * ip6tostr(void *addr) { static char buf[256]; #ifdef _WIN32 - return (InetNtop(AF_INET6, addr, buf, sizeof (buf))); + return (InetNtop(AF_INET6, addr, buf, sizeof(buf))); #else - return (inet_ntop(AF_INET6, addr, buf, sizeof (buf))); + return (inet_ntop(AF_INET6, addr, buf, sizeof(buf))); #endif } @@ -128,54 +127,69 @@ ip6tostr(void *addr) #endif TestMain("TCP Resolver", { - nni_init(); - - Convey("Google DNS IPv4 resolves", { - nni_aio aio; - const char *str; - memset(&aio, 0, sizeof (aio)); - nni_aio_init(&aio, NULL, NULL); - nni_plat_tcp_resolv("google-public-dns-a.google.com", "80", NNG_AF_INET, 1, &aio); - nni_aio_wait(&aio); - So(nni_aio_result(&aio) == 0); - So(aio.a_naddrs == 1); - So(aio.a_addrs[0].s_un.s_in.sa_family == NNG_AF_INET); - So(aio.a_addrs[0].s_un.s_in.sa_port == ntohs(80)); - str = ip4tostr(&aio.a_addrs[0].s_un.s_in.sa_addr); - So(strcmp(str, "8.8.8.8") == 0); - nni_aio_fini(&aio); - } - ); - Convey("Numeric resolves", { - nni_aio aio; - const char *str; - memset(&aio, 0, sizeof (aio)); - nni_aio_init(&aio, NULL, NULL); - nni_plat_tcp_resolv("8.8.4.4", "80", NNG_AF_INET, 1, &aio); - nni_aio_wait(&aio); - So(nni_aio_result(&aio) == 0); - So(aio.a_naddrs == 1); - So(aio.a_addrs[0].s_un.s_in.sa_family == NNG_AF_INET); - So(aio.a_addrs[0].s_un.s_in.sa_port == ntohs(80)); - str = ip4tostr(&aio.a_addrs[0].s_un.s_in.sa_addr); - So(strcmp(str, "8.8.4.4") == 0); - nni_aio_fini(&aio); - }); - Convey("Name service resolves", { - nni_aio aio; - const char *str; - memset(&aio, 0, sizeof (aio)); - nni_aio_init(&aio, NULL, NULL); - nni_plat_tcp_resolv("8.8.4.4", "http", NNG_AF_INET, 1, &aio); - nni_aio_wait(&aio); - So(nni_aio_result(&aio) == 0); - So(aio.a_naddrs == 1); - So(aio.a_addrs[0].s_un.s_in.sa_family == NNG_AF_INET); - So(aio.a_addrs[0].s_un.s_in.sa_port == ntohs(80)); - str = ip4tostr(&aio.a_addrs[0].s_un.s_in.sa_addr); - So(strcmp(str, "8.8.4.4") == 0); - nni_aio_fini(&aio); - }); - - nni_fini(); - }) + nni_init(); + + Convey("Google DNS IPv4 resolves", { + nni_aio aio; + const char *str; + memset(&aio, 0, sizeof(aio)); + nni_aio_init(&aio, NULL, NULL); + nni_plat_tcp_resolv("google-public-dns-a.google.com", "80", + NNG_AF_INET, 1, &aio); + nni_aio_wait(&aio); + So(nni_aio_result(&aio) == 0); + So(aio.a_naddrs == 1); + So(aio.a_addrs[0].s_un.s_in.sa_family == NNG_AF_INET); + So(aio.a_addrs[0].s_un.s_in.sa_port == ntohs(80)); + str = ip4tostr(&aio.a_addrs[0].s_un.s_in.sa_addr); + So(strcmp(str, "8.8.8.8") == 0); + nni_aio_fini(&aio); + }); + Convey("Numeric v4 resolves", { + nni_aio aio; + const char *str; + memset(&aio, 0, sizeof(aio)); + nni_aio_init(&aio, NULL, NULL); + nni_plat_tcp_resolv("8.8.4.4", "80", NNG_AF_INET, 1, &aio); + nni_aio_wait(&aio); + So(nni_aio_result(&aio) == 0); + So(aio.a_naddrs == 1); + So(aio.a_addrs[0].s_un.s_in.sa_family == NNG_AF_INET); + So(aio.a_addrs[0].s_un.s_in.sa_port == ntohs(80)); + str = ip4tostr(&aio.a_addrs[0].s_un.s_in.sa_addr); + So(strcmp(str, "8.8.4.4") == 0); + nni_aio_fini(&aio); + }); + Convey("Numeric v6 resolves", { + nni_aio aio; + const char *str; + memset(&aio, 0, sizeof(aio)); + nni_aio_init(&aio, NULL, NULL); + nni_plat_tcp_resolv("::1", "80", NNG_AF_INET6, 1, &aio); + nni_aio_wait(&aio); + So(nni_aio_result(&aio) == 0); + So(aio.a_naddrs == 1); + So(aio.a_addrs[0].s_un.s_in6.sa_family == NNG_AF_INET6); + So(aio.a_addrs[0].s_un.s_in6.sa_port == ntohs(80)); + str = ip6tostr(&aio.a_addrs[0].s_un.s_in6.sa_addr); + So(strcmp(str, "::1") == 0); + nni_aio_fini(&aio); + }); + Convey("Name service resolves", { + nni_aio aio; + const char *str; + memset(&aio, 0, sizeof(aio)); + nni_aio_init(&aio, NULL, NULL); + nni_plat_tcp_resolv("8.8.4.4", "http", NNG_AF_INET, 1, &aio); + nni_aio_wait(&aio); + So(nni_aio_result(&aio) == 0); + So(aio.a_naddrs == 1); + So(aio.a_addrs[0].s_un.s_in.sa_family == NNG_AF_INET); + So(aio.a_addrs[0].s_un.s_in.sa_port == ntohs(80)); + str = ip4tostr(&aio.a_addrs[0].s_un.s_in.sa_addr); + So(strcmp(str, "8.8.4.4") == 0); + nni_aio_fini(&aio); + }); + + nni_fini(); +}) diff --git a/tests/synch.c b/tests/synch.c index a49e27e1..d861f04d 100644 --- a/tests/synch.c +++ b/tests/synch.c @@ -20,7 +20,7 @@ struct notifyarg { nni_cv cv; }; -#ifdef PLATFORM_POSIX +#ifdef NNG_PLATFORM_POSIX #ifndef NDEBUG #define SYNC_FALLBACK 1 #endif |
