Problem: size of zmq_msg_t is not known to FFI wrappers

Solution: add a ZMQ_MSG_T_SIZE context read-only option so that
wrappers can call zmq_ctx_get (ctx, ZMQ_MSG_T_SIZE) to get the
size at runtime.
This commit is contained in:
Luca Boccassi 2016-11-20 12:24:03 +00:00
parent 3db69212b7
commit 670bec56d8
3 changed files with 7 additions and 0 deletions

View File

@ -206,6 +206,9 @@ ZMQ_EXPORT void zmq_version (int *major, int *minor, int *patch);
#define ZMQ_THREAD_PRIORITY 3
#define ZMQ_THREAD_SCHED_POLICY 4
#define ZMQ_MAX_MSGSZ 5
// All options after this is for version 4.3 and still *draft*
// Subject to arbitrary change without notice
#define ZMQ_MSG_T_SIZE 6
/* Default for new contexts */
#define ZMQ_IO_THREADS_DFLT 1

View File

@ -301,6 +301,9 @@ int zmq::ctx_t::get (int option_)
else
if (option_ == ZMQ_MAX_MSGSZ)
rc = max_msgsz;
else
if (option_ == ZMQ_MSG_T_SIZE)
rc = sizeof (zmq_msg_t);
else {
errno = EINVAL;
rc = -1;

View File

@ -48,6 +48,7 @@ int main (void)
#endif
assert (zmq_ctx_get (ctx, ZMQ_IO_THREADS) == ZMQ_IO_THREADS_DFLT);
assert (zmq_ctx_get (ctx, ZMQ_IPV6) == 0);
assert (zmq_ctx_get (ctx, ZMQ_MSG_T_SIZE) == sizeof (zmq_msg_t));
rc = zmq_ctx_set (ctx, ZMQ_IPV6, true);
assert (zmq_ctx_get (ctx, ZMQ_IPV6) == 1);