return usec_add(now(CLOCK_MONOTONIC), usec);
}
-static int rtnl_poll(sd_netlink *rtnl, bool need_more, uint64_t timeout_usec) {
+static int rtnl_poll(sd_netlink *rtnl, bool need_more, usec_t timeout_usec) {
usec_t m = USEC_INFINITY;
int r, e;
e |= POLLIN;
else {
usec_t until;
+
/* Caller wants to process if there is something to
* process, but doesn't care otherwise */
r = sd_netlink_get_timeout(rtnl, &until);
if (r < 0)
return r;
- if (r > 0) {
- usec_t nw;
- nw = now(CLOCK_MONOTONIC);
- m = until > nw ? until - nw : 0;
- }
- }
- if (timeout_usec != UINT64_MAX && (m == USEC_INFINITY || timeout_usec < m))
- m = timeout_usec;
+ m = usec_sub_unsigned(until, now(CLOCK_MONOTONIC));
+ }
- r = fd_wait_for_event(rtnl->fd, e, m);
+ r = fd_wait_for_event(rtnl->fd, e, MIN(m, timeout_usec));
if (r <= 0)
return r;
if (n >= timeout)
return -ETIMEDOUT;
- left = timeout - n;
+ left = usec_sub_unsigned(timeout, n);
} else
- left = UINT64_MAX;
+ left = USEC_INFINITY;
r = rtnl_poll(rtnl, true, left);
if (r < 0)