Commit 15ad6f80 authored by somdoron's avatar somdoron

save some bytes in msg class

parent dc945998
......@@ -85,25 +85,26 @@ int zmq::msg_t::init ()
u.vsm.flags = 0;
u.vsm.size = 0;
u.vsm.routing_id = 0;
file_desc = -1;
u.vsm.fd = retired_fd;
return 0;
}
int zmq::msg_t::init_size (size_t size_)
{
file_desc = -1;
if (size_ <= max_vsm_size) {
u.vsm.metadata = NULL;
u.vsm.type = type_vsm;
u.vsm.flags = 0;
u.vsm.size = (unsigned char) size_;
u.vsm.routing_id = 0;
u.vsm.fd = retired_fd;
}
else {
u.lmsg.metadata = NULL;
u.lmsg.type = type_lmsg;
u.lmsg.flags = 0;
u.lmsg.routing_id = 0;
u.lmsg.fd = retired_fd;
u.lmsg.content = NULL;
if (sizeof (content_t) + size_ > size_)
u.lmsg.content = (content_t*) malloc (sizeof (content_t) + size_);
......@@ -127,12 +128,12 @@ int zmq::msg_t::init_external_storage(void *data_, size_t size_, zmq::atomic_cou
zmq_assert(NULL != data_);
zmq_assert(NULL != ctr);
file_desc = -1;
u.zclmsg.metadata = NULL;
u.zclmsg.type = type_zclmsg;
u.zclmsg.flags = 0;
u.zclmsg.routing_id = 0;
u.zclmsg.fd = retired_fd;
u.zclmsg.data = data_;
u.zclmsg.size = size_;
......@@ -151,8 +152,6 @@ int zmq::msg_t::init_data (void *data_, size_t size_,
// would occur once the data is accessed
zmq_assert (data_ != NULL || size_ == 0);
file_desc = -1;
// Initialize constant message if there's no need to deallocate
if (ffn_ == NULL) {
u.cmsg.metadata = NULL;
......@@ -161,12 +160,14 @@ int zmq::msg_t::init_data (void *data_, size_t size_,
u.cmsg.data = data_;
u.cmsg.size = size_;
u.cmsg.routing_id = 0;
u.cmsg.fd = retired_fd;
}
else {
u.lmsg.metadata = NULL;
u.lmsg.type = type_lmsg;
u.lmsg.flags = 0;
u.lmsg.routing_id = 0;
u.lmsg.fd = retired_fd;
u.lmsg.content = (content_t*) malloc (sizeof (content_t));
if (!u.lmsg.content) {
errno = ENOMEM;
......@@ -189,6 +190,7 @@ int zmq::msg_t::init_delimiter ()
u.delimiter.type = type_delimiter;
u.delimiter.flags = 0;
u.delimiter.routing_id = 0;
u.delimiter.fd = retired_fd;
return 0;
}
......@@ -369,14 +371,14 @@ void zmq::msg_t::reset_flags (unsigned char flags_)
u.base.flags &= ~flags_;
}
int64_t zmq::msg_t::fd ()
zmq::fd_t zmq::msg_t::fd ()
{
return file_desc;
return u.base.fd;
}
void zmq::msg_t::set_fd (int64_t fd_)
void zmq::msg_t::set_fd (fd_t fd_)
{
file_desc = fd_;
u.base.fd = fd_;
}
zmq::metadata_t *zmq::msg_t::metadata () const
......
......@@ -34,6 +34,7 @@
#include <stdio.h>
#include "config.hpp"
#include "fd.hpp"
#include "atomic_counter.hpp"
#include "metadata.hpp"
......@@ -86,8 +87,8 @@ namespace zmq
unsigned char flags ();
void set_flags (unsigned char flags_);
void reset_flags (unsigned char flags_);
int64_t fd ();
void set_fd (int64_t fd_);
fd_t fd ();
void set_fd (fd_t fd_);
metadata_t *metadata () const;
void set_metadata (metadata_t *metadata_);
void reset_metadata ();
......@@ -112,7 +113,10 @@ namespace zmq
// Size in bytes of the largest message that is still copied around
// rather than being reference-counted.
enum { msg_t_size = 64 };
enum { max_vsm_size = msg_t_size - (8 + sizeof (metadata_t *) + 3 + sizeof(uint32_t)) };
enum { max_vsm_size = msg_t_size - (sizeof (metadata_t *) +
3 +
sizeof (uint32_t) +
sizeof (fd_t)) };
private:
zmq::atomic_counter_t* refcnt();
......@@ -152,9 +156,6 @@ namespace zmq
type_max = 105
};
// the file descriptor where this message originated, needs to be 64bit due to alignment
int64_t file_desc;
// Note that fields shared between different message types are not
// moved to the parent class (msg_t). This way we get tighter packing
// of the data. Shared fields can be accessed via 'base' member of
......@@ -162,10 +163,14 @@ namespace zmq
union {
struct {
metadata_t *metadata;
unsigned char unused [msg_t_size - (8 + sizeof (metadata_t *) + 2 + sizeof(uint32_t))];
unsigned char unused [msg_t_size - (sizeof (metadata_t *) +
2 +
sizeof (uint32_t) +
sizeof (fd_t))];
unsigned char type;
unsigned char flags;
uint32_t routing_id;
fd_t fd;
} base;
struct {
metadata_t *metadata;
......@@ -174,17 +179,20 @@ namespace zmq
unsigned char type;
unsigned char flags;
uint32_t routing_id;
fd_t fd;
} vsm;
struct {
metadata_t *metadata;
content_t *content;
unsigned char unused [msg_t_size - (8 + sizeof (metadata_t *)
+ sizeof (content_t*)
+ 2
+ sizeof(uint32_t))];
unsigned char unused [msg_t_size - (sizeof (metadata_t *) +
sizeof (content_t*) +
2 +
sizeof (uint32_t) +
sizeof (fd_t))];
unsigned char type;
unsigned char flags;
uint32_t routing_id;
fd_t fd;
} lmsg;
struct {
metadata_t *metadata;
......@@ -193,34 +201,45 @@ namespace zmq
msg_free_fn *ffn;
void *hint;
zmq::atomic_counter_t* refcnt;
unsigned char unused [msg_t_size - (8 + sizeof (metadata_t *)
+ sizeof (void*)
+ sizeof (size_t)
+ sizeof (msg_free_fn*)
+ sizeof (void*)
+ sizeof (zmq::atomic_counter_t*)
+ 2
+ sizeof(uint32_t))];
unsigned char unused [msg_t_size - (sizeof (metadata_t *) +
sizeof (void*) +
sizeof (size_t) +
sizeof (msg_free_fn*) +
sizeof (void*) +
sizeof (zmq::atomic_counter_t*) +
2 +
sizeof (uint32_t) +
sizeof (fd_t))];
unsigned char type;
unsigned char flags;
uint32_t routing_id;
fd_t fd;
} zclmsg;
struct {
metadata_t *metadata;
void* data;
size_t size;
unsigned char unused
[msg_t_size - (8 + sizeof (metadata_t *) + sizeof (void*) + sizeof (size_t) + 2 + sizeof(uint32_t))];
unsigned char unused [msg_t_size - (sizeof (metadata_t *) +
sizeof (void*) +
sizeof (size_t) +
2 +
sizeof (uint32_t) +
sizeof (fd_t))];
unsigned char type;
unsigned char flags;
uint32_t routing_id;
fd_t fd;
} cmsg;
struct {
metadata_t *metadata;
unsigned char unused [msg_t_size - (8 + sizeof (metadata_t *) + 2 + sizeof(uint32_t))];
unsigned char unused [msg_t_size - (sizeof (metadata_t *) +
2 +
sizeof (uint32_t) +
sizeof (fd_t))];
unsigned char type;
unsigned char flags;
uint32_t routing_id;
fd_t fd;
} delimiter;
} u;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment