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
49c9d1be
Commit
49c9d1be
authored
Feb 23, 2021
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix LGTM warnings
parent
eea24e16
Changes
2
Show 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 @
49c9d1be
...
@@ -54,7 +54,7 @@ behavior ping(event_based_actor* self, size_t num_pings) {
...
@@ -54,7 +54,7 @@ behavior ping(event_based_actor* self, size_t num_pings) {
auto
count
=
std
::
make_shared
<
size_t
>
(
0
);
auto
count
=
std
::
make_shared
<
size_t
>
(
0
);
return
{
return
{
[
=
](
ok_atom
,
const
actor
&
pong
)
{
[
=
](
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
>
{
self
->
become
([
=
](
pong_atom
,
int32_t
value
)
->
result
<
ping_atom
,
int32_t
>
{
if
(
++*
count
>=
num_pings
)
if
(
++*
count
>=
num_pings
)
self
->
quit
();
self
->
quit
();
...
@@ -76,16 +76,20 @@ behavior pong() {
...
@@ -76,16 +76,20 @@ behavior pong() {
template
<
class
T
>
template
<
class
T
>
void
write_int
(
broker
*
self
,
connection_handle
hdl
,
T
value
)
{
void
write_int
(
broker
*
self
,
connection_handle
hdl
,
T
value
)
{
using
unsigned_type
=
typename
std
::
make_unsigned
<
T
>::
type
;
using
unsigned_type
=
typename
std
::
make_unsigned
<
T
>::
type
;
if
constexpr
(
sizeof
(
T
)
>
1
)
{
auto
cpy
=
static_cast
<
T
>
(
htonl
(
static_cast
<
unsigned_type
>
(
value
)));
auto
cpy
=
static_cast
<
T
>
(
htonl
(
static_cast
<
unsigned_type
>
(
value
)));
self
->
write
(
hdl
,
sizeof
(
T
),
&
cpy
);
self
->
write
(
hdl
,
sizeof
(
T
),
&
cpy
);
self
->
flush
(
hdl
);
}
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
>
template
<
class
T
>
void
read_int
(
const
void
*
data
,
T
&
storage
)
{
void
read_int
(
const
void
*
data
,
T
&
storage
)
{
using
unsigned_type
=
typename
std
::
make_unsigned
<
T
>::
type
;
using
unsigned_type
=
typename
std
::
make_unsigned
<
T
>::
type
;
memcpy
(
&
storage
,
data
,
sizeof
(
T
));
memcpy
(
&
storage
,
data
,
sizeof
(
T
));
if
constexpr
(
sizeof
(
T
)
>
1
)
storage
=
static_cast
<
T
>
(
ntohl
(
static_cast
<
unsigned_type
>
(
storage
)));
storage
=
static_cast
<
T
>
(
ntohl
(
static_cast
<
unsigned_type
>
(
storage
)));
}
}
...
@@ -103,10 +107,10 @@ behavior broker_impl(broker* self, connection_handle hdl, const actor& buddy) {
...
@@ -103,10 +107,10 @@ behavior broker_impl(broker* self, connection_handle hdl, const actor& buddy) {
self
->
quit
(
dm
.
reason
);
self
->
quit
(
dm
.
reason
);
}
}
});
});
// Setup: we are exchanging only messages consisting of an
atom
// Setup: we are exchanging only messages consisting of an
operation
// (as uint
64
_t) and an integer value (int32_t).
// (as uint
8
_t) and an integer value (int32_t).
self
->
configure_read
(
self
->
configure_read
(
hdl
,
receive_policy
::
exactly
(
sizeof
(
uint8_t
)
hdl
,
receive_policy
::
exactly
(
sizeof
(
uint64_t
)
+
sizeof
(
int32_t
)));
+
sizeof
(
int32_t
)));
// Our message handlers.
// Our message handlers.
return
{
return
{
[
=
](
const
connection_closed_msg
&
msg
)
{
[
=
](
const
connection_closed_msg
&
msg
)
{
...
@@ -124,28 +128,33 @@ behavior broker_impl(broker* self, connection_handle hdl, const actor& buddy) {
...
@@ -124,28 +128,33 @@ behavior broker_impl(broker* self, connection_handle hdl, const actor& buddy) {
aout
(
self
)
<<
"send {ping, "
<<
i
<<
"}"
<<
endl
;
aout
(
self
)
<<
"send {ping, "
<<
i
<<
"}"
<<
endl
;
write_int
(
self
,
hdl
,
static_cast
<
uint8_t
>
(
op
::
ping
));
write_int
(
self
,
hdl
,
static_cast
<
uint8_t
>
(
op
::
ping
));
write_int
(
self
,
hdl
,
i
);
write_int
(
self
,
hdl
,
i
);
self
->
flush
(
hdl
);
},
},
[
=
](
pong_atom
,
int32_t
i
)
{
[
=
](
pong_atom
,
int32_t
i
)
{
aout
(
self
)
<<
"send {pong, "
<<
i
<<
"}"
<<
endl
;
aout
(
self
)
<<
"send {pong, "
<<
i
<<
"}"
<<
endl
;
write_int
(
self
,
hdl
,
static_cast
<
uint8_t
>
(
op
::
pong
));
write_int
(
self
,
hdl
,
static_cast
<
uint8_t
>
(
op
::
pong
));
write_int
(
self
,
hdl
,
i
);
write_int
(
self
,
hdl
,
i
);
self
->
flush
(
hdl
);
},
},
[
=
](
const
new_data_msg
&
msg
)
{
[
=
](
const
new_data_msg
&
msg
)
{
// Read the operation value as uint8_t from buffer.
// Keeps track of our position in the buffer.
uint8_t
op_val
;
auto
rd_pos
=
msg
.
buf
.
data
();
read_int
(
msg
.
buf
.
data
(),
op_val
);
// Read the operation value as uint8_t from the buffer.
// Read integer value from buffer, jumping to the correct
auto
op_val
=
uint8_t
{
0
};
// position via offset_data(...).
read_int
(
rd_pos
,
op_val
);
int32_t
ival
;
++
rd_pos
;
read_int
(
msg
.
buf
.
data
()
+
sizeof
(
uint8_t
),
ival
);
// Read the integer value from the buffer.
auto
ival
=
int32_t
{
0
};
read_int
(
rd_pos
,
ival
);
// Show some output.
// Show some output.
aout
(
self
)
<<
"received {"
<<
op_val
<<
", "
<<
ival
<<
"}"
<<
endl
;
// Send composed message to our buddy.
// Send composed message to our buddy.
switch
(
static_cast
<
op
>
(
op_val
))
{
switch
(
static_cast
<
op
>
(
op_val
))
{
case
op
:
:
ping
:
case
op
:
:
ping
:
aout
(
self
)
<<
"received {ping, "
<<
ival
<<
"}"
<<
endl
;
self
->
send
(
buddy
,
ping_atom_v
,
ival
);
self
->
send
(
buddy
,
ping_atom_v
,
ival
);
break
;
break
;
case
op
:
:
pong
:
case
op
:
:
pong
:
aout
(
self
)
<<
"received {pong, "
<<
ival
<<
"}"
<<
endl
;
self
->
send
(
buddy
,
pong_atom_v
,
ival
);
self
->
send
(
buddy
,
pong_atom_v
,
ival
);
break
;
break
;
default:
default:
...
@@ -208,8 +217,8 @@ void run_client(actor_system& system, const config& cfg) {
...
@@ -208,8 +217,8 @@ void run_client(actor_system& system, const config& cfg) {
<<
endl
;
<<
endl
;
return
;
return
;
}
}
print_on_exit
(
ping_actor
,
"ping"
);
print_on_exit
(
ping_actor
,
"ping
actor
"
);
print_on_exit
(
*
io_actor
,
"
protobuf_io
"
);
print_on_exit
(
*
io_actor
,
"
broker
"
);
send_as
(
*
io_actor
,
ping_actor
,
ok_atom_v
,
*
io_actor
);
send_as
(
*
io_actor
,
ping_actor
,
ok_atom_v
,
*
io_actor
);
}
}
...
...
libcaf_core/src/detail/type_id_list_builder.cpp
View file @
49c9d1be
...
@@ -20,9 +20,12 @@ namespace {
...
@@ -20,9 +20,12 @@ namespace {
struct
dyn_type_id_list
{
struct
dyn_type_id_list
{
explicit
dyn_type_id_list
(
type_id_t
*
storage
)
noexcept
:
storage
(
storage
)
{
explicit
dyn_type_id_list
(
type_id_t
*
storage
)
noexcept
:
storage
(
storage
)
{
CAF_ASSERT
(
storage
!=
nullptr
);
CAF_ASSERT
(
storage
!=
nullptr
);
auto
first
=
reinterpret_cast
<
const
byte
*>
(
storage
);
auto
first
=
storage
+
1
;
auto
last
=
first
+
((
storage
[
0
]
+
1
)
*
sizeof
(
type_id_t
));
auto
last
=
first
+
storage
[
0
];
hash
=
caf
::
hash
::
fnv
<
size_t
>::
compute
(
make_span
(
first
,
last
));
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
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