Skip to content
Snippets Groups Projects
Commit e2027c94 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Add net phasing

parent 625e9886
No related branches found
No related tags found
No related merge requests found
Pipeline #12387 passed
......@@ -216,6 +216,7 @@ class Universe : public ftl::Configurable {
ftl::net::Dispatcher disp_;
std::thread thread_;
std::list<ReconnectInfo> reconnects_;
size_t phase_;
struct ConnHandler {
callback_t id;
......
......@@ -24,12 +24,12 @@ using ftl::net::callback_t;
callback_t ftl::net::Universe::cbid__ = 0;
Universe::Universe() : Configurable(), active_(true), this_peer(ftl::net::this_peer), thread_(Universe::__start, this) {
Universe::Universe() : Configurable(), active_(true), this_peer(ftl::net::this_peer), thread_(Universe::__start, this), phase_(0) {
_installBindings();
}
Universe::Universe(nlohmann::json &config) :
Configurable(config), active_(true), this_peer(ftl::net::this_peer), thread_(Universe::__start, this) {
Configurable(config), active_(true), this_peer(ftl::net::this_peer), thread_(Universe::__start, this), phase_(0) {
_installBindings();
}
......@@ -305,7 +305,9 @@ void Universe::_run() {
SHARED_LOCK(net_mutex_, lk);
// Also check each clients socket to see if any messages or errors are waiting
for (auto s : peers_) {
for (size_t p=0; p<peers_.size(); ++p) {
auto s = peers_[(p+phase_)%peers_.size()];
if (s != NULL && s->isValid()) {
// Note: It is possible that the socket becomes invalid after check but before
// looking at the FD sets, therefore cache the original socket
......@@ -323,6 +325,7 @@ void Universe::_run() {
}
}
}
++phase_;
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment