Commit 2c5604c6 authored by Dominik Charousset's avatar Dominik Charousset

Rename {unexpected => default}_handler

Relates #444.
parent b86b6c30
...@@ -153,7 +153,7 @@ private: ...@@ -153,7 +153,7 @@ private:
); );
}, },
// simply ignore all requests until we have a connection // simply ignore all requests until we have a connection
others >> skip_message others >> skip
}; };
*/ */
} }
......
...@@ -81,6 +81,7 @@ set (LIBCAF_CORE_SRCS ...@@ -81,6 +81,7 @@ set (LIBCAF_CORE_SRCS
src/serializer.cpp src/serializer.cpp
src/sequencer.cpp src/sequencer.cpp
src/shared_spinlock.cpp src/shared_spinlock.cpp
src/skip.cpp
src/splitter.cpp src/splitter.cpp
src/sync_request_bouncer.cpp src/sync_request_bouncer.cpp
src/try_match.cpp src/try_match.cpp
......
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
#include "caf/actor_system.hpp" #include "caf/actor_system.hpp"
#include "caf/deserializer.hpp" #include "caf/deserializer.hpp"
#include "caf/scoped_actor.hpp" #include "caf/scoped_actor.hpp"
#include "caf/skip_message.hpp" #include "caf/skip.hpp"
#include "caf/actor_ostream.hpp" #include "caf/actor_ostream.hpp"
#include "caf/function_view.hpp" #include "caf/function_view.hpp"
#include "caf/index_mapping.hpp" #include "caf/index_mapping.hpp"
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include "caf/message.hpp" #include "caf/message.hpp"
#include "caf/duration.hpp" #include "caf/duration.hpp"
#include "caf/ref_counted.hpp" #include "caf/ref_counted.hpp"
#include "caf/skip_message.hpp" #include "caf/skip.hpp"
#include "caf/response_promise.hpp" #include "caf/response_promise.hpp"
#include "caf/timeout_definition.hpp" #include "caf/timeout_definition.hpp"
#include "caf/typed_response_promise.hpp" #include "caf/typed_response_promise.hpp"
...@@ -55,9 +55,9 @@ namespace caf { ...@@ -55,9 +55,9 @@ namespace caf {
namespace detail { namespace detail {
template <class... Ts> template <class... Ts>
struct has_skip_message { struct has_skip {
static constexpr bool value = static constexpr bool value =
disjunction<std::is_same<Ts, skip_message_t>::value...>::value; disjunction<std::is_same<Ts, skip_t>::value...>::value;
}; };
class behavior_impl : public ref_counted { class behavior_impl : public ref_counted {
......
...@@ -72,7 +72,7 @@ struct ctm_cmp<typed_mpi<In, type_list<Ts...>>, ...@@ -72,7 +72,7 @@ struct ctm_cmp<typed_mpi<In, type_list<Ts...>>,
template <class In, class Out> template <class In, class Out>
struct ctm_cmp<typed_mpi<In, Out>, struct ctm_cmp<typed_mpi<In, Out>,
typed_mpi<In, type_list<skip_message_t>>> typed_mpi<In, type_list<skip_t>>>
: std::true_type { }; : std::true_type { };
template <class In, class... Ts> template <class In, class... Ts>
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include "caf/optional.hpp" #include "caf/optional.hpp"
#include "caf/result.hpp" #include "caf/result.hpp"
#include "caf/message.hpp" #include "caf/message.hpp"
#include "caf/skip_message.hpp" #include "caf/skip.hpp"
#include "caf/typed_continue_helper.hpp" #include "caf/typed_continue_helper.hpp"
#include "caf/detail/int_list.hpp" #include "caf/detail/int_list.hpp"
...@@ -120,15 +120,15 @@ public: ...@@ -120,15 +120,15 @@ public:
return true; return true;
} }
inline bool visit(skip_message_t&) { inline bool visit(skip_t&) {
return false; return false;
} }
inline bool visit(const skip_message_t&) { inline bool visit(const skip_t&) {
return false; return false;
} }
inline bool visit(optional<skip_message_t>& x) { inline bool visit(optional<skip_t>& x) {
if (x) if (x)
return false; return false;
(*this)(x); (*this)(x);
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "caf/unit.hpp" #include "caf/unit.hpp"
#include "caf/optional.hpp" #include "caf/optional.hpp"
#include "caf/delegated.hpp" #include "caf/delegated.hpp"
#include "caf/skip_message.hpp" #include "caf/skip.hpp"
#include "caf/static_visitor.hpp" #include "caf/static_visitor.hpp"
#include "caf/response_promise.hpp" #include "caf/response_promise.hpp"
#include "caf/typed_response_promise.hpp" #include "caf/typed_response_promise.hpp"
...@@ -63,8 +63,8 @@ struct optional_message_visitor_enable_tpl { ...@@ -63,8 +63,8 @@ struct optional_message_visitor_enable_tpl {
typename std::remove_const<T>::type, typename std::remove_const<T>::type,
none_t, none_t,
unit_t, unit_t,
skip_message_t, skip_t,
optional<skip_message_t> optional<skip_t>
>::value >::value
&& ! is_message_id_wrapper<T>::value && ! is_message_id_wrapper<T>::value
&& ! is_response_promise<T>::value; && ! is_response_promise<T>::value;
...@@ -80,7 +80,7 @@ public: ...@@ -80,7 +80,7 @@ public:
return none; return none;
} }
inline opt_msg operator()(const skip_message_t&) const { inline opt_msg operator()(const skip_t&) const {
return none; return none;
} }
...@@ -88,7 +88,7 @@ public: ...@@ -88,7 +88,7 @@ public:
return message{}; return message{};
} }
inline opt_msg operator()(optional<skip_message_t>& val) const { inline opt_msg operator()(optional<skip_t>& val) const {
if (val) if (val)
return none; return none;
return message{}; return message{};
......
...@@ -65,10 +65,10 @@ public: ...@@ -65,10 +65,10 @@ public:
} }
return delegated<message>{}; return delegated<message>{};
}; };
set_unexpected_handler(g); set_default_handler(g);
return delegated<message>{}; return delegated<message>{};
}; };
set_unexpected_handler(f); set_default_handler(f);
return { return {
[] { [] {
// nop // nop
......
...@@ -39,6 +39,7 @@ template <class, class, int> class actor_cast_access; ...@@ -39,6 +39,7 @@ template <class, class, int> class actor_cast_access;
// -- variadic templates ------------------------------------------------------- // -- variadic templates -------------------------------------------------------
template <class...> class result;
template <class...> class delegated; template <class...> class delegated;
template <class...> class typed_actor; template <class...> class typed_actor;
template <class...> class typed_response_promise; template <class...> class typed_response_promise;
......
...@@ -85,32 +85,24 @@ struct make_response_promise_helper<response_promise> { ...@@ -85,32 +85,24 @@ struct make_response_promise_helper<response_promise> {
} // namespace detail } // namespace detail
/// @relates local_actor /// @relates local_actor
/// Default handler function for unexpected messages /// Default handler function that sends the message back to the sender.
/// that sends the message back to the sender. result<message> reflect(local_actor*, const type_erased_tuple*);
result<message> reflect_unexpected(local_actor*, const type_erased_tuple*);
/// @relates local_actor /// @relates local_actor
/// Default handler function for unexpected messages /// Default handler function that sends
/// that sends the message back to the sender and then quits. /// the message back to the sender and then quits.
result<message> reflect_unexpected_and_quit(local_actor*, result<message> reflect_and_quit(local_actor*,
const type_erased_tuple*); const type_erased_tuple*);
/// @relates local_actor /// @relates local_actor
/// Default handler function for unexpected messages that /// Default handler function that prints messages
/// skips an unexpected message in order to handle it again /// message via `aout` and drops them afterwards.
/// after a behavior change. result<message> print_and_drop(local_actor*,
result<message> skip_unexpected(local_actor*, const type_erased_tuple*);
/// @relates local_actor
/// Default handler function for unexpected messages that prints
/// an unexpected message via `aout` and drops it afterwards.
result<message> print_and_drop_unexpected(local_actor*,
const type_erased_tuple*); const type_erased_tuple*);
/// @relates local_actor /// @relates local_actor
/// Default handler function for unexpected messages that /// Default handler function that simply drops messages.
/// drops unexpected messages without printing them. result<message> drop(local_actor*, const type_erased_tuple*);
result<message> drop_unexpected(local_actor*, const type_erased_tuple*);
/// Base class for actors running on this node, either /// Base class for actors running on this node, either
/// living in an own thread or cooperatively scheduled. /// living in an own thread or cooperatively scheduled.
...@@ -318,7 +310,7 @@ public: ...@@ -318,7 +310,7 @@ public:
// -- miscellaneous actor operations ----------------------------------------- // -- miscellaneous actor operations -----------------------------------------
/// Sets a custom handler for unexpected messages. /// Sets a custom handler for unexpected messages.
inline void set_unexpected_handler(unexpected_handler fun) { inline void set_default_handler(unexpected_handler fun) {
unexpected_handler_ = std::move(fun); unexpected_handler_ = std::move(fun);
} }
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "caf/param.hpp" #include "caf/param.hpp"
#include "caf/optional.hpp" #include "caf/optional.hpp"
#include "caf/match_case.hpp" #include "caf/match_case.hpp"
#include "caf/skip_message.hpp" #include "caf/skip.hpp"
#include "caf/detail/int_list.hpp" #include "caf/detail/int_list.hpp"
#include "caf/detail/try_match.hpp" #include "caf/detail/try_match.hpp"
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "caf/config.hpp" #include "caf/config.hpp"
#include "caf/optional.hpp" #include "caf/optional.hpp"
#include "caf/make_counted.hpp" #include "caf/make_counted.hpp"
#include "caf/skip_message.hpp" #include "caf/skip.hpp"
#include "caf/index_mapping.hpp" #include "caf/index_mapping.hpp"
#include "caf/allowed_unsafe_message_type.hpp" #include "caf/allowed_unsafe_message_type.hpp"
......
...@@ -21,10 +21,10 @@ ...@@ -21,10 +21,10 @@
#define CAF_RESULT_HPP #define CAF_RESULT_HPP
#include "caf/none.hpp" #include "caf/none.hpp"
#include "caf/skip.hpp"
#include "caf/error.hpp" #include "caf/error.hpp"
#include "caf/message.hpp" #include "caf/message.hpp"
#include "caf/delegated.hpp" #include "caf/delegated.hpp"
#include "caf/skip_message.hpp"
namespace caf { namespace caf {
...@@ -32,11 +32,11 @@ enum result_runtime_type { ...@@ -32,11 +32,11 @@ enum result_runtime_type {
rt_value, rt_value,
rt_error, rt_error,
rt_delegated, rt_delegated,
rt_skip_message rt_skip
}; };
template <class... Ts> template <class... Ts>
struct result { class result {
public: public:
result(Ts... xs) : flag(rt_value), value(make_message(std::move(xs)...)) { result(Ts... xs) : flag(rt_value), value(make_message(std::move(xs)...)) {
// nop // nop
...@@ -62,7 +62,7 @@ public: ...@@ -62,7 +62,7 @@ public:
// nop // nop
} }
result(skip_message_t) : flag(rt_skip_message) { result(skip_t) : flag(rt_skip) {
// nop // nop
} }
...@@ -106,7 +106,7 @@ public: ...@@ -106,7 +106,7 @@ public:
// nop // nop
} }
result(skip_message_t) : flag(rt_skip_message) { result(skip_t) : flag(rt_skip) {
// nop // nop
} }
......
...@@ -17,31 +17,43 @@ ...@@ -17,31 +17,43 @@
* http://www.boost.org/LICENSE_1_0.txt. * * http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/ ******************************************************************************/
#ifndef CAF_SKIP_MESSAGE_HPP #ifndef CAF_SKIP_HPP
#define CAF_SKIP_MESSAGE_HPP #define CAF_SKIP_HPP
#include <ostream> #include <functional>
#include "caf/fwd.hpp"
namespace caf { namespace caf {
/// Optional return type for functors used in pattern matching /// @relates local_actor
/// expressions. This type is evaluated by the runtime system /// Default handler function that leaves messages in the mailbox.
/// and can be used to intentionally skip messages. /// Can also be used inside custom message handlers to signalize
struct skip_message_t { /// skipping to the runtime.
constexpr skip_message_t() {} class skip_t {
public:
using fun = std::function<result<message>(local_actor* self,
const type_erased_tuple*)>;
constexpr skip_t() {
// nop
}
constexpr skip_t operator()() const {
return *this;
}
operator fun() const;
private:
static result<message> skip_fun_impl(local_actor*, const type_erased_tuple*);
}; };
/// Tells the runtime system to skip a message when used as message /// Tells the runtime system to skip a message when used as message
/// handler, i.e., causes the runtime to leave the message in /// handler, i.e., causes the runtime to leave the message in
/// the mailbox of an actor. /// the mailbox of an actor.
constexpr skip_message_t skip_message() { constexpr skip_t skip = skip_t{};
return {};
}
// implemented in string_serialization.cpp
std::ostream& operator<<(std::ostream&, skip_message_t);
} // namespace caf } // namespace caf
#endif // CAF_SKIP_MESSAGE_HPP #endif // CAF_SKIP_HPP
...@@ -41,17 +41,17 @@ struct input_only<detail::type_list<Ts...>> { ...@@ -41,17 +41,17 @@ struct input_only<detail::type_list<Ts...>> {
using type = detail::type_list<typename Ts::input_types...>; using type = detail::type_list<typename Ts::input_types...>;
}; };
using skip_list = detail::type_list<skip_message_t>; using skip_list = detail::type_list<skip_t>;
template <class Input, class RepliesToWith> template <class Input, class RepliesToWith>
struct same_input : std::is_same<Input, typename RepliesToWith::input_types> {}; struct same_input : std::is_same<Input, typename RepliesToWith::input_types> {};
template <class Output, class RepliesToWith> template <class Output, class RepliesToWith>
struct same_output_or_skip_message_t { struct same_output_or_skip_t {
using other = typename RepliesToWith::output_types; using other = typename RepliesToWith::output_types;
static constexpr bool value = static constexpr bool value =
std::is_same<Output, typename RepliesToWith::output_types>::value || std::is_same<Output, typename RepliesToWith::output_types>::value ||
std::is_same<Output, type_list<skip_message_t>>::value; std::is_same<Output, type_list<skip_t>>::value;
}; };
template <class SList> template <class SList>
...@@ -72,7 +72,7 @@ struct valid_input_predicate { ...@@ -72,7 +72,7 @@ struct valid_input_predicate {
"contains at least one pattern that is " "contains at least one pattern that is "
"not defined in the actor's type"); "not defined in the actor's type");
static constexpr bool value = tl_exists< static constexpr bool value = tl_exists<
filtered_slist, tbind<same_output_or_skip_message_t, filtered_slist, tbind<same_output_or_skip_t,
output_types>::template type>::value; output_types>::template type>::value;
// check whether given output matches in the filtered list // check whether given output matches in the filtered list
static_assert(value, static_assert(value,
...@@ -110,7 +110,7 @@ struct valid_input { ...@@ -110,7 +110,7 @@ struct valid_input {
// check for each element in IList that there's an element in SList that // check for each element in IList that there's an element in SList that
// (1) has an identical input type list // (1) has an identical input type list
// (2) has an identical output type list // (2) has an identical output type list
// OR the output of the element in IList is skip_message_t // OR the output of the element in IList is skip_t
static_assert(detail::tl_is_distinct<IList>::value, static_assert(detail::tl_is_distinct<IList>::value,
"given pattern is not distinct"); "given pattern is not distinct");
static constexpr bool value = static constexpr bool value =
......
...@@ -28,7 +28,7 @@ namespace caf { ...@@ -28,7 +28,7 @@ namespace caf {
blocking_actor::blocking_actor(actor_config& sys) : super(sys) { blocking_actor::blocking_actor(actor_config& sys) : super(sys) {
is_blocking(true); is_blocking(true);
set_unexpected_handler(skip_unexpected); set_default_handler(skip);
} }
blocking_actor::~blocking_actor() { blocking_actor::~blocking_actor() {
......
...@@ -169,7 +169,7 @@ public: ...@@ -169,7 +169,7 @@ public:
send_to_acquaintances(message::from(ptr)); send_to_acquaintances(message::from(ptr));
return message{}; return message{};
}; };
set_unexpected_handler(fwd); set_default_handler(fwd);
// return behavior // return behavior
return { return {
[=](join_atom, const actor& other) { [=](join_atom, const actor& other) {
...@@ -329,7 +329,7 @@ behavior proxy_broker::make_behavior() { ...@@ -329,7 +329,7 @@ behavior proxy_broker::make_behavior() {
context()); context());
return message{}; return message{};
}; };
set_unexpected_handler(fwd); set_default_handler(fwd);
// return dummy behavior // return dummy behavior
return { return {
[](const down_msg&) { [](const down_msg&) {
......
...@@ -39,21 +39,17 @@ ...@@ -39,21 +39,17 @@
namespace caf { namespace caf {
result<message> reflect_unexpected(local_actor*, const type_erased_tuple* x) { result<message> reflect(local_actor*, const type_erased_tuple* x) {
return message::from(x); return message::from(x);
} }
result<message> reflect_unexpected_and_quit(local_actor* self, result<message> reflect_and_quit(local_actor* self,
const type_erased_tuple* x) { const type_erased_tuple* x) {
self->quit(); self->quit();
return reflect_unexpected(self, x); return reflect(self, x);
} }
result<message> skip_unexpected(local_actor*, const type_erased_tuple*) { result<message> print_and_drop(local_actor* self,
return skip_message();
}
result<message> print_and_drop_unexpected(local_actor* self,
const type_erased_tuple* x) { const type_erased_tuple* x) {
CAF_LOG_WARNING("unexpected message" << CAF_ARG(*x)); CAF_LOG_WARNING("unexpected message" << CAF_ARG(*x));
aout(self) << "*** unexpected message [id: " << self->id() aout(self) << "*** unexpected message [id: " << self->id()
...@@ -62,7 +58,7 @@ result<message> print_and_drop_unexpected(local_actor* self, ...@@ -62,7 +58,7 @@ result<message> print_and_drop_unexpected(local_actor* self,
return sec::unexpected_message; return sec::unexpected_message;
} }
result<message> drop_unexpected(local_actor*, result<message> drop(local_actor*,
const type_erased_tuple*) { const type_erased_tuple*) {
return sec::unexpected_message; return sec::unexpected_message;
} }
...@@ -76,7 +72,7 @@ local_actor::local_actor(actor_config& cfg) ...@@ -76,7 +72,7 @@ local_actor::local_actor(actor_config& cfg)
planned_exit_reason_(exit_reason::not_exited), planned_exit_reason_(exit_reason::not_exited),
timeout_id_(0), timeout_id_(0),
initial_behavior_fac_(std::move(cfg.init_fun)), initial_behavior_fac_(std::move(cfg.init_fun)),
unexpected_handler_(print_and_drop_unexpected) { unexpected_handler_(print_and_drop) {
if (cfg.groups != nullptr) if (cfg.groups != nullptr)
for (auto& grp : *cfg.groups) for (auto& grp : *cfg.groups)
join(grp); join(grp);
...@@ -86,7 +82,7 @@ local_actor::local_actor() ...@@ -86,7 +82,7 @@ local_actor::local_actor()
: monitorable_actor(abstract_channel::is_abstract_actor_flag), : monitorable_actor(abstract_channel::is_abstract_actor_flag),
planned_exit_reason_(exit_reason::not_exited), planned_exit_reason_(exit_reason::not_exited),
timeout_id_(0), timeout_id_(0),
unexpected_handler_(print_and_drop_unexpected) { unexpected_handler_(print_and_drop) {
// nop // nop
} }
...@@ -94,7 +90,7 @@ local_actor::local_actor(int init_flags) ...@@ -94,7 +90,7 @@ local_actor::local_actor(int init_flags)
: monitorable_actor(init_flags), : monitorable_actor(init_flags),
planned_exit_reason_(exit_reason::not_exited), planned_exit_reason_(exit_reason::not_exited),
timeout_id_(0), timeout_id_(0),
unexpected_handler_(print_and_drop_unexpected) { unexpected_handler_(print_and_drop) {
// nop // nop
} }
...@@ -532,7 +528,7 @@ invoke_message_result local_actor::invoke_message(mailbox_element_ptr& ptr, ...@@ -532,7 +528,7 @@ invoke_message_result local_actor::invoke_message(mailbox_element_ptr& ptr,
has_timeout(true); has_timeout(true);
auto sres = unexpected_handler_(this, auto sres = unexpected_handler_(this,
current_element_->msg.cvals().get()); current_element_->msg.cvals().get());
if (sres.flag != rt_skip_message) if (sres.flag != rt_skip)
visitor.visit(sres); visitor.visit(sres);
else else
skipped = true; skipped = true;
......
...@@ -244,9 +244,9 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs, ...@@ -244,9 +244,9 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
// store any occurred error in a temporary variable returned at the end // store any occurred error in a temporary variable returned at the end
std::string error; std::string error;
auto res = extract({ auto res = extract({
[&](const std::string& arg) -> optional<skip_message_t> { [&](const std::string& arg) -> optional<skip_t> {
if (arg.empty() || arg.front() != '-') { if (arg.empty() || arg.front() != '-') {
return skip_message(); return skip();
} }
auto i = shorts.find(arg.substr(0, 2)); auto i = shorts.find(arg.substr(0, 2));
if (i != shorts.end()) { if (i != shorts.end()) {
...@@ -256,13 +256,13 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs, ...@@ -256,13 +256,13 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
// this short opt comes with a value (no space), e.g., -x2 // this short opt comes with a value (no space), e.g., -x2
if (! i->second->fun(arg.substr(2))) { if (! i->second->fun(arg.substr(2))) {
error = "invalid value for " + i->second->name + ": " + arg; error = "invalid value for " + i->second->name + ": " + arg;
return skip_message(); return skip();
} }
insert_opt_name(i->second); insert_opt_name(i->second);
return none; return none;
} }
// no value given, try two-argument form below // no value given, try two-argument form below
return skip_message(); return skip();
} }
insert_opt_name(i->second); insert_opt_name(i->second);
return none; return none;
...@@ -273,11 +273,11 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs, ...@@ -273,11 +273,11 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
if (j->second->fun) { if (j->second->fun) {
if (eq_pos == std::string::npos) { if (eq_pos == std::string::npos) {
error = "missing argument to " + arg; error = "missing argument to " + arg;
return skip_message(); return skip();
} }
if (! j->second->fun(arg.substr(eq_pos + 1))) { if (! j->second->fun(arg.substr(eq_pos + 1))) {
error = "invalid value for " + j->second->name + ": " + arg; error = "invalid value for " + j->second->name + ": " + arg;
return skip_message(); return skip();
} }
insert_opt_name(j->second); insert_opt_name(j->second);
return none; return none;
...@@ -286,12 +286,12 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs, ...@@ -286,12 +286,12 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
return none; return none;
} }
error = "unknown command line option: " + arg; error = "unknown command line option: " + arg;
return skip_message(); return skip();
}, },
[&](const std::string& arg1, [&](const std::string& arg1,
const std::string& arg2) -> optional<skip_message_t> { const std::string& arg2) -> optional<skip_t> {
if (arg1.size() < 2 || arg1[0] != '-' || arg1[1] == '-') { if (arg1.size() < 2 || arg1[0] != '-' || arg1[1] == '-') {
return skip_message(); return skip();
} }
auto i = shorts.find(arg1.substr(0, 2)); auto i = shorts.find(arg1.substr(0, 2));
if (i != shorts.end()) { if (i != shorts.end()) {
...@@ -299,18 +299,18 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs, ...@@ -299,18 +299,18 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
// this short opt either expects no argument or comes with a value // this short opt either expects no argument or comes with a value
// (no space), e.g., -x2, so we have to parse it with the // (no space), e.g., -x2, so we have to parse it with the
// one-argument form above // one-argument form above
return skip_message(); return skip();
} }
CAF_ASSERT(arg1.size() == 2); CAF_ASSERT(arg1.size() == 2);
if (! i->second->fun(arg2)) { if (! i->second->fun(arg2)) {
error = "invalid value for option " + i->second->name + ": " + arg2; error = "invalid value for option " + i->second->name + ": " + arg2;
return skip_message(); return skip();
} }
insert_opt_name(i->second); insert_opt_name(i->second);
return none; return none;
} }
error = "unknown command line option: " + arg1; error = "unknown command line option: " + arg1;
return skip_message(); return skip();
} }
}); });
return {res, std::move(opts), std::move(helpstr), std::move(error)}; return {res, std::move(opts), std::move(helpstr), std::move(error)};
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/skip.hpp"
#include "caf/result.hpp"
#include "caf/message.hpp"
namespace caf {
result<message> skip_t::skip_fun_impl(local_actor*, const type_erased_tuple*) {
return skip();
}
skip_t::operator fun() const {
return skip_fun_impl;
}
} // namespace caf
...@@ -65,7 +65,7 @@ behavior fan_out_fan_in(stateful_actor<splitter_state>* self, ...@@ -65,7 +65,7 @@ behavior fan_out_fan_in(stateful_actor<splitter_state>* self,
); );
return delegated<message>{}; return delegated<message>{};
}; };
self->set_unexpected_handler(f); self->set_default_handler(f);
return [] { return [] {
// nop // nop
}; };
...@@ -85,7 +85,7 @@ behavior fan_out_fan_in(stateful_actor<splitter_state>* self, ...@@ -85,7 +85,7 @@ behavior fan_out_fan_in(stateful_actor<splitter_state>* self,
} }
); );
}; };
set_unexpected_handler(f); set_default_handler(f);
return { return {
others >> [=](const message& msg) { others >> [=](const message& msg) {
self->state.rp = self->make_response_promise(); self->state.rp = self->make_response_promise();
......
...@@ -211,7 +211,7 @@ public: ...@@ -211,7 +211,7 @@ public:
} }
behavior make_behavior() override { behavior make_behavior() override {
set_unexpected_handler(reflect_unexpected); set_default_handler(reflect);
return { return {
[] { [] {
// nop // nop
...@@ -231,7 +231,7 @@ public: ...@@ -231,7 +231,7 @@ public:
} }
behavior make_behavior() override { behavior make_behavior() override {
set_unexpected_handler(reflect_unexpected); set_default_handler(reflect);
return { return {
[] { [] {
// nop // nop
......
...@@ -43,7 +43,7 @@ public: ...@@ -43,7 +43,7 @@ public:
behavior make_behavior() override { behavior make_behavior() override {
// reflecting a message increases its reference count by one // reflecting a message increases its reference count by one
set_unexpected_handler(reflect_unexpected_and_quit); set_default_handler(reflect_and_quit);
return { return {
[] { [] {
// nop // nop
......
...@@ -49,7 +49,7 @@ CAF_TEST(metaprogramming) { ...@@ -49,7 +49,7 @@ CAF_TEST(metaprogramming) {
using if2 = type_list<replies_to<int>::with<int>, using if2 = type_list<replies_to<int>::with<int>,
replies_to<int, double>::with<void>>; replies_to<int, double>::with<void>>;
using if3 = type_list<replies_to<int, double>::with<void>>; using if3 = type_list<replies_to<int, double>::with<void>>;
using if4 = type_list<replies_to<int>::with<skip_message_t>, using if4 = type_list<replies_to<int>::with<skip_t>,
replies_to<int, double>::with<void>>; replies_to<int, double>::with<void>>;
CAF_CHECK_EQUAL((ctm<if1, if2>::value), -1); CAF_CHECK_EQUAL((ctm<if1, if2>::value), -1);
CAF_CHECK_NOT_EQUAL((ctm<if1, if3>::value), -1); CAF_CHECK_NOT_EQUAL((ctm<if1, if3>::value), -1);
......
...@@ -49,7 +49,7 @@ struct sync_mirror : event_based_actor { ...@@ -49,7 +49,7 @@ struct sync_mirror : event_based_actor {
} }
behavior make_behavior() override { behavior make_behavior() override {
set_unexpected_handler(reflect_unexpected); set_default_handler(reflect);
return { return {
[] { [] {
// nop // nop
...@@ -82,7 +82,7 @@ public: ...@@ -82,7 +82,7 @@ public:
: event_based_actor(cfg), : event_based_actor(cfg),
buddy_(buddy_arg) { buddy_(buddy_arg) {
// don't pollute unit test output with (provoked) warnings // don't pollute unit test output with (provoked) warnings
set_unexpected_handler(drop_unexpected); set_default_handler(drop);
} }
inline const actor& buddy() const { inline const actor& buddy() const {
...@@ -145,7 +145,7 @@ class C : public event_based_actor { ...@@ -145,7 +145,7 @@ class C : public event_based_actor {
public: public:
C(actor_config& cfg) : event_based_actor(cfg) { C(actor_config& cfg) : event_based_actor(cfg) {
// don't pollute unit test output with (provoked) warnings // don't pollute unit test output with (provoked) warnings
set_unexpected_handler(drop_unexpected); set_default_handler(drop);
} }
behavior make_behavior() override { behavior make_behavior() override {
...@@ -223,12 +223,12 @@ printf("server id: %d\n", (int) self->id()); ...@@ -223,12 +223,12 @@ printf("server id: %d\n", (int) self->id());
return self->delegate(worker, task); return self->delegate(worker, task);
}, },
[](idle_atom) { [](idle_atom) {
return skip_message(); return skip();
} }
); );
}, },
[](request_atom) { [](request_atom) {
return skip_message(); return skip();
} }
}; };
} }
...@@ -261,7 +261,7 @@ CAF_TEST(test_void_res) { ...@@ -261,7 +261,7 @@ CAF_TEST(test_void_res) {
CAF_TEST(pending_quit) { CAF_TEST(pending_quit) {
auto mirror = system.spawn([](event_based_actor* self) -> behavior { auto mirror = system.spawn([](event_based_actor* self) -> behavior {
self->set_unexpected_handler(reflect_unexpected); self->set_default_handler(reflect);
return { return {
[] { [] {
// nop // nop
......
...@@ -42,7 +42,7 @@ using sub4_atom = atom_constant<atom("sub4")>; ...@@ -42,7 +42,7 @@ using sub4_atom = atom_constant<atom("sub4")>;
CAF_TEST(test_serial_reply) { CAF_TEST(test_serial_reply) {
actor_system system; actor_system system;
auto mirror_behavior = [=](event_based_actor* self) -> behavior { auto mirror_behavior = [=](event_based_actor* self) -> behavior {
self->set_unexpected_handler(reflect_unexpected); self->set_default_handler(reflect);
return { return {
[] { [] {
// nop // nop
......
...@@ -74,9 +74,9 @@ struct fixture { ...@@ -74,9 +74,9 @@ struct fixture {
void await_down(const actor& x) { void await_down(const actor& x) {
self->monitor(x); self->monitor(x);
self->receive( self->receive(
[&](const down_msg& dm) -> optional<skip_message_t> { [&](const down_msg& dm) -> optional<skip_t> {
if (dm.source != x) if (dm.source != x)
return skip_message(); return skip();
return none; return none;
} }
); );
......
...@@ -192,10 +192,10 @@ public: ...@@ -192,10 +192,10 @@ public:
become(wait4int()); become(wait4int());
}, },
[](float) { [](float) {
return skip_message(); return skip();
}, },
[](int) { [](int) {
return skip_message(); return skip();
} }
}; };
} }
...@@ -210,10 +210,10 @@ public: ...@@ -210,10 +210,10 @@ public:
return 42; return 42;
}, },
[](float) { [](float) {
return skip_message(); return skip();
}, },
[](const string&) { [](const string&) {
return skip_message(); return skip();
} }
}; };
} }
...@@ -227,10 +227,10 @@ public: ...@@ -227,10 +227,10 @@ public:
become(wait4string()); become(wait4string());
}, },
[](const string&) { [](const string&) {
return skip_message(); return skip();
}, },
[](int) { [](int) {
return skip_message(); return skip();
} }
}; };
} }
......
...@@ -264,13 +264,13 @@ void basp_broker_state::learned_new_node(const node_id& nid) { ...@@ -264,13 +264,13 @@ void basp_broker_state::learned_new_node(const node_id& nid) {
tmp = system().spawn<hidden>([=](event_based_actor* this_actor) -> behavior { tmp = system().spawn<hidden>([=](event_based_actor* this_actor) -> behavior {
CAF_LOG_TRACE(""); CAF_LOG_TRACE("");
// skip messages until we receive the initial ok_atom // skip messages until we receive the initial ok_atom
this_actor->set_unexpected_handler(skip_unexpected); this_actor->set_default_handler(skip);
return { return {
[=](ok_atom, const std::string& /* key == "info" */, [=](ok_atom, const std::string& /* key == "info" */,
const actor_addr& config_serv_addr, const std::string& /* name */) { const actor_addr& config_serv_addr, const std::string& /* name */) {
CAF_LOG_TRACE(CAF_ARG(config_serv_addr)); CAF_LOG_TRACE(CAF_ARG(config_serv_addr));
// drop unexpected messages from this point on // drop unexpected messages from this point on
this_actor->set_unexpected_handler(print_and_drop_unexpected); this_actor->set_default_handler(print_and_drop);
auto config_serv = actor_cast<actor>(config_serv_addr); auto config_serv = actor_cast<actor>(config_serv_addr);
this_actor->monitor(config_serv); this_actor->monitor(config_serv);
this_actor->become( this_actor->become(
......
...@@ -644,7 +644,7 @@ CAF_TEST(remote_actor_and_send) { ...@@ -644,7 +644,7 @@ CAF_TEST(remote_actor_and_send) {
CAF_TEST(actor_serialize_and_deserialize) { CAF_TEST(actor_serialize_and_deserialize) {
auto testee_impl = [](event_based_actor* testee_self) -> behavior { auto testee_impl = [](event_based_actor* testee_self) -> behavior {
testee_self->set_unexpected_handler(reflect_unexpected_and_quit); testee_self->set_default_handler(reflect_and_quit);
return { return {
[] { [] {
// nop // nop
......
...@@ -49,7 +49,7 @@ struct fixture { ...@@ -49,7 +49,7 @@ struct fixture {
}; };
behavior make_reflector_behavior(event_based_actor* self) { behavior make_reflector_behavior(event_based_actor* self) {
self->set_unexpected_handler(reflect_unexpected_and_quit); self->set_default_handler(reflect_and_quit);
return { return {
[] { [] {
// nop // nop
...@@ -85,7 +85,7 @@ struct await_reflector_reply_behavior { ...@@ -85,7 +85,7 @@ struct await_reflector_reply_behavior {
// `grp` may be either local or remote // `grp` may be either local or remote
void make_client_behavior(event_based_actor* self, void make_client_behavior(event_based_actor* self,
actor server, group grp) { actor server, group grp) {
self->set_unexpected_handler(skip_unexpected); self->set_default_handler(skip);
self->spawn_in_group(grp, make_reflector_behavior); self->spawn_in_group(grp, make_reflector_behavior);
self->spawn_in_group(grp, make_reflector_behavior); self->spawn_in_group(grp, make_reflector_behavior);
self->request(server, infinite, spawn_atom::value, grp).then( self->request(server, infinite, spawn_atom::value, grp).then(
......
...@@ -37,7 +37,7 @@ using namespace caf; ...@@ -37,7 +37,7 @@ using namespace caf;
namespace { namespace {
behavior mirror(event_based_actor* self) { behavior mirror(event_based_actor* self) {
self->set_unexpected_handler(reflect_unexpected); self->set_default_handler(reflect);
return { return {
[] { [] {
// nop // nop
......
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