Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
15ad6f80
Commit
15ad6f80
authored
Jan 28, 2016
by
somdoron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save some bytes in msg class
parent
dc945998
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
31 deletions
+52
-31
msg.cpp
src/msg.cpp
+11
-9
msg.hpp
src/msg.hpp
+41
-22
No files found.
src/msg.cpp
View file @
15ad6f80
...
...
@@ -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
...
...
src/msg.hpp
View file @
15ad6f80
...
...
@@ -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
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment