mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
sd-netlink: use usec_sub_unsigned() and USEC_INFINITY
And shorten code more.
This commit is contained in:
parent
2b01228800
commit
11537375e3
@ -525,7 +525,7 @@ static usec_t calc_elapse(uint64_t usec) {
|
|||||||
return usec_add(now(CLOCK_MONOTONIC), usec);
|
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;
|
usec_t m = USEC_INFINITY;
|
||||||
int r, e;
|
int r, e;
|
||||||
|
|
||||||
@ -541,23 +541,18 @@ static int rtnl_poll(sd_netlink *rtnl, bool need_more, uint64_t timeout_usec) {
|
|||||||
e |= POLLIN;
|
e |= POLLIN;
|
||||||
else {
|
else {
|
||||||
usec_t until;
|
usec_t until;
|
||||||
|
|
||||||
/* Caller wants to process if there is something to
|
/* Caller wants to process if there is something to
|
||||||
* process, but doesn't care otherwise */
|
* process, but doesn't care otherwise */
|
||||||
|
|
||||||
r = sd_netlink_get_timeout(rtnl, &until);
|
r = sd_netlink_get_timeout(rtnl, &until);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
if (r > 0) {
|
|
||||||
usec_t nw;
|
m = usec_sub_unsigned(until, now(CLOCK_MONOTONIC));
|
||||||
nw = now(CLOCK_MONOTONIC);
|
|
||||||
m = until > nw ? until - nw : 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeout_usec != UINT64_MAX && (m == USEC_INFINITY || timeout_usec < m))
|
r = fd_wait_for_event(rtnl->fd, e, MIN(m, timeout_usec));
|
||||||
m = timeout_usec;
|
|
||||||
|
|
||||||
r = fd_wait_for_event(rtnl->fd, e, m);
|
|
||||||
if (r <= 0)
|
if (r <= 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
@ -716,9 +711,9 @@ int sd_netlink_read(
|
|||||||
if (n >= timeout)
|
if (n >= timeout)
|
||||||
return -ETIMEDOUT;
|
return -ETIMEDOUT;
|
||||||
|
|
||||||
left = timeout - n;
|
left = usec_sub_unsigned(timeout, n);
|
||||||
} else
|
} else
|
||||||
left = UINT64_MAX;
|
left = USEC_INFINITY;
|
||||||
|
|
||||||
r = rtnl_poll(rtnl, true, left);
|
r = rtnl_poll(rtnl, true, left);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user