* the recipient can call the normal fr_message_done() function to
* free it.
*
- * @param[in] ms the message set
- * @param[in] m the message to be localized
* @param[in] ctx the talloc context to use for localization
+ * @param[in] m the message to be localized
+ * @param[in] message_size the size of the message, including the fr_message_t
* @return
* - NULL on allocation errror
* - a newly localized message
*/
-fr_message_t *fr_message_localize(fr_message_set_t *ms, fr_message_t *m, TALLOC_CTX *ctx)
+fr_message_t *fr_message_localize(TALLOC_CTX *ctx, fr_message_t *m, size_t message_size)
{
fr_message_t *l;
-#ifndef NDEBUG
- (void) talloc_get_type_abort(ms, fr_message_set_t);
-#endif
-
if (m->status != FR_MESSAGE_USED) {
return NULL;
}
- l = talloc_memdup(ctx, m, ms->message_size);
+ if (message_size <= sizeof(fr_message_t)) return NULL;
+
+ l = talloc_memdup(ctx, m, message_size);
if (!l) return NULL;
if (l->data_size) {
* @param[in] mr the message ring
* @param[in] max_to_clean maximum number of messages to clean at a time.
*/
-static int fr_message_ring_cleanup(fr_message_set_t *ms, fr_message_ring_t *mr, int max_to_clean)
+static int fr_message_ring_gc(fr_message_set_t *ms, fr_message_ring_t *mr, int max_to_clean)
{
int i;
int messages_cleaned = 0;
}
-/** Clean up "done" messages.
+/** Garbage collect "done" messages.
*
* Called only from the originating thread. We also clean a limited
* number of messages at a time, so that we don't have sudden latency
* @param[in] ms the message set
* @param[in] max_to_clean the maximum number of messages to clean
*/
-static void fr_message_cleanup(fr_message_set_t *ms, int max_to_clean)
+static void fr_message_gc(fr_message_set_t *ms, int max_to_clean)
{
int i;
int arrays_freed, empty_slot;
fr_message_ring_t *mr = ms->mr_array[i];
- (void) fr_message_ring_cleanup(ms, mr, max_to_clean);
+ (void) fr_message_ring_gc(ms, mr, max_to_clean);
/*
* If the message ring buffer is empty, check if
used += (mr->data_end - mr->data_start);
if (used >= mr->size) {
- if (fr_message_ring_cleanup(ms, mr, 4) == 0) {
+ if (fr_message_ring_gc(ms, mr, 4) == 0) {
return NULL;
}
/*
* Else the buffer is full. Do a global cleanup.
*/
- fr_message_cleanup(ms, 128);
+ fr_message_gc(ms, 128);
*p_cleaned = true;
/*
MPRINT("CLEANED UP BECAUSE OF RING BUFFER (%zd - %zd = %zd)\n", ms->allocated, ms->freed,
ms->allocated - ms->freed);
- fr_message_cleanup(ms, 128);
+ fr_message_gc(ms, 128);
/*
* Try to allocate the packet from the newly current ring buffer.
*/
num_cleaned = 0;
for (i = 0; i <= ms->mr_max; i++) {
- num_cleaned += fr_message_ring_cleanup(ms, ms->mr_array[i],
- ms->mr_array[i]->size);
+ num_cleaned += fr_message_ring_gc(ms, ms->mr_array[i],
+ ms->mr_array[i]->size);
}
MPRINT("GC cleaned %d\n", num_cleaned);
/*
* And then do one last pass to clean up the arrays.
*/
- fr_message_cleanup(ms, 1 << 24);
+ fr_message_gc(ms, 1 << 24);
}
/** Print debug information about the message set.