Commit 0c3537cb authored by neverlord's avatar neverlord

distributed benchmark

parent 51cc731e
......@@ -86,7 +86,13 @@ void usage()
<< " of given servers, use HOST:PORT syntax" << endl
<< " --num_pings=NUM run benchmark with NUM messages per node"<< endl
<< endl
<< " example: --mode=benchmark 192.168.9.1:123 --num_pings=100"<< endl
<< " example: --mode=benchmark 192.168.9.1:1234 "
"192.168.9.2:1234 "
"--num_pings=100" << endl
<< endl
<< endl
<< "Shutdown servers:" << endl
<< " --mode=shutdown shuts down any number of given servers" << endl
<< endl
<< endl
<< "Miscellaneous:" << endl
......@@ -224,6 +230,11 @@ struct server_actor : fsm_actor<server_actor>
});
if (i != m_pongs.end()) m_pongs.erase(i);
},
on(atom("shutdown")) >> [=]()
{
m_pongs.clear();
become_void();
},
others() >> [=]()
{
cout << "unexpected: " << to_string(last_dequeued()) << endl;
......@@ -324,6 +335,11 @@ void client_mode(Iterator first, Iterator last)
cout << "no non-zero, non-negative init value given" << endl;
exit(1);
}
if (remotes.size() < 2)
{
cout << "less than two nodes given" << endl;
exit(1);
}
std::vector<actor_ptr> remote_actors;
for (auto& r : remotes)
{
......@@ -398,6 +414,48 @@ void client_mode(Iterator first, Iterator last)
await_all_others_done();
}
template<typename Iterator>
void shutdown_mode(Iterator first, Iterator last)
{
std::vector<std::pair<string, uint16_t> > remotes;
match_each(first, last, std::bind(split, std::placeholders::_1, ':'))
(
on(val<string>, _2i) >> [&](string& host, int port)
{
if (port <= 1024 || port >= 65536)
{
throw std::invalid_argument("illegal port: " + std::to_string(port));
}
remotes.emplace_back(std::move(host), static_cast<uint16_t>(port));
}
);
for (auto& r : remotes)
{
try
{
actor_ptr x = remote_actor(r.first.c_str(), r.second);
monitor(x);
send(x, atom("shutdown"));
receive
(
on(atom("DOWN"), x, val<std::uint32_t>) >> []()
{
// ok, done
},
after(std::chrono::seconds(10)) >> [&]()
{
cout << r.first << ":" << r.second << " didn't shut down "
<< "within 10s"
<< endl;
}
);
}
catch (...)
{
}
}
}
int main(int argc, char** argv)
{
if (argc < 2) usage();
......@@ -405,13 +463,23 @@ int main(int argc, char** argv)
auto last = argv + argc;
match(*first)
(
on<string>().when(_x1.in({"-h", "--help"})) >> []() { usage(); },
on("--mode=server") >> [=]() { server_mode(first + 1, last); },
on<string>().when(_x1.in({"-h", "--help"})) >> []()
{
usage();
},
on("--mode=server") >> [=]()
{
server_mode(first + 1, last);
},
on("--mode=benchmark") >> [=]()
{
client_mode(first + 1, last);
await_all_others_done();
},
on("--mode=shutdown") >> [=]()
{
shutdown_mode(first + 1, last);
},
others() >> [=]()
{
usage("unknown argument: ", *first);
......
-module(distributed).
-export([start/1, ping_loop/2]).
ping_loop(Parent, Pong) ->
receive
{pong, 0} -> Parent ! done;
{pong, X} ->
Pong ! {self(), ping, X - 1},
ping_loop(Parent, Pong);
{kickoff, Value} ->
Pong ! {ping, self(), Value},
ping_loop(Parent, Pong)
end.
server_loop(Pongs) ->
receive
{ping, Pid, Value} -> Pid ! {pong, Value};
{add_pong, Pid, Node} ->
case lists:any(fun({N, _}) -> N == Node end, Pongs) of
true ->
Pid ! {ok},
server_loop(Pongs);
false ->
case rpc:call(Node, erlang, whereis, [pong]) of
{badrpc, Reason} -> Pid ! {error, Reason};
Pong ->
Pid ! {ok},
server_loop(Pongs ++ [{Node, Pong}])
end
end;
{purge} -> server_loop([]);
{kickoff, Pid, NumPings} ->
lists:foreach(fun({_, P}) -> spawn(distributed, ping_loop, [Pid, P]) ! {kickoff, NumPings} end, Pongs),
server_loop(Pongs)
end.
server_mode() ->
register(pong, self()),
server_loop([]).
add_pong_fun(_, _, []) -> true;
add_pong_fun(Pong, Node, [Node|T]) -> add_pong_fun(Pong, Node, T);
add_pong_fun(Pong, Node, [H|T]) ->
Pong ! {add_pong, H},
receive
{ok} -> add_pong_fun(Pong, Node, T);
{error, Reason} -> error(Reason)
end.
% receive a {done} message for each node
client_mode([], [], [], _) -> true;
client_mode([], [], [_|T], NumPings) ->
receive {done} ->
client_mode([], [], T, NumPings)
end;
% send kickoff messages
client_mode([Pong|Pongs], [], Nodes, NumPings) ->
Pong ! {kickoff, self(), NumPings},
client_mode(Pongs, [], Nodes, NumPings);
client_mode(Pongs, [H|T], Nodes, NumPings) ->
case rpc:call(H, erlang, whereis, [pong]) of
{badrpc, Reason} ->
io:format("cannot connect to ~s~n", [atom_to_list(H)]),
error(Reason);
P ->
add_pong_fun(P, H, Nodes),
client_mode(Pongs ++ [P], T, Nodes, NumPings)
end.
run([], undefined, ['mode=server']) -> server_mode();
run(_, undefined, []) -> error("NumPings is undefined");
run(Hosts, _, []) when length(Hosts) < 2 -> error("less than two nodes specified");
run(Hosts, NumPings, []) -> client_mode([], Hosts, Hosts, NumPings);
run(Hosts, NumPings, [H|T]) ->
Arg = atom_to_list(H),
SetNumPings = lists:prefix("num_pings=", Arg),
if
SetNumPings == true andalso NumPings /= undefined ->
error("NumPings already set");
SetNumPings == true ->
run(Hosts, list_to_integer(lists:sublist(Arg, 11, length(Arg))), T);
true ->
run(Hosts ++ [H], NumPings, T)
end.
start(X) ->
run([], undefined, X).
cppa/ref_counted.hpp
cppa/cow_tuple.hpp
unit_testing/main.cpp
cppa/util/void_type.hpp
cppa/util/type_list.hpp
cppa/util/conjunction.hpp
cppa/util/disjunction.hpp
unit_testing/test.hpp
cppa/uniform_type_info.hpp
src/uniform_type_info.cpp
benchmarks/ActorCreation.scala
benchmarks/MailboxPerformance.scala
benchmarks/Matching.scala
benchmarks/MixedCase.scala
benchmarks/PingPong.scala
benchmarks/actor_creation.cpp
benchmarks/actor_creation.erl
benchmarks/distributed.cpp
benchmarks/distributed.erl
benchmarks/mailbox_performance.cpp
benchmarks/mailbox_performance.erl
benchmarks/matching.cpp
benchmarks/matching.erl
benchmarks/mixed_case.cpp
benchmarks/mixed_case.erl
benchmarks/theron_actor_creation.cpp
benchmarks/theron_mailbox_performance.cpp
benchmarks/theron_mixed_case.cpp
benchmarks/utility.hpp
cppa/abstract_actor.hpp
cppa/abstract_event_based_actor.hpp
cppa/actor.hpp
cppa/actor_proxy.hpp
cppa/announce.hpp
cppa/any_tuple.hpp
cppa/anything.hpp
cppa/atom.hpp
cppa/attachable.hpp
cppa/behavior.hpp
cppa/binary_deserializer.hpp
cppa/binary_serializer.hpp
cppa/channel.hpp
cppa/config.hpp
unit_testing/test__tuple.cpp
cppa/cow_ptr.hpp
cppa/cow_tuple.hpp
cppa/cppa.hpp
cppa/deserializer.hpp
cppa/detail/abstract_scheduled_actor.hpp
cppa/detail/abstract_tuple.hpp
cppa/detail/tuple_vals.hpp
cppa/detail/actor_count.hpp
cppa/detail/actor_proxy_cache.hpp
cppa/detail/actor_registry.hpp
cppa/detail/addressed_message.hpp
cppa/detail/atom_val.hpp
cppa/detail/boxed.hpp
cppa/detail/buffer.hpp
cppa/detail/channel.hpp
cppa/detail/container_tuple_view.hpp
cppa/detail/converted_thread_context.hpp
cppa/detail/decorated_tuple.hpp
cppa/cow_ptr.hpp
cppa/detail/ref_counted_impl.hpp
cppa/intrusive_ptr.hpp
unit_testing/test__spawn.cpp
src/mock_scheduler.cpp
cppa/actor.hpp
unit_testing/test__intrusive_ptr.cpp
cppa/util/callable_trait.hpp
unit_testing/test__type_list.cpp
cppa/util/compare_tuples.hpp
cppa/get.hpp
cppa/detail/tdata.hpp
cppa/detail/default_uniform_type_info_impl.hpp
cppa/detail/demangle.hpp
cppa/detail/disablable_delete.hpp
cppa/detail/empty_tuple.hpp
cppa/detail/filter_result.hpp
cppa/detail/get_behavior.hpp
cppa/detail/group_manager.hpp
cppa/detail/implicit_conversions.hpp
cppa/detail/invokable.hpp
cppa/on.hpp
unit_testing/test__serialization.cpp
cppa/serializer.hpp
cppa/deserializer.hpp
cppa/object.hpp
cppa/detail/list_member.hpp
cppa/detail/mailman.hpp
cppa/detail/map_member.hpp
cppa/detail/matches.hpp
cppa/detail/mock_scheduler.hpp
cppa/detail/native_socket.hpp
cppa/detail/nestable_receive_actor.hpp
cppa/detail/network_manager.hpp
cppa/detail/object_array.hpp
cppa/detail/object_impl.hpp
cppa/detail/swap_bytes.hpp
src/serializer.cpp
src/deserializer.cpp
cppa/util/is_legal_tuple_type.hpp
cppa/util/replace_type.hpp
cppa/detail/pair_member.hpp
cppa/detail/post_office.hpp
cppa/detail/primitive_member.hpp
cppa/detail/projection.hpp
cppa/detail/pseudo_tuple.hpp
cppa/detail/ptype_to_type.hpp
cppa/detail/receive_loop_helper.hpp
cppa/detail/recursive_queue_node.hpp
cppa/detail/ref_counted_impl.hpp
cppa/detail/scheduled_actor_dummy.hpp
cppa/detail/serialize_tuple.hpp
unit_testing/test__atom.cpp
cppa/detail/singleton_manager.hpp
cppa/detail/swap_bytes.hpp
cppa/detail/tdata.hpp
cppa/detail/thread.hpp
cppa/detail/thread_pool_scheduler.hpp
cppa/detail/to_uniform_name.hpp
cppa/detail/tuple_cast_impl.hpp
cppa/detail/tuple_iterator.hpp
cppa/detail/tuple_vals.hpp
cppa/detail/tuple_view.hpp
cppa/detail/type_to_ptype.hpp
cppa/detail/types_array.hpp
cppa/detail/unboxed.hpp
cppa/detail/uniform_type_info_map.hpp
cppa/detail/value_guard.hpp
cppa/detail/yield_interface.hpp
cppa/detail/yielding_actor.hpp
cppa/either.hpp
cppa/event_based_actor.hpp
cppa/event_based_actor_base.hpp
cppa/exception.hpp
cppa/exit_reason.hpp
cppa/from_string.hpp
cppa/fsm_actor.hpp
cppa/get.hpp
cppa/group.hpp
cppa/guard_expr.hpp
cppa/intrusive/forward_iterator.hpp
cppa/intrusive/single_reader_queue.hpp
unit_testing/test__local_group.cpp
cppa/detail/channel.hpp
cppa/intrusive/singly_linked_list.hpp
cppa/intrusive_ptr.hpp
cppa/local_actor.hpp
cppa/channel.hpp
src/channel.cpp
cppa/match.hpp
cppa/match_expr.hpp
cppa/object.hpp
cppa/on.hpp
cppa/option.hpp
cppa/partial_function.hpp
cppa/pattern.hpp
cppa/primitive_type.hpp
cppa/primitive_variant.hpp
cppa/process_information.hpp
cppa/receive.hpp
cppa/ref_counted.hpp
cppa/scheduled_actor.hpp
cppa/cppa.hpp
cppa/scheduling_hint.hpp
src/scheduled_actor.cpp
cppa/group.hpp
src/group.cpp
queue_performances/main.cpp
queue_performances/sutter_list.hpp
queue_performances/defines.hpp
queue_performances/cached_stack.hpp
queue_performances/blocking_cached_stack.hpp
queue_performances/blocking_cached_stack2.hpp
queue_performances/blocking_sutter_list.hpp
queue_performances/lockfree_list.hpp
queue_performances/intrusive_sutter_list.hpp
src/local_actor.cpp
cppa/scheduler.hpp
cppa/detail/mock_scheduler.hpp
src/scheduler.cpp
cppa/detail/converted_thread_context.hpp
src/converted_thread_context.cpp
unit_testing/test__uniform_type.cpp
cppa/detail/demangle.hpp
src/demangle.cpp
cppa/detail/to_uniform_name.hpp
src/to_uniform_name.cpp
cppa/detail/default_uniform_type_info_impl.hpp
src/object.cpp
cppa/util/comparable.hpp
cppa/primitive_variant.hpp
cppa/primitive_type.hpp
cppa/util/pt_token.hpp
cppa/detail/type_to_ptype.hpp
cppa/detail/ptype_to_type.hpp
cppa/util/is_primitive.hpp
cppa/util/is_iterable.hpp
src/primitive_variant.cpp
unit_testing/test__primitive_variant.cpp
cppa/detail/primitive_member.hpp
cppa/detail/list_member.hpp
cppa/detail/pair_member.hpp
cppa/detail/map_member.hpp
cppa/util/is_forward_iterator.hpp
cppa/util/rm_ref.hpp
cppa/binary_serializer.hpp
src/binary_serializer.cpp
cppa/binary_deserializer.hpp
src/binary_deserializer.cpp
src/actor.cpp
cppa/announce.hpp
cppa/util/shared_spinlock.hpp
src/shared_spinlock.cpp
cppa/util/shared_lock_guard.hpp
cppa/detail/object_array.hpp
src/object_array.cpp
cppa/any_tuple.hpp
src/any_tuple.cpp
cppa/util/abstract_uniform_type_info.hpp
cppa/util/upgrade_lock_guard.hpp
cppa/scheduling_hint.hpp
cppa/self.hpp
cppa/serializer.hpp
cppa/stacked_event_based_actor.hpp
cppa/to_string.hpp
src/string_serialization.cpp
cppa/from_string.hpp
cppa/tpartial_function.hpp
cppa/tuple_cast.hpp
cppa/type_value_pair.hpp
cppa/uniform_type_info.hpp
cppa/util/abstract_uniform_type_info.hpp
cppa/util/apply_args.hpp
cppa/util/apply_tuple.hpp
cppa/util/arg_match_t.hpp
cppa/util/at.hpp
cppa/util/callable_trait.hpp
cppa/util/comparable.hpp
cppa/util/compare_tuples.hpp
cppa/util/conjunction.hpp
cppa/util/deduce_ref_type.hpp
cppa/util/disjunction.hpp
cppa/util/duration.hpp
cppa/util/element_at.hpp
cppa/util/fiber.hpp
cppa/util/fixed_vector.hpp
cppa/util/if_else.hpp
cppa/util/is_array_of.hpp
cppa/util/is_builtin.hpp
cppa/util/is_comparable.hpp
cppa/util/is_forward_iterator.hpp
cppa/util/is_iterable.hpp
cppa/util/is_legal_tuple_type.hpp
cppa/util/is_manipulator.hpp
cppa/util/is_mutable_ref.hpp
cppa/util/is_primitive.hpp
cppa/util/left_or_right.hpp
cppa/util/producer_consumer_list.hpp
cppa/util/projection.hpp
cppa/util/pt_dispatch.hpp
cppa/detail/get_behavior.hpp
unit_testing/test__ripemd_160.cpp
cppa/process_information.hpp
src/process_information.cpp
cppa/util/pt_token.hpp
cppa/util/purge_refs.hpp
cppa/util/replace_type.hpp
cppa/util/ripemd_160.hpp
src/ripemd_160.cpp
src/unicast_network.cpp
unit_testing/test__remote_actor.cpp
unit_testing/ping_pong.hpp
unit_testing/ping_pong.cpp
cppa/exception.hpp
src/exception.cpp
cppa/actor_proxy.hpp
src/actor_proxy.cpp
cppa/detail/actor_proxy_cache.hpp
src/actor_proxy_cache.cpp
src/attachable.cpp
cppa/attachable.hpp
cppa/atom.hpp
cppa/detail/atom_val.hpp
src/atom.cpp
src/cppa.cpp
cppa/exit_reason.hpp
cppa/abstract_actor.hpp
cppa/detail/mailman.hpp
src/mailman.cpp
cppa/detail/native_socket.hpp
src/native_socket.cpp
cppa/detail/post_office.hpp
src/post_office.cpp
cppa/detail/buffer.hpp
cppa/detail/actor_count.hpp
src/actor_count.cpp
cppa/util/fiber.hpp
src/fiber.cpp
cppa/detail/yield_interface.hpp
src/yield_interface.cpp
cppa/detail/abstract_scheduled_actor.hpp
src/scheduled_actor_dummy.cpp
src/invokable.cpp
cppa/detail/thread_pool_scheduler.hpp
src/thread_pool_scheduler.cpp
cppa/detail/receive_loop_helper.hpp
cppa/util/rm_option.hpp
cppa/util/rm_ref.hpp
cppa/util/shared_lock_guard.hpp
cppa/util/shared_spinlock.hpp
cppa/util/static_foreach.hpp
cppa/util/tbind.hpp
cppa/util/type_list.hpp
cppa/util/type_pair.hpp
cppa/util/upgrade_lock_guard.hpp
cppa/util/void_type.hpp
cppa/util/wrapped.hpp
cppa/detail/boxed.hpp
cppa/detail/unboxed.hpp
src/abstract_tuple.cpp
cppa/util/duration.hpp
src/duration.cpp
cppa/receive.hpp
cppa/detail/thread.hpp
cppa/detail/singleton_manager.hpp
src/singleton_manager.cpp
cppa/detail/actor_registry.hpp
src/actor_registry.cpp
cppa/detail/uniform_type_info_map.hpp
cppa/detail/network_manager.hpp
src/network_manager.cpp
cppa/detail/group_manager.hpp
src/group_manager.cpp
cppa/detail/empty_tuple.hpp
src/empty_tuple.cpp
cppa/detail/addressed_message.hpp
src/addressed_message.cpp
unit_testing/test__yield_interface.cpp
cppa/anything.hpp
cppa/pattern.hpp
unit_testing/test__pattern.cpp
cppa/util/fixed_vector.hpp
cppa/detail/implicit_conversions.hpp
cppa/util/is_array_of.hpp
examples/announce_example_1.cpp
examples/announce_example_2.cpp
examples/announce_example_3.cpp
examples/announce_example_4.cpp
examples/announce_example_5.cpp
examples/dancing_kirby.cpp
examples/dining_philosophers.cpp
examples/hello_world_example.cpp
examples/math_actor_example.cpp
cppa/detail/yielding_actor.hpp
src/yielding_actor.cpp
cppa/either.hpp
cppa/abstract_event_based_actor.hpp
queue_performances/blocking_cached_stack.hpp
queue_performances/blocking_cached_stack2.hpp
queue_performances/blocking_sutter_list.hpp
queue_performances/cached_stack.hpp
queue_performances/defines.hpp
queue_performances/intrusive_sutter_list.hpp
queue_performances/lockfree_list.hpp
queue_performances/main.cpp
queue_performances/sutter_list.hpp
src/abstract_event_based_actor.cpp
cppa/event_based_actor.hpp
src/abstract_tuple.cpp
src/actor.cpp
src/actor_count.cpp
src/actor_proxy.cpp
src/actor_proxy_cache.cpp
src/actor_registry.cpp
src/addressed_message.cpp
src/any_tuple.cpp
src/atom.cpp
src/attachable.cpp
src/binary_deserializer.cpp
src/binary_serializer.cpp
src/channel.cpp
src/converted_thread_context.cpp
src/cppa.cpp
src/demangle.cpp
src/deserializer.cpp
src/duration.cpp
src/empty_tuple.cpp
src/event_based_actor.cpp
cppa/stacked_event_based_actor.hpp
src/stacked_event_based_actor.cpp
cppa/event_based_actor_base.hpp
cppa/fsm_actor.hpp
cppa/self.hpp
src/self.cpp
cppa/behavior.hpp
src/exception.cpp
src/fiber.cpp
src/group.cpp
src/group_manager.cpp
src/invokable.cpp
src/local_actor.cpp
src/mailman.cpp
src/mock_scheduler.cpp
src/native_socket.cpp
src/network_manager.cpp
src/object.cpp
src/object_array.cpp
src/partial_function.cpp
src/pattern.cpp
src/post_office.cpp
src/primitive_variant.cpp
src/process_information.cpp
src/receive.cpp
benchmarks/actor_creation.cpp
benchmarks/mailbox_performance.cpp
benchmarks/mixed_case.cpp
benchmarks/actor_creation.erl
benchmarks/mailbox_performance.erl
benchmarks/mixed_case.erl
benchmarks/ActorCreation.scala
benchmarks/MailboxPerformance.scala
benchmarks/MixedCase.scala
cppa/util/producer_consumer_list.hpp
cppa/util/arg_match_t.hpp
cppa/detail/types_array.hpp
cppa/util/is_builtin.hpp
cppa/util/type_pair.hpp
cppa/util/tbind.hpp
cppa/option.hpp
cppa/tuple_cast.hpp
cppa/util/is_mutable_ref.hpp
cppa/util/is_manipulator.hpp
cppa/util/apply_tuple.hpp
benchmarks/Matching.scala
benchmarks/matching.cpp
benchmarks/matching.erl
benchmarks/theron_mailbox_performance.cpp
benchmarks/utility.hpp
benchmarks/theron_actor_creation.cpp
benchmarks/theron_mixed_case.cpp
cppa/util/static_foreach.hpp
cppa/type_value_pair.hpp
examples/dining_philosophers.cpp
cppa/detail/disablable_delete.hpp
src/ripemd_160.cpp
src/scheduled_actor.cpp
src/scheduled_actor_dummy.cpp
src/scheduler.cpp
src/self.cpp
src/serializer.cpp
src/shared_spinlock.cpp
src/singleton_manager.cpp
src/stacked_event_based_actor.cpp
src/string_serialization.cpp
src/thread_pool_scheduler.cpp
src/to_uniform_name.cpp
src/unicast_network.cpp
src/uniform_type_info.cpp
src/yield_interface.cpp
src/yielding_actor.cpp
unit_testing/main.cpp
unit_testing/ping_pong.cpp
unit_testing/ping_pong.hpp
unit_testing/test.hpp
unit_testing/test__atom.cpp
unit_testing/test__fixed_vector.cpp
cppa/detail/tuple_cast_impl.hpp
cppa/match.hpp
cppa/partial_function.hpp
src/partial_function.cpp
cppa/intrusive/singly_linked_list.hpp
cppa/intrusive/forward_iterator.hpp
unit_testing/test__intrusive_containers.cpp
examples/dancing_kirby.cpp
cppa/util/is_comparable.hpp
cppa/detail/tuple_view.hpp
cppa/detail/container_tuple_view.hpp
cppa/detail/matches.hpp
unit_testing/test__intrusive_ptr.cpp
unit_testing/test__local_group.cpp
unit_testing/test__match.cpp
cppa/guard_expr.hpp
src/pattern.cpp
cppa/util/left_or_right.hpp
cppa/util/apply_args.hpp
cppa/tpartial_function.hpp
cppa/util/rm_option.hpp
cppa/util/projection.hpp
cppa/util/purge_refs.hpp
cppa/util/deduce_ref_type.hpp
cppa/detail/projection.hpp
cppa/detail/value_guard.hpp
cppa/detail/tuple_iterator.hpp
cppa/match_expr.hpp
cppa/detail/pseudo_tuple.hpp
cppa/detail/recursive_queue_node.hpp
cppa/detail/scheduled_actor_dummy.hpp
cppa/detail/nestable_receive_actor.hpp
cppa/detail/filter_result.hpp
benchmarks/PingPong.scala
benchmarks/distributed.cpp
unit_testing/test__pattern.cpp
unit_testing/test__primitive_variant.cpp
unit_testing/test__remote_actor.cpp
unit_testing/test__ripemd_160.cpp
unit_testing/test__serialization.cpp
unit_testing/test__spawn.cpp
unit_testing/test__tuple.cpp
unit_testing/test__type_list.cpp
unit_testing/test__uniform_type.cpp
unit_testing/test__yield_interface.cpp
......@@ -31,29 +31,36 @@
#include "cppa/cppa.hpp"
#include "cppa/local_actor.hpp"
namespace cppa {
namespace {
class observer : public cppa::attachable
class down_observer : public attachable
{
cppa::actor_ptr m_client;
actor_ptr m_observer;
actor_ptr m_observed;
public:
observer(cppa::actor_ptr&& client) : m_client(std::move(client)) { }
down_observer(actor_ptr observer, actor_ptr observed)
: m_observer(std::move(observer))
, m_observed(std::move(observed))
{
}
void actor_exited(std::uint32_t reason)
{
using namespace cppa;
send(m_client, atom("DOWN"), actor_ptr(self), reason);
send(m_observer, atom("DOWN"), m_observed, reason);
}
bool matches(const cppa::attachable::token& match_token)
bool matches(const attachable::token& match_token)
{
if (match_token.subtype == typeid(observer))
if (match_token.subtype == typeid(down_observer))
{
auto ptr = reinterpret_cast<const cppa::local_actor*>(match_token.ptr);
return m_client == ptr;
auto ptr = reinterpret_cast<const local_actor*>(match_token.ptr);
return m_observer == ptr;
}
return false;
}
......@@ -62,8 +69,6 @@ class observer : public cppa::attachable
} // namespace <anonymous>
namespace cppa {
const self_type& operator<<(const self_type& s, const any_tuple& what)
{
local_actor* sptr = s;
......@@ -120,7 +125,7 @@ void unlink(actor_ptr& lhs, actor_ptr& rhs)
void monitor(actor_ptr& whom)
{
if (whom) whom->attach(new observer(actor_ptr(self)));
if (whom) whom->attach(new down_observer(self, whom));
}
void monitor(actor_ptr&& whom)
......@@ -131,7 +136,7 @@ void monitor(actor_ptr&& whom)
void demonitor(actor_ptr& whom)
{
attachable::token mtoken(typeid(observer), self);
attachable::token mtoken(typeid(down_observer), self);
if (whom) whom->detach(mtoken);
}
......
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