From f21ff48a8495a07bd04de76d395d7512f3cb7941 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 5 Apr 2018 18:56:09 +0200 Subject: [PATCH] platform/tests: extend nmtstp_wait_for_link*() to never wait Previously, it was not (reliably) possible to use nmtstp_wait_for_link*() to only look into the platform cache, without trying to poll the netlink socket for events. Add this option. Now, if the timeout is specified as zero, we never actually read the netlink socket. Currently, there are no callers who make use of this (by passing a zero timeout). So, this is no change in existing behavior. --- src/platform/tests/test-common.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c index c480fb74a2..f54c0dd4c1 100644 --- a/src/platform/tests/test-common.c +++ b/src/platform/tests/test-common.c @@ -628,7 +628,10 @@ nmtstp_wait_for_signal_until (NMPlatform *platform, gint64 until_ms) const NMPlatformLink * nmtstp_wait_for_link (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, gint64 timeout_ms) { - return nmtstp_wait_for_link_until (platform, ifname, expected_link_type, nm_utils_get_monotonic_timestamp_ms () + timeout_ms); + return nmtstp_wait_for_link_until (platform, ifname, expected_link_type, + timeout_ms + ? nm_utils_get_monotonic_timestamp_ms () + timeout_ms + : 0); } const NMPlatformLink * @@ -636,6 +639,7 @@ nmtstp_wait_for_link_until (NMPlatform *platform, const char *ifname, NMLinkType { const NMPlatformLink *plink; gint64 now; + gboolean waited_once = FALSE; _init_platform (&platform, FALSE); @@ -647,9 +651,20 @@ nmtstp_wait_for_link_until (NMPlatform *platform, const char *ifname, NMLinkType && (expected_link_type == NM_LINK_TYPE_NONE || plink->type == expected_link_type)) return plink; - if (until_ms < now) + if (until_ms == 0) { + /* don't wait, don't even poll the socket. */ return NULL; + } + if ( waited_once + && until_ms < now) { + /* timeout reached (+ we already waited for a signal at least once). */ + return NULL; + } + + waited_once = TRUE; + /* regardless of whether timeout is already reached, we poll the netlink + * socket a bit. */ nmtstp_wait_for_signal (platform, until_ms - now); } }