diff options
author | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2017-12-14 18:56:23 +0000 |
---|---|---|
committer | Jeremie Courreges-Anglas <jca@cvs.openbsd.org> | 2017-12-14 18:56:23 +0000 |
commit | 2332e55633d35692dc649195e1ce223f26a74b0f (patch) | |
tree | 904bbdb7100237ff02b065d57ac06286381aa458 /lib | |
parent | cafb53570a19f6ebedeb5dc443f0ae8c6e520847 (diff) |
Simplify and unify timespec variables used in those event loops
ok millert@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/rpc/clnt_tcp.c | 7 | ||||
-rw-r--r-- | lib/libc/rpc/clnt_udp.c | 12 | ||||
-rw-r--r-- | lib/libc/rpc/svc_tcp.c | 13 |
3 files changed, 14 insertions, 18 deletions
diff --git a/lib/libc/rpc/clnt_tcp.c b/lib/libc/rpc/clnt_tcp.c index 462e4ef3484..4c3034fc7ca 100644 --- a/lib/libc/rpc/clnt_tcp.c +++ b/lib/libc/rpc/clnt_tcp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clnt_tcp.c,v 1.30 2017/12/14 16:55:44 jca Exp $ */ +/* $OpenBSD: clnt_tcp.c,v 1.31 2017/12/14 18:56:22 jca Exp $ */ /* * Copyright (c) 2010, Oracle America, Inc. @@ -385,7 +385,7 @@ static int readtcp(struct ct_data *ct, caddr_t buf, int len) { struct pollfd pfd[1]; - struct timespec start, after, duration, tmp, delta, wait; + struct timespec start, after, duration, delta, wait; int r, save_errno; if (len == 0) @@ -402,8 +402,7 @@ readtcp(struct ct_data *ct, caddr_t buf, int len) clock_gettime(CLOCK_MONOTONIC, &after); timespecsub(&start, &after, &duration); - timespecsub(&wait, &duration, &tmp); - delta = tmp; + timespecsub(&wait, &duration, &delta); if (delta.tv_sec < 0 || !timespecisset(&delta)) r = 0; diff --git a/lib/libc/rpc/clnt_udp.c b/lib/libc/rpc/clnt_udp.c index a90bb788fcf..87be468a564 100644 --- a/lib/libc/rpc/clnt_udp.c +++ b/lib/libc/rpc/clnt_udp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clnt_udp.c,v 1.33 2017/12/14 16:55:44 jca Exp $ */ +/* $OpenBSD: clnt_udp.c,v 1.34 2017/12/14 18:56:22 jca Exp $ */ /* * Copyright (c) 2010, Oracle America, Inc. @@ -216,7 +216,7 @@ clntudp_call(CLIENT *cl, /* client handle */ struct sockaddr_in from; struct rpc_msg reply_msg; XDR reply_xdrs; - struct timespec time_waited, start, after, tmp1, tmp2, wait; + struct timespec time_waited, start, after, duration, wait; bool_t ok; int nrefreshes = 2; /* number of times to refresh cred */ struct timespec timeout; @@ -271,8 +271,7 @@ send_again: for (;;) { switch (ppoll(pfd, 1, &wait, NULL)) { case 0: - timespecadd(&time_waited, &wait, &tmp1); - time_waited = tmp1; + timespecadd(&time_waited, &wait, &time_waited); if (timespeccmp(&time_waited, &timeout, <)) goto send_again; return (cu->cu_error.re_status = RPC_TIMEDOUT); @@ -287,9 +286,8 @@ send_again: case -1: if (errno == EINTR) { clock_gettime(CLOCK_MONOTONIC, &after); - timespecsub(&after, &start, &tmp1); - timespecadd(&time_waited, &tmp1, &tmp2); - time_waited = tmp2; + timespecsub(&after, &start, &duration); + timespecadd(&time_waited, &duration, &time_waited); if (timespeccmp(&time_waited, &timeout, <)) continue; return (cu->cu_error.re_status = RPC_TIMEDOUT); diff --git a/lib/libc/rpc/svc_tcp.c b/lib/libc/rpc/svc_tcp.c index fcecbfa7121..11d3961ee3a 100644 --- a/lib/libc/rpc/svc_tcp.c +++ b/lib/libc/rpc/svc_tcp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: svc_tcp.c,v 1.38 2017/12/14 16:55:44 jca Exp $ */ +/* $OpenBSD: svc_tcp.c,v 1.39 2017/12/14 18:56:22 jca Exp $ */ /* * Copyright (c) 2010, Oracle America, Inc. @@ -333,7 +333,7 @@ readtcp(SVCXPRT *xprt, caddr_t buf, int len) { int sock = xprt->xp_sock; int nready; - struct timespec start, delta, tmp1, tmp2; + struct timespec start, after, duration, delta; struct pollfd pfd[1]; /* @@ -350,12 +350,11 @@ readtcp(SVCXPRT *xprt, caddr_t buf, int len) case -1: if (errno != EINTR) goto fatal_err; - clock_gettime(CLOCK_MONOTONIC, &tmp1); - timespecsub(&tmp1, &start, &tmp2); - timespecsub(&wait_per_try, &tmp2, &tmp1); - if (tmp1.tv_sec < 0 || !timespecisset(&tmp1)) + clock_gettime(CLOCK_MONOTONIC, &after); + timespecsub(&after, &start, &duration); + timespecsub(&wait_per_try, &duration, &delta); + if (delta.tv_sec < 0 || !timespecisset(&delta)) goto fatal_err; - delta = tmp1; continue; case 0: goto fatal_err; |