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
bcfe863f
Commit
bcfe863f
authored
Aug 19, 2013
by
Ian Barber
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #630 from ulikoehler/cmsg
Optimized zmq::msg_t for constant messages
parents
b3ca7fd4
121a838a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
14 deletions
+43
-14
msg.cpp
src/msg.cpp
+31
-13
msg.hpp
src/msg.hpp
+12
-1
No files found.
src/msg.cpp
View file @
bcfe863f
...
...
@@ -75,19 +75,28 @@ int zmq::msg_t::init_size (size_t size_)
int
zmq
::
msg_t
::
init_data
(
void
*
data_
,
size_t
size_
,
msg_free_fn
*
ffn_
,
void
*
hint_
)
{
u
.
lmsg
.
type
=
type_lmsg
;
u
.
lmsg
.
flags
=
0
;
u
.
lmsg
.
content
=
(
content_t
*
)
malloc
(
sizeof
(
content_t
))
;
if
(
!
u
.
lmsg
.
content
)
{
errno
=
ENOMEM
;
return
-
1
;
// Initialize constant message if there's no need to deallocate
if
(
ffn_
==
NULL
)
{
u
.
cmsg
.
type
=
type_cmsg
;
u
.
cmsg
.
flags
=
0
;
u
.
cmsg
.
data
=
data_
;
u
.
cmsg
.
size
=
size_
;
}
else
{
u
.
lmsg
.
type
=
type_lmsg
;
u
.
lmsg
.
flags
=
0
;
u
.
lmsg
.
content
=
(
content_t
*
)
malloc
(
sizeof
(
content_t
));
if
(
!
u
.
lmsg
.
content
)
{
errno
=
ENOMEM
;
return
-
1
;
}
u
.
lmsg
.
content
->
data
=
data_
;
u
.
lmsg
.
content
->
size
=
size_
;
u
.
lmsg
.
content
->
ffn
=
ffn_
;
u
.
lmsg
.
content
->
hint
=
hint_
;
new
(
&
u
.
lmsg
.
content
->
refcnt
)
zmq
::
atomic_counter_t
();
u
.
lmsg
.
content
->
data
=
data_
;
u
.
lmsg
.
content
->
size
=
size_
;
u
.
lmsg
.
content
->
ffn
=
ffn_
;
u
.
lmsg
.
content
->
hint
=
hint_
;
new
(
&
u
.
lmsg
.
content
->
refcnt
)
zmq
::
atomic_counter_t
();
}
return
0
;
}
...
...
@@ -193,6 +202,8 @@ void *zmq::msg_t::data ()
return
u
.
vsm
.
data
;
case
type_lmsg
:
return
u
.
lmsg
.
content
->
data
;
case
type_cmsg
:
return
u
.
cmsg
.
data
;
default
:
zmq_assert
(
false
);
return
NULL
;
...
...
@@ -209,6 +220,8 @@ size_t zmq::msg_t::size ()
return
u
.
vsm
.
size
;
case
type_lmsg
:
return
u
.
lmsg
.
content
->
size
;
case
type_cmsg
:
return
u
.
cmsg
.
size
;
default
:
zmq_assert
(
false
);
return
0
;
...
...
@@ -245,6 +258,11 @@ bool zmq::msg_t::is_vsm ()
return
u
.
base
.
type
==
type_vsm
;
}
bool
zmq
::
msg_t
::
is_cmsg
()
{
return
u
.
base
.
type
==
type_cmsg
;
}
void
zmq
::
msg_t
::
add_refs
(
int
refs_
)
{
zmq_assert
(
refs_
>=
0
);
...
...
@@ -253,8 +271,8 @@ void zmq::msg_t::add_refs (int refs_)
if
(
!
refs_
)
return
;
// VSMs
and delimiters can be copied straight away. The only message type
// that needs special care are long messages.
// VSMs
, CMSGS and delimiters can be copied straight away. The only
//
message type
that needs special care are long messages.
if
(
u
.
base
.
type
==
type_lmsg
)
{
if
(
u
.
lmsg
.
flags
&
msg_t
::
shared
)
u
.
lmsg
.
content
->
refcnt
.
add
(
refs_
);
...
...
src/msg.hpp
View file @
bcfe863f
...
...
@@ -69,6 +69,7 @@ namespace zmq
bool
is_identity
()
const
;
bool
is_delimiter
();
bool
is_vsm
();
bool
is_cmsg
();
// After calling this function you can copy the message in POD-style
// refs_ times. No need to call copy.
...
...
@@ -107,7 +108,9 @@ namespace zmq
type_vsm
=
101
,
type_lmsg
=
102
,
type_delimiter
=
103
,
type_max
=
103
// CMSG messages point to constant data
type_cmsg
=
104
,
type_max
=
104
};
// Note that fields shared between different message types are not
...
...
@@ -132,6 +135,14 @@ namespace zmq
unsigned
char
type
;
unsigned
char
flags
;
}
lmsg
;
struct
{
void
*
data
;
size_t
size
;
unsigned
char
unused
[
max_vsm_size
+
1
-
sizeof
(
void
*
)
-
sizeof
(
size_t
)];
unsigned
char
type
;
unsigned
char
flags
;
}
cmsg
;
struct
{
unsigned
char
unused
[
max_vsm_size
+
1
];
unsigned
char
type
;
...
...
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