mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-12 18:40:27 +01:00
Add pointer to properties into message structure
This commit is contained in:
parent
26bf74972a
commit
724b2bb844
@ -200,7 +200,7 @@ ZMQ_EXPORT int zmq_ctx_destroy (void *context);
|
||||
/* 0MQ message definition. */
|
||||
/******************************************************************************/
|
||||
|
||||
typedef struct zmq_msg_t {unsigned char _ [40];} zmq_msg_t;
|
||||
typedef struct zmq_msg_t {unsigned char _ [48];} zmq_msg_t;
|
||||
|
||||
typedef void (zmq_free_fn) (void *data, void *hint);
|
||||
|
||||
|
@ -41,6 +41,7 @@ bool zmq::msg_t::check ()
|
||||
|
||||
int zmq::msg_t::init ()
|
||||
{
|
||||
u.vsm.properties = NULL;
|
||||
u.vsm.type = type_vsm;
|
||||
u.vsm.flags = 0;
|
||||
u.vsm.size = 0;
|
||||
@ -52,11 +53,13 @@ int zmq::msg_t::init_size (size_t size_)
|
||||
{
|
||||
file_desc = -1;
|
||||
if (size_ <= max_vsm_size) {
|
||||
u.vsm.properties = NULL;
|
||||
u.vsm.type = type_vsm;
|
||||
u.vsm.flags = 0;
|
||||
u.vsm.size = (unsigned char) size_;
|
||||
}
|
||||
else {
|
||||
u.lmsg.properties = NULL;
|
||||
u.lmsg.type = type_lmsg;
|
||||
u.lmsg.flags = 0;
|
||||
u.lmsg.content =
|
||||
@ -85,13 +88,15 @@ int zmq::msg_t::init_data (void *data_, size_t size_, msg_free_fn *ffn_,
|
||||
file_desc = -1;
|
||||
|
||||
// Initialize constant message if there's no need to deallocate
|
||||
if(ffn_ == NULL) {
|
||||
if (ffn_ == NULL) {
|
||||
u.cmsg.properties = NULL;
|
||||
u.cmsg.type = type_cmsg;
|
||||
u.cmsg.flags = 0;
|
||||
u.cmsg.data = data_;
|
||||
u.cmsg.size = size_;
|
||||
}
|
||||
else {
|
||||
u.lmsg.properties = NULL;
|
||||
u.lmsg.type = type_lmsg;
|
||||
u.lmsg.flags = 0;
|
||||
u.lmsg.content = (content_t*) malloc (sizeof (content_t));
|
||||
@ -112,6 +117,7 @@ int zmq::msg_t::init_data (void *data_, size_t size_, msg_free_fn *ffn_,
|
||||
|
||||
int zmq::msg_t::init_delimiter ()
|
||||
{
|
||||
u.delimiter.properties = NULL;
|
||||
u.delimiter.type = type_delimiter;
|
||||
u.delimiter.flags = 0;
|
||||
return 0;
|
||||
@ -336,4 +342,3 @@ bool zmq::msg_t::rm_refs (int refs_)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
20
src/msg.hpp
20
src/msg.hpp
@ -86,9 +86,12 @@ namespace zmq
|
||||
|
||||
private:
|
||||
|
||||
class i_properties;
|
||||
|
||||
// Size in bytes of the largest message that is still copied around
|
||||
// rather than being reference-counted.
|
||||
enum {max_vsm_size = 29};
|
||||
enum { msg_t_size = 48 };
|
||||
enum { max_vsm_size = msg_t_size - (8 + sizeof (i_properties *) + 3) };
|
||||
|
||||
// Shared message buffer. Message data are either allocated in one
|
||||
// continuous block along with this structure - thus avoiding one
|
||||
@ -125,37 +128,42 @@ namespace zmq
|
||||
int64_t file_desc;
|
||||
|
||||
// Note that fields shared between different message types are not
|
||||
// moved to tha parent class (msg_t). This way we ger tighter packing
|
||||
// moved to tha parent class (msg_t). This way we get tighter packing
|
||||
// of the data. Shared fields can be accessed via 'base' member of
|
||||
// the union.
|
||||
union {
|
||||
struct {
|
||||
unsigned char unused [max_vsm_size + 1];
|
||||
i_properties *properties;
|
||||
unsigned char unused [msg_t_size - (8 + sizeof (i_properties *) + 2)];
|
||||
unsigned char type;
|
||||
unsigned char flags;
|
||||
} base;
|
||||
struct {
|
||||
i_properties *properties;
|
||||
unsigned char data [max_vsm_size];
|
||||
unsigned char size;
|
||||
unsigned char type;
|
||||
unsigned char flags;
|
||||
} vsm;
|
||||
struct {
|
||||
i_properties *properties;
|
||||
content_t *content;
|
||||
unsigned char unused [max_vsm_size + 1 - sizeof (content_t*)];
|
||||
unsigned char unused [msg_t_size - (8 + sizeof (i_properties *) + sizeof (content_t*) + 2)];
|
||||
unsigned char type;
|
||||
unsigned char flags;
|
||||
} lmsg;
|
||||
struct {
|
||||
i_properties *properties;
|
||||
void* data;
|
||||
size_t size;
|
||||
unsigned char unused
|
||||
[max_vsm_size + 1 - sizeof (void*) - sizeof (size_t)];
|
||||
[msg_t_size - (8 + sizeof (i_properties *) + sizeof (void*) + sizeof (size_t) + 2)];
|
||||
unsigned char type;
|
||||
unsigned char flags;
|
||||
} cmsg;
|
||||
struct {
|
||||
unsigned char unused [max_vsm_size + 1];
|
||||
i_properties *properties;
|
||||
unsigned char unused [msg_t_size - (8 + sizeof (i_properties *) + 2)];
|
||||
unsigned char type;
|
||||
unsigned char flags;
|
||||
} delimiter;
|
||||
|
Loading…
Reference in New Issue
Block a user