From d426f2ab0cf48d3438076f0aa844e29b568ebd6f Mon Sep 17 00:00:00 2001 From: Gudmundur Adalsteinsson Date: Mon, 27 Apr 2020 20:32:27 +0000 Subject: [PATCH] Problem: Multiple fd_t definitions Solution: Unify definition --- src/fd.hpp | 8 ++------ tests/test_poller.cpp | 6 +++--- tests/test_system.cpp | 2 +- tests/testutil.hpp | 34 ++++++++++++++++++++-------------- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/fd.hpp b/src/fd.hpp index effcc120..21925ae6 100644 --- a/src/fd.hpp +++ b/src/fd.hpp @@ -36,18 +36,15 @@ namespace zmq { +typedef zmq_fd_t fd_t; + #ifdef ZMQ_HAVE_WINDOWS #if defined _MSC_VER && _MSC_VER <= 1400 -///< \todo zmq.h uses SOCKET unconditionally, so probably VS versions before -/// VS2008 are unsupported anyway. Apart from that, this seems to depend on -/// the Windows SDK version rather than the VS version. -typedef UINT_PTR fd_t; enum { retired_fd = (fd_t) (~0) }; #else -typedef SOCKET fd_t; enum #if _MSC_VER >= 1800 : fd_t @@ -57,7 +54,6 @@ enum }; #endif #else -typedef int fd_t; enum { retired_fd = -1 diff --git a/tests/test_poller.cpp b/tests/test_poller.cpp index 00cb90e5..e486c380 100644 --- a/tests/test_poller.cpp +++ b/tests/test_poller.cpp @@ -209,7 +209,7 @@ void test_null_poller_pointers_wait_all_indirect () void test_null_poller_pointer_poller_fd () { void *null_poller = NULL; - zmq_fd_t fd; + fd_t fd; TEST_ASSERT_FAILURE_ERRNO (EFAULT, zmq_poller_fd (&null_poller, &fd)); } @@ -285,7 +285,7 @@ void test_call_poller_fd_no_signaler () TEST_ASSERT_SUCCESS_ERRNO ( zmq_poller_add (poller, socket, NULL, ZMQ_POLLIN)); - zmq_fd_t fd; + fd_t fd; TEST_ASSERT_FAILURE_ERRNO (EINVAL, zmq_poller_fd (poller, &fd)); TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_destroy (&poller)); @@ -303,7 +303,7 @@ void test_call_poller_fd () TEST_ASSERT_SUCCESS_ERRNO ( zmq_poller_add (poller, socket, NULL, ZMQ_POLLIN)); - zmq_fd_t fd; + fd_t fd; TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_fd (poller, &fd)); TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_destroy (&poller)); diff --git a/tests/test_system.cpp b/tests/test_system.cpp index 41d37358..8c595502 100644 --- a/tests/test_system.cpp +++ b/tests/test_system.cpp @@ -85,7 +85,7 @@ void test_max_sockets () int count; for (count = 0; count < MAX_SOCKETS; count++) { handle[count] = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (handle[count] == -1) { + if (handle[count] == retired_fd) { printf ("W: Only able to create %d sockets on this box\n", count); const char msg[] = "I: Tune your system to increase maximum allowed file handles\n" diff --git a/tests/testutil.hpp b/tests/testutil.hpp index 6661f33b..f05bec6f 100644 --- a/tests/testutil.hpp +++ b/tests/testutil.hpp @@ -74,26 +74,32 @@ inline const char *as_setsockopt_opt_t (const void *opt) { return static_cast (opt); } -#if defined _MSC_VER && _MSC_VER <= 1400 -typedef UINT_PTR fd_t; -enum -{ - retired_fd = (fd_t) (~0) -}; -#else -typedef SOCKET fd_t; -enum -{ - retired_fd = (fd_t) INVALID_SOCKET -}; -#endif #else typedef size_t socket_size_t; inline const void *as_setsockopt_opt_t (const void *opt_) { return opt_; } -typedef int fd_t; +#endif + +// duplicated from fd.hpp +typedef zmq_fd_t fd_t; +#ifdef ZMQ_HAVE_WINDOWS +#if defined _MSC_VER && _MSC_VER <= 1400 +enum +{ + retired_fd = (zmq_fd_t) (~0) +}; +#else +enum +#if _MSC_VER >= 1800 + : zmq_fd_t +#endif +{ + retired_fd = INVALID_SOCKET +}; +#endif +#else enum { retired_fd = -1