]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add fr_network_pre_event()
authorAlan T. DeKok <aland@freeradius.org>
Wed, 3 Oct 2018 13:14:09 +0000 (09:14 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 3 Oct 2018 15:13:48 +0000 (11:13 -0400)
in order to get the event loop to run through it's work again.
so that the network side can say "hey, there's work to do!"
and then go do it.

src/lib/io/network.c

index 773bb860b305780236fd0c0b5f3fbebe0d104659..e47271b06d89f8025a82834cf093e3aabc2b8503 100644 (file)
@@ -135,6 +135,7 @@ struct fr_network_t {
 };
 
 static void fr_network_post_event(fr_event_list_t *el, struct timeval *now, void *uctx);
+static int fr_network_pre_event(void *ctx, struct timeval *wake);
 
 static int reply_cmp(void const *one, void const *two)
 {
@@ -233,8 +234,6 @@ static void fr_network_recv_reply(void *ctx, fr_channel_t *ch, fr_channel_data_t
        }
 
        (void) fr_heap_insert(nr->replies, cd);
-
-       (void) fr_network_post_event(nr->el, NULL, nr);
 }
 
 /** Handle a network control message callback for a channel
@@ -1080,6 +1079,11 @@ fr_network_t *fr_network_create(TALLOC_CTX *ctx, fr_event_list_t *el, fr_log_t c
                goto fail2;
        }
 
+       if (fr_event_pre_insert(nr->el, fr_network_pre_event, nr) < 0) {
+               fr_strerror_printf("Failed adding pre-check to event list");
+               goto fail2;
+       }
+
        if (fr_event_post_insert(nr->el, fr_network_post_event, nr) < 0) {
                fr_strerror_printf("Failed inserting post-processing event");
                goto fail2;
@@ -1128,6 +1132,7 @@ int fr_network_destroy(fr_network_t *nr)
                fr_message_done(&cd->m);
        }
 
+       (void) fr_event_pre_delete(nr->el, fr_network_pre_event, nr);
        (void) fr_event_post_delete(nr->el, fr_network_post_event, nr);
 
        /*
@@ -1137,6 +1142,26 @@ int fr_network_destroy(fr_network_t *nr)
        return 0;
 }
 
+/** Run the event loop 'pre' callback
+ *
+ *  This function MUST DO NO WORK.  All it does is check if there's
+ *  work, and tell the event code to return to the main loop if
+ *  there's work to do.
+ *
+ * @param[in] ctx the network
+ * @param[in] wake the time when the event loop will wake up.
+ */
+static int fr_network_pre_event(void *ctx, UNUSED struct timeval *wake)
+{
+       fr_network_t *nr = talloc_get_type_abort(ctx, fr_network_t);
+
+       if (fr_heap_num_elements(nr->replies) > 0) {
+               return 1;
+       }
+
+       return 0;
+}
+
 /** Handle replies after all FD and timer events have been serviced
  *
  * @param el   the event loop