]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
clear pending flags as necessary
authorAlan T. DeKok <aland@freeradius.org>
Thu, 27 Jul 2017 13:29:43 +0000 (09:29 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 27 Jul 2017 13:29:43 +0000 (09:29 -0400)
src/modules/rlm_radius/rlm_radius_udp.c

index 55ffd108598ecb95ba44b7e335665efe7ded779a..0df26cb58e506611aa1453ad5b5be4907a173fe0 100644 (file)
@@ -293,6 +293,7 @@ static void conn_writable(fr_event_list_t *el, int fd, UNUSED int flags, void *u
 {
        rlm_radius_udp_connection_t *c = talloc_get_type_abort(uctx, rlm_radius_udp_connection_t);
        fr_dlist_t *entry, *next;
+       bool pending;
 
        /*
         *      Clear our backlog
@@ -342,26 +343,27 @@ static void conn_writable(fr_event_list_t *el, int fd, UNUSED int flags, void *u
        /*
         *      Check if we have to enable or disable writing on the socket.
         */
-       entry = FR_DLIST_FIRST(c->queued);
-       if (!entry) {
-               c->pending = false;
-               fd_idle(c);
-
-       } else if (!c->pending) {
+       pending = ((entry = FR_DLIST_FIRST(c->queued)) != NULL);
+       if (!pending && c->pending) {
                /*
-                *      This check is here only for mod_push(), which
-                *      calls us when there are no packets pending on
-                *      a socket.  If the connection is writable, and
-                *      the write succeeds, and there's nothing more
-                *      to write, we don't need to call fd_active().
+                *      The queue is empty, and we apparently just
+                *      emptied it.  Set the FD to idle.
                 */
-               c->pending = true;
-               fd_active(c);
+               c->pending = false;
+               fd_idle(c);
        }
 
        /*
-        *      Else c->pending was already set, and we already have fd_active().
+        *      This check is here only for mod_push(), which
+        *      calls us when there are no packets pending on
+        *      a socket.  If the connection is writable, and
+        *      the write succeeds, and there's nothing more
+        *      to write, we don't need to call fd_active().
         */
+       else if (pending && !c->pending) {
+               c->pending = true;
+               fd_active(c);
+       }
 }
 
 /** Shutdown/close a file descriptor
@@ -633,6 +635,11 @@ static void mod_clear_backlog(rlm_radius_udp_thread_t *t)
                        fd_active(c);
                }
        }
+
+       /*
+        *      Update the pending flag.
+        */
+       t->pending = ((entry = FR_DLIST_FIRST(t->queued)) != NULL);
 }
 
 
@@ -827,6 +834,7 @@ static int mod_thread_detach(void *thread)
                ERROR("There are still queued requests");
                return -1;
        }
+       rad_assert(t->pending == false);
 
        /*
         *      Free all of the sockets.