revert(network): wait interface

This commit is contained in:
Alexis 2018-11-24 16:01:22 +01:00
parent 8f8ec3b999
commit 08bfdda4cb

View File

@ -52,7 +52,6 @@ void waybar::modules::Network::worker()
return; return;
} }
bool need_update = false; bool need_update = false;
bool new_addr = false;
for (auto nh = reinterpret_cast<struct nlmsghdr *>(buf); NLMSG_OK(nh, len); for (auto nh = reinterpret_cast<struct nlmsghdr *>(buf); NLMSG_OK(nh, len);
nh = NLMSG_NEXT(nh, len)) { nh = NLMSG_NEXT(nh, len)) {
if (nh->nlmsg_type == NLMSG_DONE) { if (nh->nlmsg_type == NLMSG_DONE) {
@ -61,9 +60,6 @@ void waybar::modules::Network::worker()
if (nh->nlmsg_type == NLMSG_ERROR) { if (nh->nlmsg_type == NLMSG_ERROR) {
continue; continue;
} }
if (nh->nlmsg_type == RTM_NEWADDR) {
new_addr = true;
}
if (nh->nlmsg_type < RTM_NEWADDR) { if (nh->nlmsg_type < RTM_NEWADDR) {
auto rtif = static_cast<struct ifinfomsg *>(NLMSG_DATA(nh)); auto rtif = static_cast<struct ifinfomsg *>(NLMSG_DATA(nh));
if (rtif->ifi_index == static_cast<int>(ifid_)) { if (rtif->ifi_index == static_cast<int>(ifid_)) {
@ -75,15 +71,9 @@ void waybar::modules::Network::worker()
} }
} }
if (ifid_ <= 0 && !config_["interface"].isString()) { if (ifid_ <= 0 && !config_["interface"].isString()) {
if (new_addr) { // Need to wait before get external interface
// Need to wait before get external interface thread_.sleep_for(std::chrono::seconds(1));
while (ifid_ <= 0) { ifid_ = getExternalInterface();
ifid_ = getExternalInterface();
thread_.sleep_for(std::chrono::seconds(1));
}
} else {
ifid_ = getExternalInterface();
}
if (ifid_ > 0) { if (ifid_ > 0) {
char ifname[IF_NAMESIZE]; char ifname[IF_NAMESIZE];
if_indextoname(ifid_, ifname); if_indextoname(ifid_, ifname);