Commit b0a4fdff authored by Dominik Charousset's avatar Dominik Charousset

Properly handle incoming connections from self

parent 3a5d23d8
...@@ -347,6 +347,13 @@ basp_broker::handle_basp_header(connection_context& ctx, ...@@ -347,6 +347,13 @@ basp_broker::handle_basp_header(connection_context& ctx,
return close_connection; return close_connection;
} }
auto nid = ctx.handshake_data->remote_id; auto nid = ctx.handshake_data->remote_id;
if (nid == node()) {
CAF_LOG_INFO("incoming connection from self: drop connection");
auto res = detail::singletons::get_actor_registry()->get(remote_aid);
ctx.handshake_data->result->set_value(std::move(res));
ctx.handshake_data = nullptr;
return close_connection;
}
if (!try_set_default_route(nid, ctx.hdl)) { if (!try_set_default_route(nid, ctx.hdl)) {
CAF_LOG_INFO("multiple connections to " CAF_LOG_INFO("multiple connections to "
<< to_string(nid) << to_string(nid)
......
...@@ -319,6 +319,8 @@ void test_remote_actor(std::string app_path, bool run_remote_actor) { ...@@ -319,6 +319,8 @@ void test_remote_actor(std::string app_path, bool run_remote_actor) {
do { do {
try { try {
io::publish(serv, port, "127.0.0.1"); io::publish(serv, port, "127.0.0.1");
auto serv2 = io::remote_actor("127.0.0.1", port);
CAF_CHECK(serv == serv2);
success = true; success = true;
CAF_PRINT("running on port " << port); CAF_PRINT("running on port " << port);
CAF_LOGF_INFO("running on port " << port); CAF_LOGF_INFO("running on port " << port);
...@@ -391,7 +393,10 @@ int main(int argc, char** argv) { ...@@ -391,7 +393,10 @@ int main(int argc, char** argv) {
CAF_PRINT("don't run remote actor (server mode)"); CAF_PRINT("don't run remote actor (server mode)");
test_remote_actor(argv[0], false); test_remote_actor(argv[0], false);
}, },
on() >> [&] { test_remote_actor(argv[0], true); }, others() >> [&] { on() >> [&] {
test_remote_actor(argv[0], true);
},
others() >> [&] {
CAF_PRINTERR("usage: " << argv[0] << " [-s|-c PORT]"); CAF_PRINTERR("usage: " << argv[0] << " [-s|-c PORT]");
} }
}); });
......
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