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