Skip to content

Commit

Permalink
Problem: zmq_fd_t not used/available in zmq (#452)
Browse files Browse the repository at this point in the history
* Problem: zmq_fd_t not used/available in zmq

Solution: Make zmq::fd_t available and use in poller_event

* Deprecate typedef with comment
  • Loading branch information
gummif committed Feb 12, 2021
1 parent c591113 commit f428fee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
3 changes: 1 addition & 2 deletions tests/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ TEST_CASE("socket check integral options", "[socket]")
check_integral_opt_get<int>(zmq::sockopt::events, router, "events");
#endif
#ifdef ZMQ_FD
check_integral_opt_get<zmq::sockopt::cppzmq_fd_t>(zmq::sockopt::fd, router,
"fd");
check_integral_opt_get<zmq::fd_t>(zmq::sockopt::fd, router, "fd");
#endif
#ifdef ZMQ_HANDSHAKE_IVL
check_integral_opt<int>(zmq::sockopt::handshake_ivl, router, "handshake_ivl");
Expand Down
35 changes: 15 additions & 20 deletions zmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,17 @@ struct is_range<
typedef zmq_free_fn free_fn;
typedef zmq_pollitem_t pollitem_t;

// duplicate definition from libzmq 4.3.3
#if defined _WIN32
#if defined _WIN64
typedef unsigned __int64 fd_t;
#else
typedef unsigned int fd_t;
#endif
#else
typedef int fd_t;
#endif

class error_t : public std::exception
{
public:
Expand Down Expand Up @@ -1351,10 +1362,6 @@ constexpr const_buffer operator"" _zbuf(const char32_t *str, size_t len) noexcep
}
}

#endif // ZMQ_CPP11


#ifdef ZMQ_CPP11
namespace sockopt
{
// There are two types of options,
Expand Down Expand Up @@ -1390,16 +1397,8 @@ template<int Opt, int NullTerm = 1> struct array_option
using NAME##_t = array_option<OPT, 2>; \
ZMQ_INLINE_VAR ZMQ_CONSTEXPR_VAR NAME##_t NAME {}

// duplicate definition from libzmq 4.3.3
#if defined _WIN32
#if defined _WIN64
typedef unsigned __int64 cppzmq_fd_t;
#else
typedef unsigned int cppzmq_fd_t;
#endif
#else
typedef int cppzmq_fd_t;
#endif
// deprecated, use zmq::fd_t
using cppzmq_fd_t = ::zmq::fd_t;

#ifdef ZMQ_AFFINITY
ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_AFFINITY, affinity, uint64_t);
Expand Down Expand Up @@ -1435,7 +1434,7 @@ ZMQ_DEFINE_ARRAY_OPT_BIN_OR_Z85(ZMQ_CURVE_SERVERKEY, curve_serverkey);
ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_EVENTS, events, int);
#endif
#ifdef ZMQ_FD
ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_FD, fd, cppzmq_fd_t);
ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_FD, fd, ::zmq::fd_t);
#endif
#ifdef ZMQ_GSSAPI_PLAINTEXT
ZMQ_DEFINE_INTEGRAL_BOOL_UNIT_OPT(ZMQ_GSSAPI_PLAINTEXT, gssapi_plaintext, int);
Expand Down Expand Up @@ -2587,11 +2586,7 @@ struct no_user_data;
template<class T = no_user_data> struct poller_event
{
socket_ref socket;
#ifdef _WIN32
SOCKET fd;
#else
int fd;
#endif
::zmq::fd_t fd;
T *user_data;
event_flags events;
};
Expand Down

0 comments on commit f428fee

Please sign in to comment.