Commit 857f4a0f authored by Jakob Otto's avatar Jakob Otto

Include review feedback

parent ec2fe898
...@@ -29,7 +29,7 @@ class multiplexer; ...@@ -29,7 +29,7 @@ class multiplexer;
class socket_manager; class socket_manager;
template <class Application, class IdType = unit_t> template <class Application, class IdType = unit_t>
class transport_worker; class transport_worker;
template <class Application, class IdType> template <class Application, class IdType = unit_t>
class transport_worker_dispatcher; class transport_worker_dispatcher;
struct network_socket; struct network_socket;
......
...@@ -58,12 +58,8 @@ public: ...@@ -58,12 +58,8 @@ public:
// -- member functions ------------------------------------------------------- // -- member functions -------------------------------------------------------
template <class Parent> template <class Parent>
error init(Parent& parent) { error init(Parent&) {
for (const auto& p : workers_by_id_) { CAF_ASSERT(workers_by_id_.empty());
auto worker = p.second;
if (auto err = worker->init(parent))
return err;
}
return none; return none;
} }
...@@ -72,7 +68,7 @@ public: ...@@ -72,7 +68,7 @@ public:
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 here? // TODO: where to get node_id from here?
add_new_worker(node_id{}, id); add_new_worker(parent, node_id{}, id);
it = workers_by_id_.find(id); it = workers_by_id_.find(id);
} }
auto worker = it->second; auto worker = it->second;
...@@ -89,7 +85,7 @@ public: ...@@ -89,7 +85,7 @@ public:
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 here? // TODO: where to get id_type from here?
add_new_worker(nid, id_type{}); add_new_worker(parent, nid, id_type{});
it = workers_by_node_.find(nid); it = workers_by_node_.find(nid);
} }
auto worker = it->second; auto worker = it->second;
...@@ -132,9 +128,11 @@ public: ...@@ -132,9 +128,11 @@ public:
} }
} }
void add_new_worker(node_id node, id_type id) { template <class Parent>
void add_new_worker(Parent& parent, node_id node, id_type id) {
auto application = factory_.make(); auto application = factory_.make();
auto worker = std::make_shared<worker_type>(std::move(application), id); auto worker = std::make_shared<worker_type>(std::move(application), id);
worker->init(parent);
workers_by_id_.emplace(std::move(id), worker); workers_by_id_.emplace(std::move(id), worker);
workers_by_node_.emplace(std::move(node), std::move(worker)); workers_by_node_.emplace(std::move(node), std::move(worker));
} }
......
...@@ -196,8 +196,9 @@ struct fixture : host_fixture { ...@@ -196,8 +196,9 @@ struct fixture : host_fixture {
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(dummy, data.nid, data.ep);
} }
buf->clear();
} }
void test_write_message(testdata& testcase) { void test_write_message(testdata& testcase) {
...@@ -249,13 +250,9 @@ struct fixture : host_fixture { ...@@ -249,13 +250,9 @@ 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) {
dispatcher_type dispatcher{dummy_application_factory{buf}};
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(contains(byte(0)));
CAF_CHECK(contains(byte(1)));
CAF_CHECK(contains(byte(2)));
CAF_CHECK(contains(byte(3)));
} }
CAF_TEST(handle_data) { CAF_TEST(handle_data) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment