Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
actor-incubator
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
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-incubator
Commits
b56f485f
Commit
b56f485f
authored
Oct 18, 2019
by
Jakob Otto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use basp::worker for serializing
parent
58cfcbd2
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
54 additions
and
36 deletions
+54
-36
libcaf_net/caf/net/basp/application.hpp
libcaf_net/caf/net/basp/application.hpp
+9
-0
libcaf_net/caf/net/basp/message_queue.hpp
libcaf_net/caf/net/basp/message_queue.hpp
+1
-1
libcaf_net/caf/net/basp/worker.hpp
libcaf_net/caf/net/basp/worker.hpp
+1
-1
libcaf_net/src/application.cpp
libcaf_net/src/application.cpp
+36
-28
libcaf_net/src/net/backend/test.cpp
libcaf_net/src/net/backend/test.cpp
+2
-2
libcaf_net/src/worker.cpp
libcaf_net/src/worker.cpp
+2
-1
libcaf_net/test/net/basp/worker.cpp
libcaf_net/test/net/basp/worker.cpp
+3
-3
No files found.
libcaf_net/caf/net/basp/application.hpp
View file @
b56f485f
...
...
@@ -28,11 +28,14 @@
#include "caf/actor_addr.hpp"
#include "caf/byte.hpp"
#include "caf/callback.hpp"
#include "caf/detail/worker_hub.hpp"
#include "caf/error.hpp"
#include "caf/net/basp/connection_state.hpp"
#include "caf/net/basp/constants.hpp"
#include "caf/net/basp/header.hpp"
#include "caf/net/basp/message_queue.hpp"
#include "caf/net/basp/message_type.hpp"
#include "caf/net/basp/worker.hpp"
#include "caf/net/endpoint_manager.hpp"
#include "caf/net/packet_writer.hpp"
#include "caf/net/receive_policy.hpp"
...
...
@@ -57,6 +60,8 @@ public:
using
byte_span
=
span
<
const
byte
>
;
using
hub_type
=
detail
::
worker_hub
<
worker
>
;
struct
test_tag
{};
// -- constructors, destructors, and assignment operators --------------------
...
...
@@ -193,6 +198,10 @@ private:
/// Provides pointers to the actor system as well as the registry,
/// serializers and deserializer.
scoped_execution_unit
executor_
;
std
::
unique_ptr
<
message_queue
>
queue_
;
std
::
unique_ptr
<
hub_type
>
hub_
;
};
}
// namespace basp
...
...
libcaf_net/caf/net/basp/message_queue.hpp
View file @
b56f485f
...
...
@@ -77,5 +77,5 @@ public:
};
}
// namespace basp
}
// namespace
io
}
// namespace
net
}
// namespace caf
libcaf_net/caf/net/basp/worker.hpp
View file @
b56f485f
...
...
@@ -50,7 +50,7 @@ public:
using
scheduler_type
=
scheduler
::
abstract_coordinator
;
using
buffer_type
=
std
::
vector
<
char
>
;
using
buffer_type
=
std
::
vector
<
byte
>
;
using
hub_type
=
detail
::
worker_hub
<
worker
>
;
...
...
libcaf_net/src/application.cpp
View file @
b56f485f
...
...
@@ -44,7 +44,10 @@ namespace caf {
namespace
net
{
namespace
basp
{
application
::
application
(
proxy_registry
&
proxies
)
:
proxies_
(
proxies
)
{
application
::
application
(
proxy_registry
&
proxies
)
:
proxies_
(
proxies
),
queue_
{
std
::
unique_ptr
<
message_queue
>
{
new
message_queue
}},
hub_
{
std
::
unique_ptr
<
hub_type
>
{
new
hub_type
}}
{
// nop
}
...
...
@@ -248,34 +251,39 @@ error application::handle_handshake(packet_writer&, header hdr,
error
application
::
handle_actor_message
(
packet_writer
&
,
header
hdr
,
byte_span
payload
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
hdr
)
<<
CAF_ARG2
(
"payload.size"
,
payload
.
size
()));
// Deserialize payload.
actor_id
src_id
=
0
;
node_id
src_node
;
actor_id
dst_id
=
0
;
std
::
vector
<
strong_actor_ptr
>
fwd_stack
;
message
content
;
binary_deserializer
source
{
&
executor_
,
payload
};
if
(
auto
err
=
source
(
src_node
,
src_id
,
dst_id
,
fwd_stack
,
content
))
return
err
;
// Sanity checks.
if
(
dst_id
==
0
)
return
ec
::
invalid_payload
;
// Try to fetch the receiver.
auto
dst_hdl
=
system
().
registry
().
get
(
dst_id
);
if
(
dst_hdl
==
nullptr
)
{
CAF_LOG_DEBUG
(
"no actor found for given ID, drop message"
);
return
caf
::
none
;
auto
worker
=
hub_
->
pop
();
buffer_type
buf
(
payload
.
begin
(),
payload
.
end
());
if
(
worker
!=
nullptr
)
{
CAF_LOG_DEBUG
(
"launch BASP worker for deserializing an actor_message"
);
worker
->
launch
(
node_id
{},
hdr
,
buf
);
}
else
{
CAF_LOG_DEBUG
(
"out of BASP workers, continue deserializing an actor_message"
);
// If no worker is available then we have no other choice than to take
// the performance hit and deserialize in this thread.
struct
handler
:
remote_message_handler
<
handler
>
{
handler
(
message_queue
*
queue
,
proxy_registry
*
proxies
,
actor_system
*
system
,
node_id
last_hop
,
basp
::
header
&
hdr
,
buffer_type
&
payload
)
:
queue_
(
queue
),
proxies_
(
proxies
),
system_
(
system
),
last_hop_
(
std
::
move
(
last_hop
)),
hdr_
(
hdr
),
payload_
(
payload
)
{
msg_id_
=
queue_
->
new_id
();
}
message_queue
*
queue_
;
proxy_registry
*
proxies_
;
actor_system
*
system_
;
node_id
last_hop_
;
basp
::
header
&
hdr_
;
buffer_type
&
payload_
;
uint64_t
msg_id_
;
};
handler
f
{
queue_
.
get
(),
&
proxies_
,
system_
,
node_id
{},
hdr
,
buf
};
f
.
handle_remote_message
(
&
executor_
);
}
// Try to fetch the sender.
strong_actor_ptr
src_hdl
;
if
(
src_node
!=
none
&&
src_id
!=
0
)
src_hdl
=
proxies_
.
get_or_put
(
src_node
,
src_id
);
// Ship the message.
auto
ptr
=
make_mailbox_element
(
std
::
move
(
src_hdl
),
make_message_id
(
hdr
.
operation_data
),
std
::
move
(
fwd_stack
),
std
::
move
(
content
));
dst_hdl
->
get
()
->
enqueue
(
std
::
move
(
ptr
),
nullptr
);
return
none
;
}
...
...
libcaf_net/src/net/backend/test.cpp
View file @
b56f485f
...
...
@@ -75,9 +75,9 @@ test::peer_entry& test::emplace(const node_id& peer_id, stream_socket first,
using
transport_type
=
stream_transport
<
basp
::
application
>
;
nonblocking
(
second
,
true
);
auto
mpx
=
mm_
.
mpx
();
basp
::
application
app
{
proxies_
};
auto
mgr
=
make_endpoint_manager
(
mpx
,
mm_
.
system
(),
transport_type
{
second
,
basp
::
application
{
proxies_
}});
transport_type
{
second
,
std
::
move
(
app
)});
if
(
auto
err
=
mgr
->
init
())
{
CAF_LOG_ERROR
(
"mgr->init() failed: "
<<
mm_
.
system
().
render
(
err
));
CAF_RAISE_ERROR
(
"mgr->init() failed"
);
...
...
libcaf_net/src/worker.cpp
View file @
b56f485f
...
...
@@ -19,6 +19,7 @@
#include "caf/net/basp/worker.hpp"
#include "caf/actor_system.hpp"
#include "caf/byte.hpp"
#include "caf/net/basp/message_queue.hpp"
#include "caf/proxy_registry.hpp"
#include "caf/scheduler/abstract_coordinator.hpp"
...
...
@@ -60,5 +61,5 @@ resumable::resume_result worker::resume(execution_unit* ctx, size_t) {
}
}
// namespace basp
}
// namespace
io
}
// namespace
net
}
// namespace caf
libcaf_net/test/net/basp/worker.cpp
View file @
b56f485f
...
...
@@ -25,10 +25,10 @@
#include "caf/actor_cast.hpp"
#include "caf/actor_control_block.hpp"
#include "caf/actor_system.hpp"
#include "caf/binary_serializer.hpp"
#include "caf/make_actor.hpp"
#include "caf/net/basp/message_queue.hpp"
#include "caf/proxy_registry.hpp"
#include "caf/serializer_impl.hpp"
using
namespace
caf
;
...
...
@@ -105,9 +105,9 @@ CAF_TEST(deliver serialized message) {
CAF_REQUIRE_NOT_EQUAL
(
hub
.
peek
(),
nullptr
);
auto
w
=
hub
.
pop
();
CAF_MESSAGE
(
"create a fake message + BASP header"
);
std
::
vector
<
char
>
payload
;
std
::
vector
<
byte
>
payload
;
std
::
vector
<
strong_actor_ptr
>
stages
;
binary_serializer
sink
{
sys
,
payload
};
serializer_impl
<
std
::
vector
<
byte
>>
sink
{
sys
,
payload
};
if
(
auto
err
=
sink
(
node_id
{},
self
->
id
(),
testee
.
id
(),
stages
,
make_message
(
ok_atom
::
value
)))
CAF_FAIL
(
"unable to serialize message: "
<<
sys
.
render
(
err
));
...
...
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