Commit 8d1b0361 authored by Dominik Charousset's avatar Dominik Charousset

replaced 'EXIT' and 'DOWN' messages w/ msg types

parent d2afafff
...@@ -140,7 +140,6 @@ cppa/response_promise.hpp ...@@ -140,7 +140,6 @@ cppa/response_promise.hpp
cppa/sb_actor.hpp cppa/sb_actor.hpp
cppa/scheduler.hpp cppa/scheduler.hpp
cppa/scoped_actor.hpp cppa/scoped_actor.hpp
cppa/send.hpp
cppa/serializer.hpp cppa/serializer.hpp
cppa/singletons.hpp cppa/singletons.hpp
cppa/spawn.hpp cppa/spawn.hpp
...@@ -279,7 +278,6 @@ src/response_promise.cpp ...@@ -279,7 +278,6 @@ src/response_promise.cpp
src/ripemd_160.cpp src/ripemd_160.cpp
src/scheduler.cpp src/scheduler.cpp
src/scoped_actor.cpp src/scoped_actor.cpp
src/send.cpp
src/serializer.cpp src/serializer.cpp
src/shared_spinlock.cpp src/shared_spinlock.cpp
src/singleton_manager.cpp src/singleton_manager.cpp
...@@ -339,3 +337,4 @@ src/functor_based_blocking_actor.cpp ...@@ -339,3 +337,4 @@ src/functor_based_blocking_actor.cpp
src/blocking_untyped_actor.cpp src/blocking_untyped_actor.cpp
cppa/policy/policies.hpp cppa/policy/policies.hpp
cppa/detail/response_future_util.hpp cppa/detail/response_future_util.hpp
cppa/system_messages.hpp
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#define CPPA_BEHAVIOR_STACK_BASED_HPP #define CPPA_BEHAVIOR_STACK_BASED_HPP
#include "cppa/message_id.hpp" #include "cppa/message_id.hpp"
#include "cppa/system_messages.hpp"
#include "cppa/detail/behavior_stack.hpp" #include "cppa/detail/behavior_stack.hpp"
...@@ -163,7 +164,7 @@ class behavior_stack_based : public Base { ...@@ -163,7 +164,7 @@ class behavior_stack_based : public Base {
if (d.valid()) { if (d.valid()) {
m_has_timeout = true; m_has_timeout = true;
auto tid = ++m_timeout_id; auto tid = ++m_timeout_id;
auto msg = make_any_tuple(atom("SYNC_TOUT"), tid); auto msg = make_any_tuple(timeout_msg{tid});
if (d.is_zero()) { if (d.is_zero()) {
// immediately enqueue timeout message if duration == 0s // immediately enqueue timeout message if duration == 0s
this->enqueue({this->address(), this}, std::move(msg)); this->enqueue({this->address(), this}, std::move(msg));
......
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
#include "cppa/spawn_options.hpp" #include "cppa/spawn_options.hpp"
#include "cppa/untyped_actor.hpp" #include "cppa/untyped_actor.hpp"
#include "cppa/abstract_actor.hpp" #include "cppa/abstract_actor.hpp"
#include "cppa/system_messages.hpp"
#include "cppa/response_promise.hpp" #include "cppa/response_promise.hpp"
#include "cppa/blocking_untyped_actor.hpp" #include "cppa/blocking_untyped_actor.hpp"
......
...@@ -298,7 +298,7 @@ class proper_actor<Base, Policies,true> : public proper_actor_base<Base, ...@@ -298,7 +298,7 @@ class proper_actor<Base, Policies,true> : public proper_actor_base<Base,
std::uint32_t request_timeout(const util::duration& d) { std::uint32_t request_timeout(const util::duration& d) {
CPPA_REQUIRE(d.valid()); CPPA_REQUIRE(d.valid());
auto tid = ++m_next_timeout_id; auto tid = ++m_next_timeout_id;
auto msg = make_any_tuple(atom("SYNC_TOUT"), tid); auto msg = make_any_tuple(timeout_msg{tid});
if (d.is_zero()) { if (d.is_zero()) {
// immediately enqueue timeout message if duration == 0s // immediately enqueue timeout message if duration == 0s
this->enqueue({this->address(), this}, std::move(msg)); this->enqueue({this->address(), this}, std::move(msg));
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "cppa/on.hpp" #include "cppa/on.hpp"
#include "cppa/match_hint.hpp" #include "cppa/match_hint.hpp"
#include "cppa/system_messages.hpp"
#include "cppa/util/type_traits.hpp" #include "cppa/util/type_traits.hpp"
...@@ -46,7 +47,7 @@ behavior fs2bhvr(Actor* self, Fs... fs) { ...@@ -46,7 +47,7 @@ behavior fs2bhvr(Actor* self, Fs... fs) {
return match_hint::skip; return match_hint::skip;
}; };
return behavior{ return behavior{
on(atom("TIMEOUT")) >> handle_sync_timeout, on<sync_timeout_msg>() >> handle_sync_timeout,
on(atom("VOID")) >> skip_message, on(atom("VOID")) >> skip_message,
on(atom("EXITED")) >> skip_message, on(atom("EXITED")) >> skip_message,
(on(any_vals, arg_match) >> std::move(fs))... (on(any_vals, arg_match) >> std::move(fs))...
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "cppa/unit.hpp" #include "cppa/unit.hpp"
#include "cppa/none.hpp" #include "cppa/none.hpp"
#include "cppa/node_id.hpp" #include "cppa/node_id.hpp"
#include "cppa/system_messages.hpp"
#include "cppa/util/buffer.hpp" #include "cppa/util/buffer.hpp"
#include "cppa/util/duration.hpp" #include "cppa/util/duration.hpp"
...@@ -65,11 +66,15 @@ using mapped_type_list = util::type_list< ...@@ -65,11 +66,15 @@ using mapped_type_list = util::type_list<
any_tuple, any_tuple,
atom_value, atom_value,
channel, channel,
down_msg,
exit_msg,
group_ptr, group_ptr,
node_id_ptr, node_id_ptr,
io::accept_handle, io::accept_handle,
io::connection_handle, io::connection_handle,
message_header, message_header,
sync_timeout_msg,
timeout_msg,
unit_t, unit_t,
util::buffer, util::buffer,
util::duration, util::duration,
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "cppa/message_id.hpp" #include "cppa/message_id.hpp"
#include "cppa/exit_reason.hpp" #include "cppa/exit_reason.hpp"
#include "cppa/mailbox_element.hpp" #include "cppa/mailbox_element.hpp"
#include "cppa/system_messages.hpp"
#include "cppa/partial_function.hpp" #include "cppa/partial_function.hpp"
#include "cppa/response_promise.hpp" #include "cppa/response_promise.hpp"
...@@ -152,34 +153,32 @@ class invoke_policy { ...@@ -152,34 +153,32 @@ class invoke_policy {
filter_result filter_msg(Actor* self, mailbox_element* node) { filter_result filter_msg(Actor* self, mailbox_element* node) {
const any_tuple& msg = node->msg; const any_tuple& msg = node->msg;
auto mid = node->mid; auto mid = node->mid;
auto& arr = detail::static_types_array<atom_value, std::uint32_t>::arr; auto& arr = detail::static_types_array<exit_msg,
if ( msg.size() == 2 timeout_msg,
&& msg.type_at(0) == arr[0] sync_timeout_msg>::arr;
&& msg.type_at(1) == arr[1]) { if (msg.size() == 1) {
auto v0 = msg.get_as<atom_value>(0); if (msg.type_at(0) == arr[0]) {
auto v1 = msg.get_as<std::uint32_t>(1); auto& em = msg.get_as<exit_msg>(0);
if (v0 == atom("EXIT")) {
CPPA_REQUIRE(!mid.valid()); CPPA_REQUIRE(!mid.valid());
if (self->trap_exit() == false) { if (self->trap_exit() == false) {
if (v1 != exit_reason::normal) { if (em.reason != exit_reason::normal) {
self->quit(v1); self->quit(em.reason);
return non_normal_exit_signal; return non_normal_exit_signal;
} }
return normal_exit_signal; return normal_exit_signal;
} }
} }
else if (v0 == atom("SYNC_TOUT")) { else if (msg.type_at(0) == arr[1]) {
auto& tm = msg.get_as<timeout_msg>(0);
auto tid = tm.timeout_id;
CPPA_REQUIRE(!mid.valid()); CPPA_REQUIRE(!mid.valid());
if (self->is_active_timeout(v1)) return timeout_message; if (self->is_active_timeout(tid)) return timeout_message;
return self->waits_for_timeout(v1) ? inactive_timeout_message return self->waits_for_timeout(tid) ? inactive_timeout_message
: expired_timeout_message; : expired_timeout_message;
}
else if (msg.type_at(0) == arr[2] && mid.is_response()) {
return timeout_response_message;
} }
}
else if ( msg.size() == 1
&& msg.type_at(0) == arr[0]
&& msg.get_as<atom_value>(0) == atom("TIMEOUT")
&& mid.is_response()) {
return timeout_response_message;
} }
if (mid.is_response()) { if (mid.is_response()) {
return (self->awaits(mid)) ? sync_response return (self->awaits(mid)) ? sync_response
...@@ -322,8 +321,8 @@ class invoke_policy { ...@@ -322,8 +321,8 @@ class invoke_policy {
} }
case timeout_message: { case timeout_message: {
CPPA_LOG_DEBUG("handle timeout message"); CPPA_LOG_DEBUG("handle timeout message");
auto tid = node->msg.get_as<std::uint32_t>(1); auto& tm = node->msg.get_as<timeout_msg>(0);
self->handle_timeout(fun, tid); self->handle_timeout(fun, tm.timeout_id);
if (awaited_response.valid()) { if (awaited_response.valid()) {
self->mark_arrived(awaited_response); self->mark_arrived(awaited_response);
self->remove_handler(awaited_response); self->remove_handler(awaited_response);
......
This diff is collapsed.
...@@ -28,52 +28,65 @@ ...@@ -28,52 +28,65 @@
\******************************************************************************/ \******************************************************************************/
#include "cppa/scheduler.hpp" #ifndef CPPA_SYSTEM_MESSAGES_HPP
#include "cppa/singletons.hpp" #define CPPA_SYSTEM_MESSAGES_HPP
namespace cppa { #include <cstdint>
#include "cppa/actor_addr.hpp"
response_future sync_send_tuple(actor_destination dest, any_tuple what) { namespace cppa {
if (!dest.receiver) throw std::invalid_argument("whom == nullptr");
auto req = self->new_request_id();
message_header hdr{self, std::move(dest.receiver), req, dest.priority};
if (self->chaining_enabled()) {
if (hdr.receiver->chained_enqueue(hdr, std::move(what))) {
self->chained_actor(hdr.receiver.downcast<actor>());
}
}
else hdr.deliver(std::move(what));
return req.response_id();
}
void delayed_send_tuple(channel_destination dest, /**
const util::duration& rtime, * @brief Sent to all links when an actor is terminated.
any_tuple data) { * @note This message can be handled manually by calling
if (dest.receiver) { * {@link local_actor::trap_exit(true) local_actor::trap_exit(bool)}
message_header hdr{self, std::move(dest.receiver), dest.priority}; * and is otherwise handled implicitly by the runtime system.
get_scheduler()->delayed_send(std::move(hdr), rtime, std::move(data)); */
} struct exit_msg {
} /**
* @brief The source of this message, i.e., the terminated actor.
*/
actor_addr source;
/**
* @brief The exit reason of the terminated actor.
*/
std::uint32_t reason;
};
response_future timed_sync_send_tuple(actor_destination dest, /**
const util::duration& rtime, * @brief Sent to all actors monitoring an actor when it is terminated.
any_tuple what) { */
auto mf = sync_send_tuple(std::move(dest), std::move(what)); struct down_msg {
message_header hdr{self, self, mf.id()}; /**
auto tmp = make_any_tuple(atom("TIMEOUT")); * @brief The source of this message, i.e., the terminated actor.
get_scheduler()->delayed_send(std::move(hdr), rtime, std::move(tmp)); */
return mf; actor_addr source;
} /**
* @brief The exit reason of the terminated actor.
*/
std::uint32_t reason;
};
void delayed_reply_tuple(const util::duration& rtime, /**
message_id mid, * @brief Sent whenever a timeout occurs during a synchronous send.
any_tuple data) { *
message_header hdr{self, self->last_sender(), mid}; * This system message does not have any fields, because the message ID
get_scheduler()->delayed_send(std::move(hdr), rtime, std::move(data)); * sent alongside this message identifies the matching request that timed out.
} */
struct sync_timeout_msg { };
void delayed_reply_tuple(const util::duration& rel_time, any_tuple data) { /**
delayed_reply_tuple(rel_time, self->get_response_id(), std::move(data)); * @brief Signalizes a timeout event.
} * @note This message is handled implicitly by the runtime system.
*/
struct timeout_msg {
/**
* @brief Actor-specific timeout ID.
*/
std::uint32_t timeout_id;
};
} // namespace cppa } // namespace cppa
#endif // CPPA_SYSTEM_MESSAGES_HPP
...@@ -83,7 +83,7 @@ void client_bhvr(untyped_actor* self, const string& host, uint16_t port, const a ...@@ -83,7 +83,7 @@ void client_bhvr(untyped_actor* self, const string& host, uint16_t port, const a
} }
); );
}, },
on(atom("DOWN"), arg_match) >> [=](uint32_t) { on_arg_match >> [=](const down_msg&) {
aout << "*** server down, try to reconnect ..." << endl; aout << "*** server down, try to reconnect ..." << endl;
client_bhvr(self, host, port, nullptr); client_bhvr(self, host, port, nullptr);
}, },
......
...@@ -104,8 +104,8 @@ void protobuf_io(broker* thisptr, connection_handle hdl, const actor_ptr& buddy) ...@@ -104,8 +104,8 @@ void protobuf_io(broker* thisptr, connection_handle hdl, const actor_ptr& buddy)
p.mutable_pong()->set_id(i); p.mutable_pong()->set_id(i);
write(p); write(p);
}, },
on(atom("DOWN"), arg_match) >> [=](uint32_t rsn) { on_arg_match >> [=](const down_msg& dm) {
if (self->last_sender() == buddy) self->quit(rsn); if (dm.source == buddy) self->quit(dm.reason);
}, },
others() >> [=] { others() >> [=] {
cout << "unexpected: " << to_string(self->last_dequeued()) << endl; cout << "unexpected: " << to_string(self->last_dequeued()) << endl;
......
No preview for this file type
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "cppa/actor_addr.hpp" #include "cppa/actor_addr.hpp"
#include "cppa/abstract_actor.hpp" #include "cppa/abstract_actor.hpp"
#include "cppa/message_header.hpp" #include "cppa/message_header.hpp"
#include "cppa/system_messages.hpp"
#include "cppa/util/shared_spinlock.hpp" #include "cppa/util/shared_spinlock.hpp"
#include "cppa/util/shared_lock_guard.hpp" #include "cppa/util/shared_lock_guard.hpp"
...@@ -71,7 +72,8 @@ bool abstract_actor::link_to_impl(const actor_addr& other) { ...@@ -71,7 +72,8 @@ bool abstract_actor::link_to_impl(const actor_addr& other) {
auto ptr = detail::actor_addr_cast<abstract_actor>(other); auto ptr = detail::actor_addr_cast<abstract_actor>(other);
// send exit message if already exited // send exit message if already exited
if (exited()) { if (exited()) {
ptr->enqueue({address(), ptr}, make_any_tuple(atom("EXIT"), exit_reason())); ptr->enqueue({address(), ptr},
make_any_tuple(exit_msg{address(), exit_reason()}));
} }
// add link if not already linked to other // add link if not already linked to other
// (checked by establish_backlink) // (checked by establish_backlink)
...@@ -152,7 +154,9 @@ bool abstract_actor::establish_backlink(const actor_addr& other) { ...@@ -152,7 +154,9 @@ bool abstract_actor::establish_backlink(const actor_addr& other) {
} }
// send exit message without lock // send exit message without lock
if (reason != exit_reason::not_exited) { if (reason != exit_reason::not_exited) {
//send_as(this, other, make_any_tuple(atom("EXIT"), reason)); auto ptr = detail::raw_access::unsafe_cast(other);
ptr.enqueue({address(), ptr},
make_any_tuple(exit_msg{address(), exit_reason()}));
} }
return false; return false;
} }
...@@ -202,7 +206,7 @@ void abstract_actor::cleanup(std::uint32_t reason) { ...@@ -202,7 +206,7 @@ void abstract_actor::cleanup(std::uint32_t reason) {
<< " attached functors; exit reason = " << reason << " attached functors; exit reason = " << reason
<< ", class = " << detail::demangle(typeid(*this))); << ", class = " << detail::demangle(typeid(*this)));
// send exit messages // send exit messages
auto msg = make_any_tuple(atom("EXIT"), reason); auto msg = make_any_tuple(exit_msg{address(), reason});
CPPA_LOGM_DEBUG("cppa::actor", "send EXIT to " << mlinks.size() << " links"); CPPA_LOGM_DEBUG("cppa::actor", "send EXIT to " << mlinks.size() << " links");
for (auto& aptr : mlinks) { for (auto& aptr : mlinks) {
aptr->enqueue({address(), aptr, message_id{}.with_high_priority()}, msg); aptr->enqueue({address(), aptr, message_id{}.with_high_priority()}, msg);
......
...@@ -163,7 +163,7 @@ class local_broker : public untyped_actor { ...@@ -163,7 +163,7 @@ class local_broker : public untyped_actor {
// forward to all acquaintances // forward to all acquaintances
send_to_acquaintances(what); send_to_acquaintances(what);
}, },
on(atom("DOWN"), arg_match) >> [=](uint32_t) { on_arg_match >> [=](const down_msg&) {
auto sender = last_sender(); auto sender = last_sender();
CPPA_LOGC_TRACE("cppa::local_broker", "init$DOWN", CPPA_LOGC_TRACE("cppa::local_broker", "init$DOWN",
CPPA_TARG(sender, to_string)); CPPA_TARG(sender, to_string));
...@@ -519,13 +519,13 @@ class remote_group_module : public group::module { ...@@ -519,13 +519,13 @@ class remote_group_module : public group::module {
sm->put(key, nullptr); sm->put(key, nullptr);
} }
}, },
on(atom("TIMEOUT")) >> [sm, &key] { on<sync_timeout_msg>() >> [sm, &key] {
sm->put(key, nullptr); sm->put(key, nullptr);
} }
); );
} }
}, },
on<atom("DOWN"), std::uint32_t>() >> [&] { on_arg_match >> [&](const down_msg&) {
auto who = self->last_sender(); auto who = self->last_sender();
auto find_peer = [&] { auto find_peer = [&] {
return find_if(begin(*peers), end(*peers), [&](const peer_map::value_type& kvp) { return find_if(begin(*peers), end(*peers), [&](const peer_map::value_type& kvp) {
......
...@@ -58,7 +58,7 @@ class down_observer : public attachable { ...@@ -58,7 +58,7 @@ class down_observer : public attachable {
if (m_observer) { if (m_observer) {
auto ptr = detail::actor_addr_cast<abstract_actor>(m_observer); auto ptr = detail::actor_addr_cast<abstract_actor>(m_observer);
message_header hdr{m_observed, ptr, message_id{}.with_high_priority()}; message_header hdr{m_observed, ptr, message_id{}.with_high_priority()};
hdr.deliver(make_any_tuple(atom("DOWN"), reason)); hdr.deliver(make_any_tuple(down_msg{m_observed, reason}));
} }
} }
...@@ -154,7 +154,7 @@ void local_actor::send_tuple(const channel& dest, any_tuple what) { ...@@ -154,7 +154,7 @@ void local_actor::send_tuple(const channel& dest, any_tuple what) {
} }
void local_actor::send_exit(const actor_addr& whom, std::uint32_t reason) { void local_actor::send_exit(const actor_addr& whom, std::uint32_t reason) {
send(detail::raw_access::get(whom), atom("EXIT"), reason); send(detail::raw_access::get(whom), exit_msg{address(), reason});
} }
void local_actor::delayed_send_tuple(const channel& dest, void local_actor::delayed_send_tuple(const channel& dest,
...@@ -203,7 +203,7 @@ message_id local_actor::timed_sync_send_tuple_impl(message_priority mp, ...@@ -203,7 +203,7 @@ message_id local_actor::timed_sync_send_tuple_impl(message_priority mp,
dest.enqueue({address(), dest, nri}, std::move(what)); dest.enqueue({address(), dest, nri}, std::move(what));
auto rri = nri.response_id(); auto rri = nri.response_id();
get_scheduler()->delayed_send({address(), this, rri}, rtime, get_scheduler()->delayed_send({address(), this, rri}, rtime,
make_any_tuple(atom("TIMEOUT"))); make_any_tuple(sync_timeout_msg{}));
return rri; return rri;
} }
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "cppa/scheduler.hpp" #include "cppa/scheduler.hpp"
#include "cppa/local_actor.hpp" #include "cppa/local_actor.hpp"
#include "cppa/scoped_actor.hpp" #include "cppa/scoped_actor.hpp"
#include "cppa/system_messages.hpp"
#include "cppa/detail/proper_actor.hpp" #include "cppa/detail/proper_actor.hpp"
#include "cppa/detail/actor_registry.hpp" #include "cppa/detail/actor_registry.hpp"
...@@ -241,7 +242,7 @@ void scheduler_helper::printer_loop(blocking_untyped_actor* self) { ...@@ -241,7 +242,7 @@ void scheduler_helper::printer_loop(blocking_untyped_actor* self) {
on(atom("flush")) >> [&] { on(atom("flush")) >> [&] {
flush_output(self->last_sender()); flush_output(self->last_sender());
}, },
on(atom("DOWN"), any_vals) >> [&] { on_arg_match >> [&](const down_msg&) {
auto s = self->last_sender(); auto s = self->last_sender();
flush_output(s); flush_output(s);
out.erase(s); out.erase(s);
......
This diff is collapsed.
...@@ -71,8 +71,8 @@ void pong(cppa::untyped_actor* self) { ...@@ -71,8 +71,8 @@ void pong(cppa::untyped_actor* self) {
on(atom("ping"), arg_match) >> [](int value) { on(atom("ping"), arg_match) >> [](int value) {
return make_cow_tuple(atom("pong"), value); return make_cow_tuple(atom("pong"), value);
}, },
on(atom("DOWN"), arg_match) >> [=](uint32_t reason) { on_arg_match >> [=](const down_msg& dm) {
self->quit(reason); self->quit(dm.reason);
}, },
others() >> CPPA_UNEXPECTED_MSG_CB() others() >> CPPA_UNEXPECTED_MSG_CB()
); );
...@@ -113,8 +113,8 @@ void peer(io::broker* self, io::connection_handle hdl, const actor& buddy) { ...@@ -113,8 +113,8 @@ void peer(io::broker* self, io::connection_handle hdl, const actor& buddy) {
on(atom("pong"), arg_match) >> [=](int value) { on(atom("pong"), arg_match) >> [=](int value) {
write(atom("pong"), value); write(atom("pong"), value);
}, },
on(atom("DOWN"), arg_match) >> [=](uint32_t reason) { on_arg_match >> [=](const down_msg& dm) {
if (self->last_sender() == buddy) self->quit(reason); if (dm.source == buddy) self->quit(dm.reason);
}, },
others() >> CPPA_UNEXPECTED_MSG_CB() others() >> CPPA_UNEXPECTED_MSG_CB()
); );
......
...@@ -69,8 +69,8 @@ void spawn5_server_impl(untyped_actor* self, actor client, group_ptr grp) { ...@@ -69,8 +69,8 @@ void spawn5_server_impl(untyped_actor* self, actor client, group_ptr grp) {
CPPA_PRINT("wait for DOWN messages"); CPPA_PRINT("wait for DOWN messages");
auto downs = std::make_shared<int>(0); auto downs = std::make_shared<int>(0);
self->become ( self->become (
on(atom("DOWN"), arg_match) >> [=](std::uint32_t reason) { on_arg_match >> [=](const down_msg& dm) {
if (reason != exit_reason::normal) { if (dm.reason != exit_reason::normal) {
CPPA_PRINTERR("reflector exited for non-normal exit reason!"); CPPA_PRINTERR("reflector exited for non-normal exit reason!");
} }
if (++*downs == 5) { if (++*downs == 5) {
...@@ -141,8 +141,8 @@ void spawn5_client(untyped_actor* self) { ...@@ -141,8 +141,8 @@ void spawn5_client(untyped_actor* self) {
template<typename F> template<typename F>
void await_down(untyped_actor* self, actor ptr, F continuation) { void await_down(untyped_actor* self, actor ptr, F continuation) {
self->become ( self->become (
on(atom("DOWN"), arg_match) >> [=](uint32_t) -> bool { on_arg_match >> [=](const down_msg& dm) -> bool {
if (self->last_sender() == ptr) { if (dm.source == ptr) {
continuation(); continuation();
return true; return true;
} }
...@@ -351,9 +351,9 @@ int main(int argc, char** argv) { ...@@ -351,9 +351,9 @@ int main(int argc, char** argv) {
} }
auto c = self->spawn<client, monitored>(serv); auto c = self->spawn<client, monitored>(serv);
self->receive ( self->receive (
on(atom("DOWN"), arg_match) >> [&](uint32_t rsn) { on_arg_match >> [&](const down_msg& dm) {
CPPA_CHECK_EQUAL(self->last_sender(), c); CPPA_CHECK_EQUAL(dm.source, c);
CPPA_CHECK_EQUAL(rsn, exit_reason::normal); CPPA_CHECK_EQUAL(dm.reason, exit_reason::normal);
} }
); );
}); });
...@@ -397,9 +397,9 @@ int main(int argc, char** argv) { ...@@ -397,9 +397,9 @@ int main(int argc, char** argv) {
else { CPPA_PRINT("actor published at port " << port); } else { CPPA_PRINT("actor published at port " << port); }
CPPA_CHECKPOINT(); CPPA_CHECKPOINT();
self->receive ( self->receive (
on(atom("DOWN"), arg_match) >> [&](uint32_t rsn) { on_arg_match >> [&](const down_msg& dm) {
CPPA_CHECK_EQUAL(self->last_sender(), serv); CPPA_CHECK_EQUAL(dm.source, serv);
CPPA_CHECK_EQUAL(rsn, exit_reason::normal); CPPA_CHECK_EQUAL(dm.reason, exit_reason::normal);
} }
); );
// wait until separate process (in sep. thread) finished execution // wait until separate process (in sep. thread) finished execution
......
...@@ -529,7 +529,12 @@ void test_spawn() { ...@@ -529,7 +529,12 @@ void test_spawn() {
); );
self->send_exit(mirror, exit_reason::user_shutdown); self->send_exit(mirror, exit_reason::user_shutdown);
self->receive ( self->receive (
on(atom("DOWN"), exit_reason::user_shutdown) >> CPPA_CHECKPOINT_CB(), on_arg_match >> [&](const down_msg& dm) {
if (dm.reason == exit_reason::user_shutdown) {
CPPA_CHECKPOINT();
}
else { CPPA_UNEXPECTED_MSG(); }
},
others() >> CPPA_UNEXPECTED_MSG_CB() others() >> CPPA_UNEXPECTED_MSG_CB()
); );
self->await_all_other_actors_done(); self->await_all_other_actors_done();
...@@ -545,7 +550,12 @@ void test_spawn() { ...@@ -545,7 +550,12 @@ void test_spawn() {
); );
self->send_exit(mirror, exit_reason::user_shutdown); self->send_exit(mirror, exit_reason::user_shutdown);
self->receive ( self->receive (
on(atom("DOWN"), exit_reason::user_shutdown) >> CPPA_CHECKPOINT_CB(), on_arg_match >> [&](const down_msg& dm) {
if (dm.reason == exit_reason::user_shutdown) {
CPPA_CHECKPOINT();
}
else { CPPA_UNEXPECTED_MSG(); }
},
others() >> CPPA_UNEXPECTED_MSG_CB() others() >> CPPA_UNEXPECTED_MSG_CB()
); );
self->await_all_other_actors_done(); self->await_all_other_actors_done();
...@@ -562,7 +572,12 @@ void test_spawn() { ...@@ -562,7 +572,12 @@ void test_spawn() {
); );
self->send_exit(mirror, exit_reason::user_shutdown); self->send_exit(mirror, exit_reason::user_shutdown);
self->receive ( self->receive (
on(atom("DOWN"), exit_reason::user_shutdown) >> CPPA_CHECKPOINT_CB(), on_arg_match >> [&](const down_msg& dm) {
if (dm.reason == exit_reason::user_shutdown) {
CPPA_CHECKPOINT();
}
else { CPPA_UNEXPECTED_MSG(); }
},
others() >> CPPA_UNEXPECTED_MSG_CB() others() >> CPPA_UNEXPECTED_MSG_CB()
); );
self->await_all_other_actors_done(); self->await_all_other_actors_done();
...@@ -714,8 +729,9 @@ void test_spawn() { ...@@ -714,8 +729,9 @@ void test_spawn() {
after(std::chrono::seconds(5)) >> CPPA_UNEXPECTED_TOUT_CB() after(std::chrono::seconds(5)) >> CPPA_UNEXPECTED_TOUT_CB()
); );
self->receive ( self->receive (
on(atom("DOWN"), exit_reason::normal) >> [&] { on_arg_match >> [&](const down_msg& dm) {
CPPA_CHECK_EQUAL(self->last_sender(), sync_testee); CPPA_CHECK_EQUAL(dm.reason, exit_reason::normal);
CPPA_CHECK_EQUAL(dm.source, sync_testee);
} }
); );
self->await_all_other_actors_done(); self->await_all_other_actors_done();
...@@ -830,20 +846,19 @@ void test_spawn() { ...@@ -830,20 +846,19 @@ void test_spawn() {
self->delayed_send(self, chrono::seconds(1), atom("FooBar")); self->delayed_send(self, chrono::seconds(1), atom("FooBar"));
// wait for DOWN and EXIT messages of pong // wait for DOWN and EXIT messages of pong
self->receive_for(i, 4) ( self->receive_for(i, 4) (
on(atom("EXIT"), arg_match) >> [&](uint32_t reason) { on_arg_match >> [&](const exit_msg& em) {
CPPA_CHECK_EQUAL(exit_reason::user_shutdown, reason); CPPA_CHECK_EQUAL(em.source, pong_actor);
CPPA_CHECK(self->last_sender() == pong_actor); CPPA_CHECK_EQUAL(em.reason, exit_reason::user_shutdown);
flags |= 0x01; flags |= 0x01;
}, },
on(atom("DOWN"), arg_match) >> [&](uint32_t reason) { on_arg_match >> [&](const down_msg& dm) {
auto who = self->last_sender(); if (dm.source == pong_actor) {
if (who == pong_actor) {
flags |= 0x02; flags |= 0x02;
CPPA_CHECK_EQUAL(reason, exit_reason::user_shutdown); CPPA_CHECK_EQUAL(dm.reason, exit_reason::user_shutdown);
} }
else if (who == ping_actor) { else if (dm.source == ping_actor) {
flags |= 0x04; flags |= 0x04;
CPPA_CHECK_EQUAL(reason, exit_reason::normal); CPPA_CHECK_EQUAL(dm.reason, exit_reason::normal);
} }
}, },
on_arg_match >> [&](const atom_value& val) { on_arg_match >> [&](const atom_value& val) {
......
...@@ -201,7 +201,9 @@ void test_sync_send() { ...@@ -201,7 +201,9 @@ void test_sync_send() {
self->quit(exit_reason::user_shutdown); self->quit(exit_reason::user_shutdown);
}); });
self->receive ( self->receive (
on(atom("DOWN"), exit_reason::user_shutdown) >> CPPA_CHECKPOINT_CB(), on_arg_match >> [&](const down_msg& dm) {
CPPA_CHECK_EQUAL(dm.reason, exit_reason::user_shutdown);
},
others() >> CPPA_UNEXPECTED_MSG_CB() others() >> CPPA_UNEXPECTED_MSG_CB()
); );
auto mirror = spawn<sync_mirror>(); auto mirror = spawn<sync_mirror>();
...@@ -219,9 +221,12 @@ void test_sync_send() { ...@@ -219,9 +221,12 @@ void test_sync_send() {
self->receive ( self->receive (
on(atom("success")) >> CPPA_CHECKPOINT_CB(), on(atom("success")) >> CPPA_CHECKPOINT_CB(),
on(atom("failure")) >> CPPA_FAILURE_CB("A didn't receive sync response"), on(atom("failure")) >> CPPA_FAILURE_CB("A didn't receive sync response"),
on(atom("DOWN"), arg_match).when(_x2 != exit_reason::normal) on_arg_match >> [&](const down_msg& dm) -> match_hint {
>> [&](uint32_t err) { if (dm.reason != exit_reason::normal) {
CPPA_FAILURE("A exited for reason " << err); CPPA_FAILURE("A exited for reason " << dm.reason);
return match_hint::handle;
}
return match_hint::skip;
} }
); );
}; };
...@@ -235,14 +240,16 @@ void test_sync_send() { ...@@ -235,14 +240,16 @@ void test_sync_send() {
self->await_all_other_actors_done(); self->await_all_other_actors_done();
CPPA_CHECKPOINT(); CPPA_CHECKPOINT();
self->timed_sync_send(self, std::chrono::milliseconds(50), atom("NoWay")).await( self->timed_sync_send(self, std::chrono::milliseconds(50), atom("NoWay")).await(
on(atom("TIMEOUT")) >> CPPA_CHECKPOINT_CB(), on<sync_timeout_msg>() >> CPPA_CHECKPOINT_CB(),
others() >> CPPA_UNEXPECTED_MSG_CB() others() >> CPPA_UNEXPECTED_MSG_CB()
); );
// we should have received two DOWN messages with normal exit reason // we should have received two DOWN messages with normal exit reason
// plus 'NoWay' // plus 'NoWay'
int i = 0; int i = 0;
self->receive_for(i, 3) ( self->receive_for(i, 3) (
on(atom("DOWN"), exit_reason::normal) >> CPPA_CHECKPOINT_CB(), on_arg_match >> [&](const down_msg& dm) {
CPPA_CHECK_EQUAL(dm.reason, exit_reason::normal);
},
on(atom("NoWay")) >> [] { on(atom("NoWay")) >> [] {
CPPA_CHECKPOINT(); CPPA_CHECKPOINT();
CPPA_PRINT("trigger \"actor did not reply to a " CPPA_PRINT("trigger \"actor did not reply to a "
...@@ -305,7 +312,9 @@ void test_sync_send() { ...@@ -305,7 +312,9 @@ void test_sync_send() {
self->receive_loop(others() >> CPPA_UNEXPECTED_MSG_CB()); self->receive_loop(others() >> CPPA_UNEXPECTED_MSG_CB());
}); });
self->receive ( self->receive (
on(atom("DOWN"), exit_reason::user_shutdown) >> CPPA_CHECKPOINT_CB(), on_arg_match >> [&](const down_msg& dm) {
CPPA_CHECK_EQUAL(dm.reason, exit_reason::user_shutdown);
},
others() >> CPPA_UNEXPECTED_MSG_CB() others() >> CPPA_UNEXPECTED_MSG_CB()
); );
} }
......
...@@ -93,7 +93,11 @@ int main() { ...@@ -93,7 +93,11 @@ int main() {
"@proc", // intrusive_ptr<node_id> "@proc", // intrusive_ptr<node_id>
"@duration", // util::duration "@duration", // util::duration
"@buffer", // util::buffer "@buffer", // util::buffer
// default announced cpap tuples "@down", // down_msg
"@exit", // exit_msg
"@timeout", // timeout_msg
"@sync_timeout", // sync_timeout_msg
// default announced cppa tuples
"@<>+@atom", // {atom_value} "@<>+@atom", // {atom_value}
"@<>+@atom+@actor", // {atom_value, actor_ptr} "@<>+@atom+@actor", // {atom_value, actor_ptr}
"@<>+@atom+@proc", // {atom_value, node_id} "@<>+@atom+@proc", // {atom_value, node_id}
......
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