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
5d5def40
Commit
5d5def40
authored
Feb 21, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: casts required due to void* arguments in a C++ class
Solution: introduce a type template argument
parent
15b4f596
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
43 deletions
+44
-43
generic_mtrie.hpp
src/generic_mtrie.hpp
+11
-9
generic_mtrie_impl.hpp
src/generic_mtrie_impl.hpp
+10
-7
xpub.cpp
src/xpub.cpp
+12
-14
xpub.hpp
src/xpub.hpp
+2
-2
unittest_mtrie.cpp
unittests/unittest_mtrie.cpp
+9
-11
No files found.
src/generic_mtrie.hpp
View file @
5d5def40
...
...
@@ -58,11 +58,11 @@ template <typename T> class generic_mtrie_t
// The call_on_uniq_ flag controls if the callback is invoked
// when there are no subscriptions left on a topic only (true)
// or on every removal (false).
void
rm
(
value_t
*
pipe_
,
void
(
*
func_
)
(
const
unsigned
char
*
data_
,
size_t
size_
,
void
*
arg_
),
void
*
arg_
,
bool
call_on_uniq_
);
template
<
typename
Arg
>
void
rm
(
value_t
*
pipe_
,
void
(
*
func_
)
(
const
unsigned
char
*
data_
,
size_t
size_
,
Arg
arg_
),
Arg
arg_
,
bool
call_on_uniq_
);
// Remove specific subscription from the trie. Return true if it was
// actually removed rather than de-duplicated.
...
...
@@ -71,19 +71,21 @@ template <typename T> class generic_mtrie_t
bool
rm
(
prefix_t
prefix_
,
size_t
size_
,
value_t
*
pipe_
);
// Signal all the matching pipes.
template
<
typename
Arg
>
void
match
(
prefix_t
data_
,
size_t
size_
,
void
(
*
func_
)
(
value_t
*
pipe_
,
void
*
arg_
),
void
*
arg_
);
void
(
*
func_
)
(
value_t
*
pipe_
,
Arg
arg_
),
Arg
arg_
);
private
:
bool
add_helper
(
prefix_t
prefix_
,
size_t
size_
,
value_t
*
pipe_
);
template
<
typename
Arg
>
void
rm_helper
(
value_t
*
pipe_
,
unsigned
char
**
buff_
,
size_t
buffsize_
,
size_t
maxbuffsize_
,
void
(
*
func_
)
(
prefix_t
data_
,
size_t
size_
,
void
*
arg_
),
void
*
arg_
,
void
(
*
func_
)
(
prefix_t
data_
,
size_t
size_
,
Arg
arg_
),
Arg
arg_
,
bool
call_on_uniq_
);
bool
rm_helper
(
prefix_t
prefix_
,
size_t
size_
,
value_t
*
pipe_
);
bool
is_redundant
()
const
;
...
...
src/generic_mtrie_impl.hpp
View file @
5d5def40
...
...
@@ -152,11 +152,12 @@ bool zmq::generic_mtrie_t<T>::add_helper (prefix_t prefix_,
template
<
typename
T
>
template
<
typename
Arg
>
void
zmq
::
generic_mtrie_t
<
T
>::
rm
(
value_t
*
pipe_
,
void
(
*
func_
)
(
prefix_t
data_
,
size_t
size_
,
void
*
arg_
),
void
*
arg_
,
Arg
arg_
),
Arg
arg_
,
bool
call_on_uniq_
)
{
unsigned
char
*
buff
=
NULL
;
...
...
@@ -165,14 +166,15 @@ void zmq::generic_mtrie_t<T>::rm (value_t *pipe_,
}
template
<
typename
T
>
void
zmq
::
generic_mtrie_t
<
T
>::
rm_helper
(
value_t
*
pipe_
,
template
<
typename
Arg
>
void
zmq
::
generic_mtrie_t
<
T
>::
rm_helper
(
value_t
*
pipe_
,
unsigned
char
**
buff_
,
size_t
buffsize_
,
size_t
maxbuffsize_
,
void
(
*
func_
)
(
prefix_t
data_
,
size_t
size_
,
void
*
arg_
),
void
*
arg_
,
Arg
arg_
),
Arg
arg_
,
bool
call_on_uniq_
)
{
// Remove the subscription from this node.
...
...
@@ -405,10 +407,11 @@ bool zmq::generic_mtrie_t<T>::rm_helper (prefix_t prefix_,
}
template
<
typename
T
>
template
<
typename
Arg
>
void
zmq
::
generic_mtrie_t
<
T
>::
match
(
prefix_t
data_
,
size_t
size_
,
void
(
*
func_
)
(
value_t
*
pipe_
,
void
*
arg_
),
void
*
arg_
)
void
(
*
func_
)
(
value_t
*
pipe_
,
Arg
arg_
),
Arg
arg_
)
{
generic_mtrie_t
*
current
=
this
;
while
(
true
)
{
...
...
src/xpub.cpp
View file @
5d5def40
...
...
@@ -35,6 +35,7 @@
#include "err.hpp"
#include "msg.hpp"
#include "macros.hpp"
#include "generic_mtrie_impl.hpp"
zmq
::
xpub_t
::
xpub_t
(
class
ctx_t
*
parent_
,
uint32_t
tid_
,
int
sid_
)
:
socket_base_t
(
parent_
,
tid_
,
sid_
),
...
...
@@ -204,7 +205,7 @@ void zmq::xpub_t::xpipe_terminated (pipe_t *pipe_)
// Remove pipe without actually sending the message as it was taken
// care of by the manual call above. subscriptions is the real mtrie,
// so the pipe must be removed from there or it will be left over.
subscriptions
.
rm
(
pipe_
,
stub
,
NULL
,
false
);
subscriptions
.
rm
(
pipe_
,
stub
,
(
void
*
)
NULL
,
false
);
}
else
{
// Remove the pipe from the trie. If there are topics that nobody
// is interested in anymore, send corresponding unsubscriptions
...
...
@@ -215,10 +216,9 @@ void zmq::xpub_t::xpipe_terminated (pipe_t *pipe_)
dist
.
pipe_terminated
(
pipe_
);
}
void
zmq
::
xpub_t
::
mark_as_matching
(
pipe_t
*
pipe_
,
void
*
arg
_
)
void
zmq
::
xpub_t
::
mark_as_matching
(
pipe_t
*
pipe_
,
xpub_t
*
self
_
)
{
xpub_t
*
self
=
(
xpub_t
*
)
arg_
;
self
->
dist
.
match
(
pipe_
);
self_
->
dist
.
match
(
pipe_
);
}
int
zmq
::
xpub_t
::
xsend
(
msg_t
*
msg_
)
...
...
@@ -297,24 +297,22 @@ bool zmq::xpub_t::xhas_in ()
void
zmq
::
xpub_t
::
send_unsubscription
(
zmq
::
mtrie_t
::
prefix_t
data_
,
size_t
size_
,
void
*
arg
_
)
xpub_t
*
self
_
)
{
xpub_t
*
self
=
(
xpub_t
*
)
arg_
;
if
(
self
->
options
.
type
!=
ZMQ_PUB
)
{
if
(
self_
->
options
.
type
!=
ZMQ_PUB
)
{
// Place the unsubscription to the queue of pending (un)subscriptions
// to be retrieved by the user later on.
blob_t
unsub
(
size_
+
1
);
*
unsub
.
data
()
=
0
;
if
(
size_
>
0
)
memcpy
(
unsub
.
data
()
+
1
,
data_
,
size_
);
self
->
pending_data
.
ZMQ_PUSH_OR_EMPLACE_BACK
(
ZMQ_MOVE
(
unsub
));
self
->
pending_metadata
.
push_back
(
NULL
);
self
->
pending_flags
.
push_back
(
0
);
self
_
->
pending_data
.
ZMQ_PUSH_OR_EMPLACE_BACK
(
ZMQ_MOVE
(
unsub
));
self
_
->
pending_metadata
.
push_back
(
NULL
);
self
_
->
pending_flags
.
push_back
(
0
);
if
(
self
->
manual
)
{
self
->
last_pipe
=
NULL
;
self
->
pending_pipes
.
push_back
(
NULL
);
if
(
self
_
->
manual
)
{
self
_
->
last_pipe
=
NULL
;
self
_
->
pending_pipes
.
push_back
(
NULL
);
}
}
}
src/xpub.hpp
View file @
5d5def40
...
...
@@ -68,10 +68,10 @@ class xpub_t : public socket_base_t
// upstream.
static
void
send_unsubscription
(
zmq
::
mtrie_t
::
prefix_t
data_
,
size_t
size_
,
void
*
arg
_
);
xpub_t
*
self
_
);
// Function to be applied to each matching pipes.
static
void
mark_as_matching
(
zmq
::
pipe_t
*
pipe_
,
void
*
arg_
);
static
void
mark_as_matching
(
zmq
::
pipe_t
*
pipe_
,
xpub_t
*
arg_
);
// List of all subscriptions mapped to corresponding pipes.
mtrie_t
subscriptions
;
...
...
unittests/unittest_mtrie.cpp
View file @
5d5def40
...
...
@@ -44,10 +44,9 @@ void test_create ()
zmq
::
generic_mtrie_t
<
int
>
mtrie
;
}
void
mtrie_count
(
int
*
pipe
,
void
*
arg
)
void
mtrie_count
(
int
*
pipe
,
int
*
count
)
{
LIBZMQ_UNUSED
(
pipe
);
int
*
count
=
static_cast
<
int
*>
(
arg
);
++*
count
;
}
...
...
@@ -283,7 +282,7 @@ void test_add_multiple_reverse ()
zmq
::
generic_mtrie_t
<
int
>
mtrie
;
for
(
int
i
=
2
;
i
>=
0
;
--
i
)
{
add_indexed_expect_unique
(
mtrie
,
pipes
,
names
,
(
size_t
)
i
);
add_indexed_expect_unique
(
mtrie
,
pipes
,
names
,
(
size_t
)
i
);
}
for
(
size_t
i
=
0
;
i
<
3
;
++
i
)
{
...
...
@@ -324,10 +323,10 @@ void test_rm_multiple_reverse_order ()
void
check_name
(
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
data_
,
size_t
len_
,
void
*
void_
name_
)
const
char
*
name_
)
{
TEST_ASSERT_EQUAL_UINT
(
strlen
(
(
char
*
)
void_
name_
),
len_
);
TEST_ASSERT_EQUAL_STRING_LEN
(
void_
name_
,
data_
,
len_
);
TEST_ASSERT_EQUAL_UINT
(
strlen
(
name_
),
len_
);
TEST_ASSERT_EQUAL_STRING_LEN
(
name_
,
data_
,
len_
);
}
template
<
size_t
N
>
void
add_entries_rm_pipes_unique
(
const
char
*
(
&
names
)[
N
])
...
...
@@ -337,7 +336,7 @@ template <size_t N> void add_entries_rm_pipes_unique (const char *(&names)[N])
add_entries
(
mtrie
,
pipes
,
names
);
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
mtrie
.
rm
(
&
pipes
[
i
],
check_name
,
const_cast
<
char
*>
(
names
[
i
])
,
false
);
mtrie
.
rm
(
&
pipes
[
i
],
check_name
,
names
[
i
]
,
false
);
}
}
...
...
@@ -357,11 +356,10 @@ void test_rm_with_callback_multiple_reverse_order ()
void
check_count
(
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
data_
,
size_t
len_
,
void
*
void_
count_
)
int
*
count_
)
{
int
*
count
=
reinterpret_cast
<
int
*>
(
void_count_
);
--
count
;
TEST_ASSERT_GREATER_OR_EQUAL
(
0
,
count
);
--
count_
;
TEST_ASSERT_GREATER_OR_EQUAL
(
0
,
count_
);
}
void
add_duplicate_entry
(
zmq
::
generic_mtrie_t
<
int
>
&
mtrie
,
int
(
&
pipes
)[
2
])
...
...
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