Commit 69ec093f authored by Jakob Otto's avatar Jakob Otto

Cleanup

parent 0e4c456b
......@@ -32,7 +32,7 @@
namespace caf {
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>
class transport_worker_dispatcher {
public:
......@@ -57,9 +57,6 @@ public:
// -- 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>
error init(Parent& parent) {
for (const auto& p : workers_by_id_) {
......@@ -74,7 +71,7 @@ public:
void handle_data(Parent& parent, span<byte> data, id_type id) {
auto it = workers_by_id_.find(id);
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);
it = workers_by_id_.find(id);
}
......@@ -91,12 +88,11 @@ public:
auto nid = sender->node();
auto it = workers_by_node_.find(nid);
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{});
it = workers_by_node_.find(nid);
}
auto worker = it->second;
// parent should be a decorator with parent and parent->parent.
worker->write_message(parent, std::move(msg));
}
......@@ -108,7 +104,9 @@ public:
template <class Parent>
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())
return;
auto worker = workers_by_id_.begin()->second;
......@@ -148,9 +146,8 @@ private:
std::unordered_map<node_id, worker_ptr> workers_by_node_;
std::unordered_map<uint64_t, worker_ptr> workers_by_timeout_id_;
/// Factory to make application instances for transport_workers
factory_type factory_;
}; // namespace net
};
} // namespace net
} // namespace caf
......@@ -190,6 +190,10 @@ struct fixture : host_fixture {
payload);
}
bool contains(byte x) {
return std::count(buf->begin(), buf->end(), x) > 0;
}
void add_new_workers() {
for (auto& data : test_data) {
dispatcher.add_new_worker(data.nid, data.ep);
......@@ -245,9 +249,6 @@ struct fixture : host_fixture {
CAF_TEST_FIXTURE_SCOPE(transport_worker_dispatcher_test, fixture)
CAF_TEST(init) {
auto contains = [&](byte x) {
return std::count(buf->begin(), buf->end(), x) > 0;
};
if (auto err = dispatcher.init(dummy))
CAF_FAIL("init failed with error: " << err);
CAF_CHECK_EQUAL(buf->size(), 4u);
......@@ -283,9 +284,6 @@ CAF_TEST(timeout) {
}
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);
CAF_CHECK_EQUAL(buf->size(), 4u);
CAF_CHECK(contains(byte(0)));
......
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