Commit 4a61bd68 authored by Dominik Charousset's avatar Dominik Charousset

Cleanup publish() and remote_actor() impls

parent c38a1608
...@@ -35,15 +35,14 @@ namespace caf { ...@@ -35,15 +35,14 @@ namespace caf {
namespace io { namespace io {
template <class... Ts> template <class... Ts>
void publish_impl(abstract_actor_ptr whom, uint16_t port, Ts&&... args) { void publish_impl(abstract_actor_ptr whom, uint16_t port, const char* in) {
using namespace detail; using namespace detail;
auto mm = middleman::instance(); auto mm = middleman::instance();
std::promise<bool> res; std::promise<bool> res;
mm->run_later([&] { mm->run_later([&] {
auto bro = mm->get_named_broker<basp_broker>(atom("_BASP")); auto bro = mm->get_named_broker<basp_broker>(atom("_BASP"));
try { try {
auto hdl = mm->backend().add_tcp_doorman(bro.get(), port, auto hdl = mm->backend().add_tcp_doorman(bro.get(), port, in);
std::forward<Ts>(args)...);
bro->announce_published_actor(hdl, whom); bro->announce_published_actor(hdl, whom);
mm->notify<hook::actor_published>(whom->address(), port); mm->notify<hook::actor_published>(whom->address(), port);
res.set_value(true); res.set_value(true);
......
...@@ -34,62 +34,26 @@ ...@@ -34,62 +34,26 @@
namespace caf { namespace caf {
namespace io { namespace io {
/**
* Establish a new connection to a remote actor via `connection`.
* @param connection A connection to another process described by a pair
* of input and output stream.
* @returns An {@link actor_ptr} to the proxy instance
* representing a remote actor.
* @throws std::invalid_argument Thrown when connecting to a typed actor.
*/
template <class Socket>
inline actor remote_actor(Socket fd) {
auto res = remote_actor_impl(std::move(fd), std::set<std::string>{});
return actor_cast<actor>(res);
}
/** /**
* Establish a new connection to the actor at `host` on given `port`. * Establish a new connection to the actor at `host` on given `port`.
* @param host Valid hostname or IP address. * @param host Valid hostname or IP address.
* @param port TCP port. * @param port TCP port.
* @returns An {@link actor_ptr} to the proxy instance * @returns An {@link actor_ptr} to the proxy instance
* representing a remote actor. * representing a remote actor.
* @throws std::invalid_argument Thrown when connecting to a typed actor. * @throws std::invalid_argument Thrown when connecting to a typed actor.
*/ */
inline actor remote_actor(const char* host, uint16_t port) {
auto res = remote_actor_impl(std::set<std::string>{}, host, port);
return actor_cast<actor>(res);
}
/**
* @copydoc remote_actor(const char*, uint16_t)
*/
inline actor remote_actor(const std::string& host, uint16_t port) { inline actor remote_actor(const std::string& host, uint16_t port) {
auto res = remote_actor_impl(std::set<std::string>{}, host, port); auto res = remote_actor_impl(std::set<std::string>{}, host, port);
return actor_cast<actor>(res); return actor_cast<actor>(res);
} }
/** /**
* @copydoc remote_actor(stream_ptr_pair) * Establish a new connection to the typed actor at `host` on given `port`.
*/ * @param host Valid hostname or IP address.
template <class List, class Socket> * @param port TCP port.
typename typed_remote_actor_helper<List>::return_type * @returns An {@link actor_ptr} to the proxy instance
typed_remote_actor(Socket fd) { * representing a typed remote actor.
typed_remote_actor_helper<List> f; * @throws std::invalid_argument Thrown when connecting to a typed actor.
return f(std::move(fd));
}
/**
* @copydoc remote_actor(const char*,uint16_t)
*/
template <class List>
typename typed_remote_actor_helper<List>::return_type
typed_remote_actor(const char* host, uint16_t port) {
typed_remote_actor_helper<List> f;
return f(host, port);
}
/**
* @copydoc remote_actor(const std::string&,uint16_t)
*/ */
template <class List> template <class List>
typename typed_remote_actor_helper<List>::return_type typename typed_remote_actor_helper<List>::return_type
......
...@@ -40,15 +40,9 @@ ...@@ -40,15 +40,9 @@
namespace caf { namespace caf {
namespace io { namespace io {
constexpr uint32_t max_iface_size = 100;
constexpr uint32_t max_iface_clause_size = 500;
using string_set = std::set<std::string>;
template <class... Ts> template <class... Ts>
abstract_actor_ptr remote_actor_impl(const std::set<std::string>& ifs, abstract_actor_ptr remote_actor_impl(const std::set<std::string>& ifs,
Ts&&... args) { const std::string& host, uint16_t port) {
auto mm = middleman::instance(); auto mm = middleman::instance();
std::string error_msg; std::string error_msg;
std::promise<abstract_actor_ptr> result_promise; std::promise<abstract_actor_ptr> result_promise;
...@@ -57,8 +51,7 @@ abstract_actor_ptr remote_actor_impl(const std::set<std::string>& ifs, ...@@ -57,8 +51,7 @@ abstract_actor_ptr remote_actor_impl(const std::set<std::string>& ifs,
mm->run_later([&] { mm->run_later([&] {
try { try {
auto bro = mm->get_named_broker<basp_broker>(atom("_BASP")); auto bro = mm->get_named_broker<basp_broker>(atom("_BASP"));
auto hdl = mm->backend().add_tcp_scribe(bro.get(), auto hdl = mm->backend().add_tcp_scribe(bro.get(), host, port);
std::forward<Ts>(args)...);
bro->init_client(hdl, &hdata); bro->init_client(hdl, &hdata);
} }
catch (...) { catch (...) {
......
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