]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
round robin listeners among network threads
authorAlan T. DeKok <aland@freeradius.org>
Fri, 24 Jul 2020 15:07:40 +0000 (11:07 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 24 Jul 2020 15:07:58 +0000 (11:07 -0400)
src/lib/io/schedule.c

index bf404d6d25f36be0f795dcc7dc444b648f9792b5..9355a258917e209aade6f0927251bc969e58e743 100644 (file)
@@ -146,6 +146,8 @@ struct fr_schedule_s {
 
        fr_network_t    *single_network;        //!< for single-threaded mode
        fr_worker_t     *single_worker;         //!< for single-threaded mode
+
+       fr_network_t    *last;                  //!< for round robin selection of networks
 };
 
 static _Thread_local int worker_id;            //!< Internal ID of the current worker thread.
@@ -831,14 +833,18 @@ fr_network_t *fr_schedule_listen_add(fr_schedule_t *sc, fr_listen_t *li)
        if (sc->el) {
                nr = sc->single_network;
        } else {
-               fr_schedule_network_t *sn;
+               /*
+                *      This may walk off of the end of the list.
+                */
+               if (sc->last) sc->last = fr_dlist_next(&sc->networks, sc->last);
 
                /*
-                *      @todo - round robin it among the listeners?
-                *      or maybe add it to the same parent thread?
+                *      If we did walk off of the end of the list, go
+                *      back to the first one again.
                 */
-               sn = fr_dlist_head(&sc->networks);
-               nr = sn->nr;
+               if (!sc->last) sc->last = fr_dlist_head(&sc->networks);
+
+               nr = sc->last;
        }
 
        if (fr_network_listen_add(nr, li) < 0) return NULL;