refactor(network): process all messages

This commit is contained in:
Alex 2019-04-04 11:58:27 +02:00
parent a68011bce6
commit 8351dea292
1 changed files with 15 additions and 10 deletions

View File

@ -396,21 +396,26 @@ int waybar::modules::Network::netlinkResponse(void *resp,
} }
int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) { int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
int ret = 0;
auto net = static_cast<waybar::modules::Network *>(data); auto net = static_cast<waybar::modules::Network *>(data);
bool need_update = false; bool need_update = false;
nlmsghdr *nh = nlmsg_hdr(msg); for (nlmsghdr *nh = nlmsg_hdr(msg); NLMSG_OK(nh, ret);
if (nh->nlmsg_type == RTM_NEWADDR) { nh = NLMSG_NEXT(nh, ret)) {
need_update = true; if (nh->nlmsg_type == RTM_NEWADDR) {
}
if (nh->nlmsg_type < RTM_NEWADDR) {
auto rtif = static_cast<struct ifinfomsg *>(NLMSG_DATA(nh));
if (rtif->ifi_index == static_cast<int>(net->ifid_)) {
need_update = true; need_update = true;
if (!(rtif->ifi_flags & IFF_RUNNING)) { }
net->disconnected(); if (nh->nlmsg_type < RTM_NEWADDR) {
net->dp.emit(); auto rtif = static_cast<struct ifinfomsg *>(NLMSG_DATA(nh));
if (rtif->ifi_index == static_cast<int>(net->ifid_)) {
need_update = true;
if (!(rtif->ifi_flags & IFF_RUNNING)) {
net->disconnected();
net->dp.emit();
return NL_SKIP;
}
} }
} }
if (need_update) break;
} }
if (net->ifid_ <= 0 && !net->config_["interface"].isString()) { if (net->ifid_ <= 0 && !net->config_["interface"].isString()) {
for (uint8_t i = 0; i < MAX_RETRY; i += 1) { for (uint8_t i = 0; i < MAX_RETRY; i += 1) {