Skip to content

Commit

Permalink
Added const accessors to data and size members of message_t
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralph Langendam committed Sep 3, 2012
1 parent 9b07de2 commit e3b219f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/zmq.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ ZMQ_EXPORT int zmq_msg_close (zmq_msg_t *msg);
ZMQ_EXPORT int zmq_msg_move (zmq_msg_t *dest, zmq_msg_t *src);
ZMQ_EXPORT int zmq_msg_copy (zmq_msg_t *dest, zmq_msg_t *src);
ZMQ_EXPORT void *zmq_msg_data (zmq_msg_t *msg);
ZMQ_EXPORT const void *zmq_msg_cdata (const zmq_msg_t *msg);
ZMQ_EXPORT size_t zmq_msg_size (zmq_msg_t *msg);
ZMQ_EXPORT size_t zmq_msg_csize (const zmq_msg_t *msg_);

/******************************************************************************/
/* 0MQ infrastructure (a.k.a. context) initialisation & termination. */
Expand Down
10 changes: 10 additions & 0 deletions include/zmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,21 @@ namespace zmq
return zmq_msg_data (this);
}

inline const void *cdata () const
{
return zmq_msg_cdata (this);
}

inline size_t size ()
{
return zmq_msg_size (this);
}

inline size_t csize () const
{
return zmq_msg_csize (this);
}

private:

// Disable implicit message copying, so that users won't use shared
Expand Down
24 changes: 24 additions & 0 deletions src/zmq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@ void *zmq_msg_data (zmq_msg_t *msg_)
return ((zmq::msg_content_t*) msg_->content)->data;
}

const void *zmq_msg_cdata (const zmq_msg_t *msg_)
{
zmq_assert ((msg_->flags | ZMQ_MSG_MASK) == 0xff);

if (msg_->content == (zmq::msg_content_t*) ZMQ_VSM)
return msg_->vsm_data;
if (msg_->content == (zmq::msg_content_t*) ZMQ_DELIMITER)
return NULL;

return ((zmq::msg_content_t*) msg_->content)->data;
}

size_t zmq_msg_size (zmq_msg_t *msg_)
{
zmq_assert ((msg_->flags | ZMQ_MSG_MASK) == 0xff);
Expand All @@ -230,6 +242,18 @@ size_t zmq_msg_size (zmq_msg_t *msg_)
return ((zmq::msg_content_t*) msg_->content)->size;
}

size_t zmq_msg_csize (const zmq_msg_t *msg_)
{
zmq_assert ((msg_->flags | ZMQ_MSG_MASK) == 0xff);

if (msg_->content == (zmq::msg_content_t*) ZMQ_VSM)
return msg_->vsm_size;
if (msg_->content == (zmq::msg_content_t*) ZMQ_DELIMITER)
return 0;

return ((zmq::msg_content_t*) msg_->content)->size;
}

void *zmq_init (int io_threads_)
{
if (io_threads_ < 0) {
Expand Down

0 comments on commit e3b219f

Please sign in to comment.