]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Modify dns_dispatch API to accept zero timeout
authorOndřej Surý <ondrej@isc.org>
Fri, 20 Sep 2024 13:13:09 +0000 (15:13 +0200)
committerOndřej Surý <ondrej@isc.org>
Sat, 21 Sep 2024 08:53:25 +0000 (08:53 +0000)
The dns_dispatch_add() has timeout parameter that could not be 0 (for
not timeout).  Modify the dns_dispatch implementation to accept a zero
timeout for cases where the timeouts are undesirable because they are
managed externally.

(cherry picked from commit 0f810b3144866f45413c109275210637e4425432)

lib/dns/dispatch.c

index e5412abe9eb455ebac686329d73a94a45abd4d2c..9cc27e5a752daec983fbc81596ab027d3c5d2828 100644 (file)
@@ -593,15 +593,18 @@ next:
         * time to wait for the correct one to arrive before the timeout fires.
         */
        now = isc_loop_now(resp->loop);
-       timeout = resp->timeout - dispentry_runtime(resp, &now);
-       if (timeout <= 0) {
-               /*
-                * The time window for receiving the correct response is
-                * already closed, libuv has just not processed the socket
-                * timer yet.  Invoke the read callback, indicating a timeout.
-                */
-               eresult = ISC_R_TIMEDOUT;
-               goto done;
+       if (resp->timeout > 0) {
+               timeout = resp->timeout - dispentry_runtime(resp, &now);
+               if (timeout <= 0) {
+                       /*
+                        * The time window for receiving the correct response is
+                        * already closed, libuv has just not processed the
+                        * socket timer yet.  Invoke the read callback,
+                        * indicating a timeout.
+                        */
+                       eresult = ISC_R_TIMEDOUT;
+                       goto done;
+               }
        }
 
        /*
@@ -774,7 +777,7 @@ tcp_recv(isc_nmhandle_t *handle, isc_result_t result, isc_region_t *region,
        isc_sockaddr_t peer;
        dns_displist_t resps = ISC_LIST_INITIALIZER;
        isc_time_t now;
-       int timeout;
+       int timeout = 0;
 
        REQUIRE(VALID_DISPATCH(disp));
 
@@ -837,9 +840,11 @@ tcp_recv(isc_nmhandle_t *handle, isc_result_t result, isc_region_t *region,
        while (resp != NULL) {
                dns_dispentry_t *next = ISC_LIST_NEXT(resp, alink);
 
-               timeout = resp->timeout - dispentry_runtime(resp, &now);
-               if (timeout <= 0) {
-                       tcp_recv_add(&resps, resp, ISC_R_TIMEDOUT);
+               if (resp->timeout > 0) {
+                       timeout = resp->timeout - dispentry_runtime(resp, &now);
+                       if (timeout <= 0) {
+                               tcp_recv_add(&resps, resp, ISC_R_TIMEDOUT);
+                       }
                }
 
                resp = next;
@@ -879,10 +884,14 @@ tcp_recv(isc_nmhandle_t *handle, isc_result_t result, isc_region_t *region,
         */
        resp = ISC_LIST_HEAD(disp->active);
        if (resp != NULL) {
-               timeout = resp->timeout - dispentry_runtime(resp, &now);
-               INSIST(timeout > 0);
+               if (resp->timeout > 0) {
+                       timeout = resp->timeout - dispentry_runtime(resp, &now);
+                       INSIST(timeout > 0);
+               }
                tcp_startrecv(disp, resp);
-               isc_nmhandle_settimeout(handle, timeout);
+               if (timeout > 0) {
+                       isc_nmhandle_settimeout(handle, timeout);
+               }
        }
 
        rcu_read_unlock();
@@ -1523,14 +1532,16 @@ dns_dispatch_getnext(dns_dispentry_t *resp) {
 
        dns_dispatch_t *disp = resp->disp;
        isc_result_t result = ISC_R_SUCCESS;
-       int32_t timeout = -1;
+       int32_t timeout = 0;
 
        dispentry_log(resp, ISC_LOG_DEBUG(90), "getnext for QID %d", resp->id);
 
-       isc_time_t now = isc_loop_now(resp->loop);
-       timeout = resp->timeout - dispentry_runtime(resp, &now);
-       if (timeout <= 0) {
-               return (ISC_R_TIMEDOUT);
+       if (resp->timeout > 0) {
+               isc_time_t now = isc_loop_now(resp->loop);
+               timeout = resp->timeout - dispentry_runtime(resp, &now);
+               if (timeout <= 0) {
+                       return (ISC_R_TIMEDOUT);
+               }
        }
 
        REQUIRE(disp->tid == isc_tid());