Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
eb526e49
Unverified
Commit
eb526e49
authored
Feb 23, 2021
by
Dominik Charousset
Committed by
GitHub
Feb 23, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1223
Fix LGTM warnings
parents
eea24e16
49c9d1be
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
23 deletions
+35
-23
examples/broker/simple_broker.cpp
examples/broker/simple_broker.cpp
+29
-20
libcaf_core/src/detail/type_id_list_builder.cpp
libcaf_core/src/detail/type_id_list_builder.cpp
+6
-3
No files found.
examples/broker/simple_broker.cpp
View file @
eb526e49
...
...
@@ -54,7 +54,7 @@ behavior ping(event_based_actor* self, size_t num_pings) {
auto
count
=
std
::
make_shared
<
size_t
>
(
0
);
return
{
[
=
](
ok_atom
,
const
actor
&
pong
)
{
self
->
send
(
pong
,
ping_atom_v
,
int32_t
(
1
)
);
self
->
send
(
pong
,
ping_atom_v
,
int32_t
{
1
}
);
self
->
become
([
=
](
pong_atom
,
int32_t
value
)
->
result
<
ping_atom
,
int32_t
>
{
if
(
++*
count
>=
num_pings
)
self
->
quit
();
...
...
@@ -76,17 +76,21 @@ behavior pong() {
template
<
class
T
>
void
write_int
(
broker
*
self
,
connection_handle
hdl
,
T
value
)
{
using
unsigned_type
=
typename
std
::
make_unsigned
<
T
>::
type
;
auto
cpy
=
static_cast
<
T
>
(
htonl
(
static_cast
<
unsigned_type
>
(
value
)));
self
->
write
(
hdl
,
sizeof
(
T
),
&
cpy
);
self
->
flush
(
hdl
);
if
constexpr
(
sizeof
(
T
)
>
1
)
{
auto
cpy
=
static_cast
<
T
>
(
htonl
(
static_cast
<
unsigned_type
>
(
value
)));
self
->
write
(
hdl
,
sizeof
(
T
),
&
cpy
);
}
else
{
self
->
write
(
hdl
,
sizeof
(
T
),
&
value
);
}
}
// Utility function for reading an in
g
eger from incoming data.
// Utility function for reading an in
t
eger from incoming data.
template
<
class
T
>
void
read_int
(
const
void
*
data
,
T
&
storage
)
{
using
unsigned_type
=
typename
std
::
make_unsigned
<
T
>::
type
;
memcpy
(
&
storage
,
data
,
sizeof
(
T
));
storage
=
static_cast
<
T
>
(
ntohl
(
static_cast
<
unsigned_type
>
(
storage
)));
if
constexpr
(
sizeof
(
T
)
>
1
)
storage
=
static_cast
<
T
>
(
ntohl
(
static_cast
<
unsigned_type
>
(
storage
)));
}
// Implementation of our broker.
...
...
@@ -103,10 +107,10 @@ behavior broker_impl(broker* self, connection_handle hdl, const actor& buddy) {
self
->
quit
(
dm
.
reason
);
}
});
// Setup: we are exchanging only messages consisting of an
atom
// (as uint
64
_t) and an integer value (int32_t).
self
->
configure_read
(
hdl
,
receive_policy
::
exactly
(
sizeof
(
uint64_t
)
+
sizeof
(
int32_t
)));
// Setup: we are exchanging only messages consisting of an
operation
// (as uint
8
_t) and an integer value (int32_t).
self
->
configure_read
(
hdl
,
receive_policy
::
exactly
(
sizeof
(
uint8_t
)
+
sizeof
(
int32_t
)));
// Our message handlers.
return
{
[
=
](
const
connection_closed_msg
&
msg
)
{
...
...
@@ -124,28 +128,33 @@ behavior broker_impl(broker* self, connection_handle hdl, const actor& buddy) {
aout
(
self
)
<<
"send {ping, "
<<
i
<<
"}"
<<
endl
;
write_int
(
self
,
hdl
,
static_cast
<
uint8_t
>
(
op
::
ping
));
write_int
(
self
,
hdl
,
i
);
self
->
flush
(
hdl
);
},
[
=
](
pong_atom
,
int32_t
i
)
{
aout
(
self
)
<<
"send {pong, "
<<
i
<<
"}"
<<
endl
;
write_int
(
self
,
hdl
,
static_cast
<
uint8_t
>
(
op
::
pong
));
write_int
(
self
,
hdl
,
i
);
self
->
flush
(
hdl
);
},
[
=
](
const
new_data_msg
&
msg
)
{
// Read the operation value as uint8_t from buffer.
uint8_t
op_val
;
read_int
(
msg
.
buf
.
data
(),
op_val
);
// Read integer value from buffer, jumping to the correct
// position via offset_data(...).
int32_t
ival
;
read_int
(
msg
.
buf
.
data
()
+
sizeof
(
uint8_t
),
ival
);
// Keeps track of our position in the buffer.
auto
rd_pos
=
msg
.
buf
.
data
();
// Read the operation value as uint8_t from the buffer.
auto
op_val
=
uint8_t
{
0
};
read_int
(
rd_pos
,
op_val
);
++
rd_pos
;
// Read the integer value from the buffer.
auto
ival
=
int32_t
{
0
};
read_int
(
rd_pos
,
ival
);
// Show some output.
aout
(
self
)
<<
"received {"
<<
op_val
<<
", "
<<
ival
<<
"}"
<<
endl
;
// Send composed message to our buddy.
switch
(
static_cast
<
op
>
(
op_val
))
{
case
op
:
:
ping
:
aout
(
self
)
<<
"received {ping, "
<<
ival
<<
"}"
<<
endl
;
self
->
send
(
buddy
,
ping_atom_v
,
ival
);
break
;
case
op
:
:
pong
:
aout
(
self
)
<<
"received {pong, "
<<
ival
<<
"}"
<<
endl
;
self
->
send
(
buddy
,
pong_atom_v
,
ival
);
break
;
default:
...
...
@@ -208,8 +217,8 @@ void run_client(actor_system& system, const config& cfg) {
<<
endl
;
return
;
}
print_on_exit
(
ping_actor
,
"ping"
);
print_on_exit
(
*
io_actor
,
"
protobuf_io
"
);
print_on_exit
(
ping_actor
,
"ping
actor
"
);
print_on_exit
(
*
io_actor
,
"
broker
"
);
send_as
(
*
io_actor
,
ping_actor
,
ok_atom_v
,
*
io_actor
);
}
...
...
libcaf_core/src/detail/type_id_list_builder.cpp
View file @
eb526e49
...
...
@@ -20,9 +20,12 @@ namespace {
struct
dyn_type_id_list
{
explicit
dyn_type_id_list
(
type_id_t
*
storage
)
noexcept
:
storage
(
storage
)
{
CAF_ASSERT
(
storage
!=
nullptr
);
auto
first
=
reinterpret_cast
<
const
byte
*>
(
storage
);
auto
last
=
first
+
((
storage
[
0
]
+
1
)
*
sizeof
(
type_id_t
));
hash
=
caf
::
hash
::
fnv
<
size_t
>::
compute
(
make_span
(
first
,
last
));
auto
first
=
storage
+
1
;
auto
last
=
first
+
storage
[
0
];
caf
::
hash
::
fnv
<
size_t
>
h
;
for
(
auto
i
=
first
;
i
!=
last
;
++
i
)
h
.
value
(
*
i
);
hash
=
h
.
result
;
}
dyn_type_id_list
(
dyn_type_id_list
&&
other
)
noexcept
...
...
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