From 8351dea2922eb4b24c3bca359d13c48a0e4b189a Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 4 Apr 2019 11:58:27 +0200 Subject: [PATCH] refactor(network): process all messages --- src/modules/network.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/modules/network.cpp b/src/modules/network.cpp index 6aaff778..36587e66 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -396,21 +396,26 @@ int waybar::modules::Network::netlinkResponse(void *resp, } int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) { + int ret = 0; auto net = static_cast(data); bool need_update = false; - nlmsghdr *nh = nlmsg_hdr(msg); - if (nh->nlmsg_type == RTM_NEWADDR) { - need_update = true; - } - if (nh->nlmsg_type < RTM_NEWADDR) { - auto rtif = static_cast(NLMSG_DATA(nh)); - if (rtif->ifi_index == static_cast(net->ifid_)) { + for (nlmsghdr *nh = nlmsg_hdr(msg); NLMSG_OK(nh, ret); + nh = NLMSG_NEXT(nh, ret)) { + if (nh->nlmsg_type == RTM_NEWADDR) { need_update = true; - if (!(rtif->ifi_flags & IFF_RUNNING)) { - net->disconnected(); - net->dp.emit(); + } + if (nh->nlmsg_type < RTM_NEWADDR) { + auto rtif = static_cast(NLMSG_DATA(nh)); + if (rtif->ifi_index == static_cast(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()) { for (uint8_t i = 0; i < MAX_RETRY; i += 1) {