Commit 56c070ba authored by Dominik Charousset's avatar Dominik Charousset Committed by Dominik Charousset

Allow send/anon_send to strong_actor_ptr

parent 3e2ac362
......@@ -22,15 +22,19 @@
#include <tuple>
#include <chrono>
#include "caf/fwd.hpp"
#include "caf/actor.hpp"
#include "caf/message.hpp"
#include "caf/actor_cast.hpp"
#include "caf/actor_control_block.hpp"
#include "caf/check_typed_input.hpp"
#include "caf/duration.hpp"
#include "caf/no_stages.hpp"
#include "caf/response_type.hpp"
#include "caf/response_handle.hpp"
#include "caf/fwd.hpp"
#include "caf/message.hpp"
#include "caf/message_priority.hpp"
#include "caf/check_typed_input.hpp"
#include "caf/response_handle.hpp"
#include "caf/response_type.hpp"
namespace caf {
namespace mixin {
......@@ -52,10 +56,7 @@ public:
// -- send function family ---------------------------------------------------
/// Sends `{xs...}` as a synchronous message to `dest` with priority `mp`.
/// @warning The returned handle is actor specific and the response to the
/// sent message cannot be received by another actor.
/// @throws std::invalid_argument if `dest == invalid_actor`
/// Sends `{xs...}` as an asynchronous message to `dest` with priority `mp`.
template <message_priority P = message_priority::normal,
class Dest = actor, class... Ts>
void send(const Dest& dest, Ts&&... xs) {
......@@ -77,11 +78,25 @@ public:
typename res_t::type
>::valid,
"this actor does not accept the response message");
if (dest)
if (dest != nullptr)
dest->eq_impl(make_message_id(P), dptr()->ctrl(),
dptr()->context(), std::forward<Ts>(xs)...);
}
/// Sends `{xs...}` as an asynchronous message to `dest` with priority `mp`.
template <message_priority P = message_priority::normal, class... Ts>
void send(const strong_actor_ptr& dest, Ts&&... xs) {
using detail::type_list;
static_assert(sizeof...(Ts) > 0, "no message to send");
static_assert(!statically_typed<Subtype>(),
"statically typed actors can only send() to other "
"statically typed actors; use anon_send() or request() when "
"communicating with dynamically typed actors");
if (dest != nullptr)
dest->get()->eq_impl(make_message_id(P), dptr()->ctrl(),
dptr()->context(), std::forward<Ts>(xs)...);
}
template <message_priority P = message_priority::normal,
class Source = actor, class Dest = actor, class... Ts>
void anon_send(const Dest& dest, Ts&&... xs) {
......
......@@ -102,11 +102,20 @@ void anon_send(const Dest& dest, Ts&&... xs) {
using token = detail::type_list<detail::strip_and_convert_t<Ts>...>;
static_assert(response_type_unbox<signatures_of_t<Dest>, token>::valid,
"receiver does not accept given message");
if (dest)
if (dest != nullptr)
dest->eq_impl(make_message_id(P), nullptr, nullptr,
std::forward<Ts>(xs)...);
}
/// Anonymously sends `dest` a message.
template <message_priority P = message_priority::normal, class... Ts>
void anon_send(const strong_actor_ptr& dest, Ts&&... xs) {
static_assert(sizeof...(Ts) > 0, "no message to send");
if (dest != nullptr)
dest->get()->eq_impl(make_message_id(P), nullptr, nullptr,
std::forward<Ts>(xs)...);
}
/// Anonymously sends `dest` an exit message.
template <class Dest>
void anon_send_exit(const Dest& dest, exit_reason reason) {
......
......@@ -85,7 +85,7 @@ void inbound_path::emit_irregular_shutdown(local_actor* self,
stream_slots slots,
const strong_actor_ptr& hdl,
error reason) {
CAF_LOG_TRACE(CAF_ARG(slot) << CAF_ARG(hdl) << CAF_ARG(reason));
CAF_LOG_TRACE(CAF_ARG(slots) << CAF_ARG(hdl) << CAF_ARG(reason));
unsafe_send_as(
self, hdl,
make<upstream_msg::forced_drop>(slots, self->address(), std::move(reason)));
......
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