Commit ac2f6f23 authored by Dominik Charousset's avatar Dominik Charousset

convert invoke_message_result to an enum class

parent 8607ad2f
...@@ -7,6 +7,7 @@ file(GLOB_RECURSE LIBCAF_CORE_HDRS "caf/*.hpp") ...@@ -7,6 +7,7 @@ file(GLOB_RECURSE LIBCAF_CORE_HDRS "caf/*.hpp")
enum_to_string("caf/exit_reason.hpp" "exit_reason_strings.cpp") enum_to_string("caf/exit_reason.hpp" "exit_reason_strings.cpp")
enum_to_string("caf/intrusive/inbox_result.hpp" "inbox_result_strings.cpp") enum_to_string("caf/intrusive/inbox_result.hpp" "inbox_result_strings.cpp")
enum_to_string("caf/intrusive/task_result.hpp" "task_result_strings.cpp") enum_to_string("caf/intrusive/task_result.hpp" "task_result_strings.cpp")
enum_to_string("caf/invoke_message_result.hpp" "invoke_msg_result_strings.cpp")
enum_to_string("caf/message_priority.hpp" "message_priority_strings.cpp") enum_to_string("caf/message_priority.hpp" "message_priority_strings.cpp")
enum_to_string("caf/pec.hpp" "pec_strings.cpp") enum_to_string("caf/pec.hpp" "pec_strings.cpp")
enum_to_string("caf/sec.hpp" "sec_strings.cpp") enum_to_string("caf/sec.hpp" "sec_strings.cpp")
...@@ -16,6 +17,7 @@ enum_to_string("caf/stream_priority.hpp" "stream_priority_strings.cpp") ...@@ -16,6 +17,7 @@ enum_to_string("caf/stream_priority.hpp" "stream_priority_strings.cpp")
set(LIBCAF_CORE_SRCS set(LIBCAF_CORE_SRCS
"${CMAKE_CURRENT_BINARY_DIR}/exit_reason_strings.cpp" "${CMAKE_CURRENT_BINARY_DIR}/exit_reason_strings.cpp"
"${CMAKE_CURRENT_BINARY_DIR}/inbox_result_strings.cpp" "${CMAKE_CURRENT_BINARY_DIR}/inbox_result_strings.cpp"
"${CMAKE_CURRENT_BINARY_DIR}/invoke_msg_result_strings.cpp"
"${CMAKE_CURRENT_BINARY_DIR}/message_priority_strings.cpp" "${CMAKE_CURRENT_BINARY_DIR}/message_priority_strings.cpp"
"${CMAKE_CURRENT_BINARY_DIR}/pec_strings.cpp" "${CMAKE_CURRENT_BINARY_DIR}/pec_strings.cpp"
"${CMAKE_CURRENT_BINARY_DIR}/sec_strings.cpp" "${CMAKE_CURRENT_BINARY_DIR}/sec_strings.cpp"
......
...@@ -177,6 +177,7 @@ enum class atom_value : uint64_t; ...@@ -177,6 +177,7 @@ enum class atom_value : uint64_t;
enum class byte : uint8_t; enum class byte : uint8_t;
enum class sec : uint8_t; enum class sec : uint8_t;
enum class stream_priority; enum class stream_priority;
enum class invoke_message_result;
// -- aliases ------------------------------------------------------------------ // -- aliases ------------------------------------------------------------------
......
...@@ -22,17 +22,21 @@ ...@@ -22,17 +22,21 @@
namespace caf { namespace caf {
enum invoke_message_result { /// Stores the result of a message invocation.
im_success, enum class invoke_message_result {
im_skipped, /// Indicates that the actor consumed the message.
im_dropped consumed,
/// Indicates that the actor left the message in the mailbox.
skipped,
/// Indicates that the actor discarded the message based on meta data. For
/// example, timeout messages for already received requests usually get
/// dropped without calling any user-defined code.
dropped,
}; };
inline std::string to_string(invoke_message_result x) { /// @relates invoke_message_result
return x == im_success ? "im_success" std::string to_string(invoke_message_result);
: (x == im_skipped ? "im_skipped" : "im_dropped" );
}
} // namespace caf } // namespace caf
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
namespace caf { namespace caf {
raw_event_based_actor::raw_event_based_actor(actor_config& cfg) raw_event_based_actor::raw_event_based_actor(actor_config& cfg)
: event_based_actor(cfg) { : event_based_actor(cfg) {
// nop // nop
} }
...@@ -36,30 +36,30 @@ invoke_message_result raw_event_based_actor::consume(mailbox_element& x) { ...@@ -36,30 +36,30 @@ invoke_message_result raw_event_based_actor::consume(mailbox_element& x) {
auto& pr = awaited_responses_.front(); auto& pr = awaited_responses_.front();
// skip all messages until we receive the currently awaited response // skip all messages until we receive the currently awaited response
if (x.mid != pr.first) if (x.mid != pr.first)
return im_skipped; return invoke_message_result::skipped;
if (!pr.second(x.content())) { if (!pr.second(x.content())) {
// try again with error if first attempt failed // try again with error if first attempt failed
auto msg = make_message(make_error(sec::unexpected_response, auto msg = make_message(
x.move_content_to_message())); make_error(sec::unexpected_response, x.move_content_to_message()));
pr.second(msg); pr.second(msg);
} }
awaited_responses_.pop_front(); awaited_responses_.pop_front();
return im_success; return invoke_message_result::consumed;
} }
// handle multiplexed responses // handle multiplexed responses
if (x.mid.is_response()) { if (x.mid.is_response()) {
auto mrh = multiplexed_responses_.find(x.mid); auto mrh = multiplexed_responses_.find(x.mid);
// neither awaited nor multiplexed, probably an expired timeout // neither awaited nor multiplexed, probably an expired timeout
if (mrh == multiplexed_responses_.end()) if (mrh == multiplexed_responses_.end())
return im_dropped; return invoke_message_result::dropped;
if (!mrh->second(x.content())) { if (!mrh->second(x.content())) {
// try again with error if first attempt failed // try again with error if first attempt failed
auto msg = make_message(make_error(sec::unexpected_response, auto msg = make_message(
x.move_content_to_message())); make_error(sec::unexpected_response, x.move_content_to_message()));
mrh->second(msg); mrh->second(msg);
} }
multiplexed_responses_.erase(mrh); multiplexed_responses_.erase(mrh);
return im_success; return invoke_message_result::consumed;
} }
auto& content = x.content(); auto& content = x.content();
// handle timeout messages // handle timeout messages
...@@ -70,12 +70,12 @@ invoke_message_result raw_event_based_actor::consume(mailbox_element& x) { ...@@ -70,12 +70,12 @@ invoke_message_result raw_event_based_actor::consume(mailbox_element& x) {
if (is_active_receive_timeout(tid)) { if (is_active_receive_timeout(tid)) {
CAF_LOG_DEBUG("handle timeout message"); CAF_LOG_DEBUG("handle timeout message");
if (bhvr_stack_.empty()) if (bhvr_stack_.empty())
return im_dropped; return invoke_message_result::dropped;
bhvr_stack_.back().handle_timeout(); bhvr_stack_.back().handle_timeout();
return im_success; return invoke_message_result::consumed;
} }
CAF_LOG_DEBUG("dropped expired timeout message"); CAF_LOG_DEBUG("dropped expired timeout message");
return im_dropped; return invoke_message_result::dropped;
} }
// handle everything else as ordinary message // handle everything else as ordinary message
detail::default_invoke_result_visitor<event_based_actor> visitor{this}; detail::default_invoke_result_visitor<event_based_actor> visitor{this};
...@@ -103,7 +103,8 @@ invoke_message_result raw_event_based_actor::consume(mailbox_element& x) { ...@@ -103,7 +103,8 @@ invoke_message_result raw_event_based_actor::consume(mailbox_element& x) {
}; };
if (bhvr_stack_.empty()) { if (bhvr_stack_.empty()) {
call_default_handler(); call_default_handler();
return !skipped ? im_success : im_skipped; return !skipped ? invoke_message_result::consumed
: invoke_message_result::skipped;
} }
auto& bhvr = bhvr_stack_.back(); auto& bhvr = bhvr_stack_.back();
switch (bhvr(visitor, x.content())) { switch (bhvr(visitor, x.content())) {
...@@ -115,7 +116,8 @@ invoke_message_result raw_event_based_actor::consume(mailbox_element& x) { ...@@ -115,7 +116,8 @@ invoke_message_result raw_event_based_actor::consume(mailbox_element& x) {
case match_case::no_match: case match_case::no_match:
call_default_handler(); call_default_handler();
} }
return !skipped ? im_success : im_skipped; return !skipped ? invoke_message_result::consumed
: invoke_message_result::skipped;
// should be unreachable // should be unreachable
CAF_CRITICAL("invalid message type"); CAF_CRITICAL("invalid message type");
} }
......
This diff is collapsed.
...@@ -60,13 +60,13 @@ void manager::detach(execution_unit*, bool invoke_disconnect_message) { ...@@ -60,13 +60,13 @@ void manager::detach(execution_unit*, bool invoke_disconnect_message) {
auto mptr = make_mailbox_element(nullptr, make_message_id(), {}, auto mptr = make_mailbox_element(nullptr, make_message_id(), {},
detach_message()); detach_message());
switch (raw_ptr->consume(*mptr)) { switch (raw_ptr->consume(*mptr)) {
case im_success: case invoke_message_result::consumed:
raw_ptr->finalize(); raw_ptr->finalize();
break; break;
case im_skipped: case invoke_message_result::skipped:
raw_ptr->push_to_cache(std::move(mptr)); raw_ptr->push_to_cache(std::move(mptr));
break; break;
case im_dropped: case invoke_message_result::dropped:
CAF_LOG_INFO("broker dropped disconnect message"); CAF_LOG_INFO("broker dropped disconnect message");
break; break;
} }
......
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