Skip to content

Commit

Permalink
add fr_network_pre_event()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alandekok committed Oct 3, 2018
1 parent f956d44 commit 61fd200
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/lib/io/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

/*
Expand All @@ -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
Expand Down

0 comments on commit 61fd200

Please sign in to comment.