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
69ec093f
Commit
69ec093f
authored
Aug 31, 2019
by
Jakob Otto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup
parent
0e4c456b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
16 deletions
+11
-16
libcaf_net/caf/net/transport_worker_dispatcher.hpp
libcaf_net/caf/net/transport_worker_dispatcher.hpp
+7
-10
libcaf_net/test/transport_worker_dispatcher.cpp
libcaf_net/test/transport_worker_dispatcher.cpp
+4
-6
No files found.
libcaf_net/caf/net/transport_worker_dispatcher.hpp
View file @
69ec093f
...
@@ -32,7 +32,7 @@
...
@@ -32,7 +32,7 @@
namespace
caf
{
namespace
caf
{
namespace
net
{
namespace
net
{
/// implements a dispatcher that dispatches
calls to the right worker
/// implements a dispatcher that dispatches
between transport and workers.
template
<
class
ApplicationFactory
,
class
IdType
>
template
<
class
ApplicationFactory
,
class
IdType
>
class
transport_worker_dispatcher
{
class
transport_worker_dispatcher
{
public:
public:
...
@@ -57,9 +57,6 @@ public:
...
@@ -57,9 +57,6 @@ public:
// -- member functions -------------------------------------------------------
// -- member functions -------------------------------------------------------
/// Initializes all contained contained workers.
/// @param The parent of this Dispatcher
/// @return error if something went wrong sec::none when init() worked.
template
<
class
Parent
>
template
<
class
Parent
>
error
init
(
Parent
&
parent
)
{
error
init
(
Parent
&
parent
)
{
for
(
const
auto
&
p
:
workers_by_id_
)
{
for
(
const
auto
&
p
:
workers_by_id_
)
{
...
@@ -74,7 +71,7 @@ public:
...
@@ -74,7 +71,7 @@ public:
void
handle_data
(
Parent
&
parent
,
span
<
byte
>
data
,
id_type
id
)
{
void
handle_data
(
Parent
&
parent
,
span
<
byte
>
data
,
id_type
id
)
{
auto
it
=
workers_by_id_
.
find
(
id
);
auto
it
=
workers_by_id_
.
find
(
id
);
if
(
it
==
workers_by_id_
.
end
())
{
if
(
it
==
workers_by_id_
.
end
())
{
// TODO: where to get node_id from
in this scope.
// TODO: where to get node_id from
here?
add_new_worker
(
node_id
{},
id
);
add_new_worker
(
node_id
{},
id
);
it
=
workers_by_id_
.
find
(
id
);
it
=
workers_by_id_
.
find
(
id
);
}
}
...
@@ -91,12 +88,11 @@ public:
...
@@ -91,12 +88,11 @@ public:
auto
nid
=
sender
->
node
();
auto
nid
=
sender
->
node
();
auto
it
=
workers_by_node_
.
find
(
nid
);
auto
it
=
workers_by_node_
.
find
(
nid
);
if
(
it
==
workers_by_node_
.
end
())
{
if
(
it
==
workers_by_node_
.
end
())
{
// TODO: where to get id_type from
in this scope.
// TODO: where to get id_type from
here?
add_new_worker
(
nid
,
id_type
{});
add_new_worker
(
nid
,
id_type
{});
it
=
workers_by_node_
.
find
(
nid
);
it
=
workers_by_node_
.
find
(
nid
);
}
}
auto
worker
=
it
->
second
;
auto
worker
=
it
->
second
;
// parent should be a decorator with parent and parent->parent.
worker
->
write_message
(
parent
,
std
::
move
(
msg
));
worker
->
write_message
(
parent
,
std
::
move
(
msg
));
}
}
...
@@ -108,7 +104,9 @@ public:
...
@@ -108,7 +104,9 @@ public:
template
<
class
Parent
>
template
<
class
Parent
>
void
resolve
(
Parent
&
parent
,
const
std
::
string
&
path
,
actor
listener
)
{
void
resolve
(
Parent
&
parent
,
const
std
::
string
&
path
,
actor
listener
)
{
// TODO: How to find the right worker? use path somehow?
// TODO path should be uri to lookup the corresponding worker
// if enpoint is known -> resolve actor through worker
// if not connect to endpoint?!
if
(
workers_by_id_
.
empty
())
if
(
workers_by_id_
.
empty
())
return
;
return
;
auto
worker
=
workers_by_id_
.
begin
()
->
second
;
auto
worker
=
workers_by_id_
.
begin
()
->
second
;
...
@@ -148,9 +146,8 @@ private:
...
@@ -148,9 +146,8 @@ private:
std
::
unordered_map
<
node_id
,
worker_ptr
>
workers_by_node_
;
std
::
unordered_map
<
node_id
,
worker_ptr
>
workers_by_node_
;
std
::
unordered_map
<
uint64_t
,
worker_ptr
>
workers_by_timeout_id_
;
std
::
unordered_map
<
uint64_t
,
worker_ptr
>
workers_by_timeout_id_
;
/// Factory to make application instances for transport_workers
factory_type
factory_
;
factory_type
factory_
;
};
// namespace net
};
}
// namespace net
}
// namespace net
}
// namespace caf
}
// namespace caf
libcaf_net/test/transport_worker_dispatcher.cpp
View file @
69ec093f
...
@@ -190,6 +190,10 @@ struct fixture : host_fixture {
...
@@ -190,6 +190,10 @@ struct fixture : host_fixture {
payload
);
payload
);
}
}
bool
contains
(
byte
x
)
{
return
std
::
count
(
buf
->
begin
(),
buf
->
end
(),
x
)
>
0
;
}
void
add_new_workers
()
{
void
add_new_workers
()
{
for
(
auto
&
data
:
test_data
)
{
for
(
auto
&
data
:
test_data
)
{
dispatcher
.
add_new_worker
(
data
.
nid
,
data
.
ep
);
dispatcher
.
add_new_worker
(
data
.
nid
,
data
.
ep
);
...
@@ -245,9 +249,6 @@ struct fixture : host_fixture {
...
@@ -245,9 +249,6 @@ struct fixture : host_fixture {
CAF_TEST_FIXTURE_SCOPE
(
transport_worker_dispatcher_test
,
fixture
)
CAF_TEST_FIXTURE_SCOPE
(
transport_worker_dispatcher_test
,
fixture
)
CAF_TEST
(
init
)
{
CAF_TEST
(
init
)
{
auto
contains
=
[
&
](
byte
x
)
{
return
std
::
count
(
buf
->
begin
(),
buf
->
end
(),
x
)
>
0
;
};
if
(
auto
err
=
dispatcher
.
init
(
dummy
))
if
(
auto
err
=
dispatcher
.
init
(
dummy
))
CAF_FAIL
(
"init failed with error: "
<<
err
);
CAF_FAIL
(
"init failed with error: "
<<
err
);
CAF_CHECK_EQUAL
(
buf
->
size
(),
4u
);
CAF_CHECK_EQUAL
(
buf
->
size
(),
4u
);
...
@@ -283,9 +284,6 @@ CAF_TEST(timeout) {
...
@@ -283,9 +284,6 @@ CAF_TEST(timeout) {
}
}
CAF_TEST
(
handle_error
)
{
CAF_TEST
(
handle_error
)
{
auto
contains
=
[
&
](
byte
x
)
{
return
std
::
count
(
buf
->
begin
(),
buf
->
end
(),
x
)
>
0
;
};
dispatcher
.
handle_error
(
sec
::
unavailable_or_would_block
);
dispatcher
.
handle_error
(
sec
::
unavailable_or_would_block
);
CAF_CHECK_EQUAL
(
buf
->
size
(),
4u
);
CAF_CHECK_EQUAL
(
buf
->
size
(),
4u
);
CAF_CHECK
(
contains
(
byte
(
0
)));
CAF_CHECK
(
contains
(
byte
(
0
)));
...
...
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