mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
refactor: add retry to get external interface
This commit is contained in:
parent
01cec9fcb7
commit
dc9fe04d11
@ -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*);
|
||||
|
||||
|
@ -383,9 +383,14 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
||||
}
|
||||
}
|
||||
if (net->ifid_ <= 0 && !net->config_["interface"].isString()) {
|
||||
// Need to wait before get external interface
|
||||
net->thread_.sleep_for(std::chrono::seconds(1));
|
||||
net->ifid_ = net->getExternalInterface();
|
||||
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));
|
||||
}
|
||||
if (net->ifid_ > 0) {
|
||||
char ifname[IF_NAMESIZE];
|
||||
if_indextoname(net->ifid_, ifname);
|
||||
|
Loading…
Reference in New Issue
Block a user