Commit b7e99c51 authored by Joseph Noir's avatar Joseph Noir

Adapt to middleman actor behavior accepting URIs

parent 8c140ab5
......@@ -93,8 +93,7 @@ struct state {
behavior unconnected(stateful_actor<state>*);
// prototype definition for transition to `connecting` with Host and Port
void connecting(stateful_actor<state>*,
const std::string& host, uint16_t port);
void connecting(stateful_actor<state>*, io::uri);
// prototype definition for transition to `running` with Calculator
behavior running(stateful_actor<state>*, actor calculator);
......@@ -121,27 +120,28 @@ behavior unconnected(stateful_actor<state>* self) {
self->state.tasks.emplace_back(task{op, x, y});
},
[=](connect_atom, const std::string& host, uint16_t port) {
connecting(self, host, port);
auto u = io::uri::make("tcp://" + host + std::to_string(port));
if (!u)
throw sec::invalid_argument;
connecting(self, std::move(*u));
}
};
}
void connecting(stateful_actor<state>* self,
const std::string& host, uint16_t port) {
void connecting(stateful_actor<state>* self, io::uri u) {
// make sure we are not pointing to an old server
self->state.current_server = nullptr;
// use request().await() to suspend regular behavior until MM responded
auto mm = self->system().middleman().actor_handle();
self->request(mm, infinite, connect_atom::value, host, port).await(
self->request(mm, infinite, connect_atom::value, u).await(
[=](const node_id&, strong_actor_ptr serv, const std::set<std::string>& ifs) {
if (!serv) {
aout(self) << "*** no server found at \"" << host << "\":"
<< port << endl;
aout(self) << "*** no server found at \"" << u << endl;
return;
}
if (!ifs.empty()) {
aout(self) << "*** typed actor found at \"" << host << "\":"
<< port << ", but expected an untyped actor "<< endl;
aout(self) << "*** typed actor found at \"" << u
<< ", but expected an untyped actor "<< endl;
return;
}
aout(self) << "*** successfully connected to server" << endl;
......@@ -151,8 +151,8 @@ void connecting(stateful_actor<state>* self,
self->become(running(self, hdl));
},
[=](const error& err) {
aout(self) << "*** cannot connect to \"" << host << "\":"
<< port << " => " << self->system().render(err) << endl;
aout(self) << "*** cannot connect to \"" << u
<< " => " << self->system().render(err) << endl;
self->become(unconnected(self));
}
);
......@@ -183,7 +183,10 @@ behavior running(stateful_actor<state>* self, actor calculator) {
send_task(task{op, x, y});
},
[=](connect_atom, const std::string& host, uint16_t port) {
connecting(self, host, port);
auto u = io::uri::make("tcp://" + host + std::to_string(port));
if (!u)
throw sec::invalid_argument;
connecting(self, std::move(*u));
}
};
}
......
......@@ -575,13 +575,15 @@ CAF_TEST(publish_and_connect) {
CAF_TEST(remote_actor_and_send) {
constexpr const char* lo = "localhost";
constexpr uint16_t port = 4242;
auto u = uri::make("tcp://" + std::string(lo) + ":" + std::to_string(port));
CAF_REQUIRE(u);
CAF_MESSAGE("self: " << to_string(self()->address()));
mpx()->provide_scribe(lo, 4242, jupiter().connection);
CAF_REQUIRE(mpx()->has_pending_scribe(lo, 4242));
auto mm1 = system.middleman().actor_handle();
actor result;
auto f = self()->request(mm1, infinite,
connect_atom::value, lo, uint16_t{4242});
auto f = self()->request(mm1, infinite, connect_atom::value, *u);
// wait until BASP broker has received and processed the connect message
while (!aut()->valid(jupiter().connection))
mpx()->exec_runnable();
......
......@@ -73,9 +73,8 @@ struct fixture {
actor result;
scoped_actor self{system, true};
auto host = std::string(u.host().first, u.host().second);
auto port = u.port_as_int();
self->request(system.middleman().actor_handle(), infinite,
connect_atom::value, host, port).receive(
connect_atom::value, u).receive(
[&](node_id&, strong_actor_ptr& res, std::set<std::string>& xs) {
CAF_REQUIRE(xs.empty());
if (res)
......
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