From bf6bde3ae3db4278feb0c20771db124107602445 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Mon, 14 May 2018 14:29:49 +0200 Subject: [PATCH] Problem: unnecessary ifdefs regarding handling of int vs. SOCKET at various places Solution: use a typedef instead --- src/fd.hpp | 3 +++ src/zmq.cpp | 27 ++++----------------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/fd.hpp b/src/fd.hpp index 892e2a9d..13178565 100644 --- a/src/fd.hpp +++ b/src/fd.hpp @@ -38,6 +38,9 @@ namespace zmq { #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 { diff --git a/src/zmq.cpp b/src/zmq.cpp index 4fd9b891..573d4770 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -1219,13 +1219,8 @@ static int check_poller_registration_args (void *const poller_, void *const s_) return 0; } -#if defined _WIN32 static int check_poller_fd_registration_args (void *const poller_, - const SOCKET fd_) -#else -static int check_poller_fd_registration_args (void *const poller_, - const int fd_) -#endif + const zmq::fd_t fd_) { if (-1 == check_poller (poller_)) return -1; @@ -1250,14 +1245,10 @@ int zmq_poller_add (void *poller_, void *s_, void *user_data_, short events_) ->add (socket, user_data_, events_); } -#if defined _WIN32 int zmq_poller_add_fd (void *poller_, - SOCKET fd_, + zmq::fd_t fd_, void *user_data_, short events_) -#else -int zmq_poller_add_fd (void *poller_, int fd_, void *user_data_, short events_) -#endif { if (-1 == check_poller_fd_registration_args (poller_, fd_) || -1 == check_events (events_)) @@ -1279,12 +1270,7 @@ int zmq_poller_modify (void *poller_, void *s_, short events_) return ((zmq::socket_poller_t *) poller_)->modify (socket, events_); } - -#if defined _WIN32 -int zmq_poller_modify_fd (void *poller_, SOCKET fd_, short events_) -#else -int zmq_poller_modify_fd (void *poller_, int fd_, short events_) -#endif +int zmq_poller_modify_fd (void *poller_, zmq::fd_t fd_, short events_) { if (-1 == check_poller_fd_registration_args (poller_, fd_) || -1 == check_events (events_)) @@ -1293,7 +1279,6 @@ int zmq_poller_modify_fd (void *poller_, int fd_, short events_) return ((zmq::socket_poller_t *) poller_)->modify_fd (fd_, events_); } - int zmq_poller_remove (void *poller_, void *s_) { if (-1 == check_poller_registration_args (poller_, s_)) @@ -1304,11 +1289,7 @@ int zmq_poller_remove (void *poller_, void *s_) return ((zmq::socket_poller_t *) poller_)->remove (socket); } -#if defined _WIN32 -int zmq_poller_remove_fd (void *poller_, SOCKET fd_) -#else -int zmq_poller_remove_fd (void *poller_, int fd_) -#endif +int zmq_poller_remove_fd (void *poller_, zmq::fd_t fd_) { if (-1 == check_poller_fd_registration_args (poller_, fd_)) return -1;