Update zmq_msg_get(ZMQ_SHARED) to return true for type_cmsg messages

This commit is contained in:
Thomas Rodgers 2014-07-29 13:43:38 -05:00
parent 416ee8e75c
commit 03f097a541
3 changed files with 42 additions and 23 deletions

View File

@ -30,8 +30,8 @@ aware that the respective socket might be closed already, reused even.
Currently only implemented for TCP sockets.
*ZMQ_SHARED*::
Indicates that a message has been copied and MAY share underlying storage
with another copy of this message.
Indicates that a message MAY share underlying storage with another copy of
this message.
RETURN VALUE
------------

View File

@ -630,7 +630,8 @@ int zmq_msg_get (zmq_msg_t *msg_, int property_)
// warning: int64_t to int
return ((zmq::msg_t*) msg_)->fd ();
case ZMQ_SHARED:
return (((zmq::msg_t*) msg_)->flags () & zmq::msg_t::shared)? 1: 0;
return (((zmq::msg_t*) msg_)->is_cmsg ()) ||
(((zmq::msg_t*) msg_)->flags () & zmq::msg_t::shared)? 1: 0;
default:
errno = EINVAL;
return -1;

View File

@ -65,7 +65,7 @@ int main (void)
more = zmq_msg_more (&msg);
assert (more == 0);
// Test ZMQ_SHARED property
// Test ZMQ_SHARED property (case 1, refcounted messages)
zmq_msg_t msg_a;
rc = zmq_msg_init_size(&msg_a, 1024); // large enough to be a type_lmsg
assert (rc == 0);
@ -85,6 +85,24 @@ int main (void)
rc = zmq_msg_get(&msg_b, ZMQ_SHARED);
assert (rc == 1);
// cleanup
rc = zmq_msg_close(&msg_a);
assert (rc == 0);
rc = zmq_msg_close(&msg_b);
assert (rc == 0);
// Test ZMQ_SHARED property (case 2, constant data messages)
rc = zmq_msg_init_data(&msg_a, (void*) "TEST", 5, 0, 0);
assert (rc == 0);
// Message reports as shared
rc = zmq_msg_get(&msg_a, ZMQ_SHARED);
assert (rc == 1);
// cleanup
rc = zmq_msg_close(&msg_a);
assert (rc == 0);
// Deallocate the infrastructure.
rc = zmq_close (sc);
assert (rc == 0);