Simplify and unify timespec variables used in those event loops
authorjca <jca@openbsd.org>
Thu, 14 Dec 2017 18:56:22 +0000 (18:56 +0000)
committerjca <jca@openbsd.org>
Thu, 14 Dec 2017 18:56:22 +0000 (18:56 +0000)
ok millert@

lib/libc/rpc/clnt_tcp.c
lib/libc/rpc/clnt_udp.c
lib/libc/rpc/svc_tcp.c

index 462e4ef..4c3034f 100644 (file)
@@ -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;
 
index a90bb78..87be468 100644 (file)
@@ -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);
index fcecbfa..11d3961 100644 (file)
@@ -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;