mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-13 18:55:10 +01:00
Merge pull request #1147 from rodgert/master
Update zmq_msg_get(ZMQ_SHARED) to return true for type_cmsg messages
This commit is contained in:
commit
0c4ee0a9b0
@ -30,8 +30,8 @@ aware that the respective socket might be closed already, reused even.
|
|||||||
Currently only implemented for TCP sockets.
|
Currently only implemented for TCP sockets.
|
||||||
|
|
||||||
*ZMQ_SHARED*::
|
*ZMQ_SHARED*::
|
||||||
Indicates that a message has been copied and MAY share underlying storage
|
Indicates that a message MAY share underlying storage with another copy of
|
||||||
with another copy of this message.
|
this message.
|
||||||
|
|
||||||
RETURN VALUE
|
RETURN VALUE
|
||||||
------------
|
------------
|
||||||
|
@ -630,7 +630,8 @@ int zmq_msg_get (zmq_msg_t *msg_, int property_)
|
|||||||
// warning: int64_t to int
|
// warning: int64_t to int
|
||||||
return ((zmq::msg_t*) msg_)->fd ();
|
return ((zmq::msg_t*) msg_)->fd ();
|
||||||
case ZMQ_SHARED:
|
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:
|
default:
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -65,7 +65,7 @@ int main (void)
|
|||||||
more = zmq_msg_more (&msg);
|
more = zmq_msg_more (&msg);
|
||||||
assert (more == 0);
|
assert (more == 0);
|
||||||
|
|
||||||
// Test ZMQ_SHARED property
|
// Test ZMQ_SHARED property (case 1, refcounted messages)
|
||||||
zmq_msg_t msg_a;
|
zmq_msg_t msg_a;
|
||||||
rc = zmq_msg_init_size(&msg_a, 1024); // large enough to be a type_lmsg
|
rc = zmq_msg_init_size(&msg_a, 1024); // large enough to be a type_lmsg
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
@ -85,6 +85,24 @@ int main (void)
|
|||||||
rc = zmq_msg_get(&msg_b, ZMQ_SHARED);
|
rc = zmq_msg_get(&msg_b, ZMQ_SHARED);
|
||||||
assert (rc == 1);
|
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.
|
// Deallocate the infrastructure.
|
||||||
rc = zmq_close (sc);
|
rc = zmq_close (sc);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user