refactor: add retry to get external interface

pull/178/head
Alex 2019-02-06 10:33:12 +01:00
parent 01cec9fcb7
commit dc9fe04d11
2 changed files with 10 additions and 3 deletions

View File

@ -20,6 +20,8 @@ class Network : public ALabel {
~Network();
auto update() -> void;
private:
static const uint8_t MAX_RETRY = 10;
static int handleEvents(struct nl_msg*, void*);
static int handleScan(struct nl_msg*, void*);

View File

@ -383,9 +383,14 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
}
}
if (net->ifid_ <= 0 && !net->config_["interface"].isString()) {
for (uint8_t i = 0; i < MAX_RETRY; i += 1) {
net->ifid_ = net->getExternalInterface();
if (net->ifid_ > 0) {
break;
}
// Need to wait before get external interface
net->thread_.sleep_for(std::chrono::seconds(1));
net->ifid_ = net->getExternalInterface();
}
if (net->ifid_ > 0) {
char ifname[IF_NAMESIZE];
if_indextoname(net->ifid_, ifname);