25#include <freeradius-devel/bio/bio_priv.h>
26#include <freeradius-devel/bio/queue.h>
27#include <freeradius-devel/bio/null.h>
90 if (fr_bio_queue_list_num_elements(&my->pending) == 0)
return;
95 while ((
item = fr_bio_queue_list_pop_head(&my->pending)) != NULL) {
97 item->cancelled =
true;
98 fr_bio_queue_list_insert_head(&my->free,
item);
120 item = fr_bio_queue_list_pop_head(&my->free);
128 fr_assert((fr_bio_queue_list_num_elements(&my->pending) == 0) ||
129 (already_written == 0));
134 item->already_written = already_written;
135 item->cancelled =
false;
137 fr_bio_queue_list_insert_tail(&my->pending,
item);
157 fr_assert(fr_bio_queue_list_num_elements(&my->pending) == 0);
166 if (rcode < 0)
return rcode;
168 if ((
size_t) rcode == size)
return rcode;
173 if (!
buffer)
return rcode;
181 fr_assert(fr_bio_queue_list_num_elements(&my->free) > 0);
197 if (fr_bio_queue_list_num_elements(&my->pending) == 0) {
209 while (written < size) {
216 item = fr_bio_queue_list_head(&my->pending);
229 if (rcode == 0)
break;
244 item->already_written += rcode;
246 if (
item->already_written <
item->size)
break;
251 if (
item->cancelled) {
257 (void) fr_bio_queue_list_pop_head(&my->pending);
260 item->packet_ctx = NULL;
262 item->already_written = 0;
264 item->cancelled =
true;
266 fr_bio_queue_list_insert_head(&my->free,
item);
365 if (!my)
return NULL;
371 fr_bio_queue_list_init(&my->pending);
372 fr_bio_queue_list_init(&my->free);
379 my->array[i].my = my;
380 my->array[i].cancelled =
true;
381 fr_bio_queue_list_insert_tail(&my->free, &my->array[i]);
417 if (!((
item >= &my->array[0]) && (item < &my->array[my->
max_saved]))) {
424 if (
item->cancelled)
return 0;
441 if (rcode <= 0)
return -1;
446 item->already_written += rcode;
447 if (
item->already_written <
item->size)
return -1;
457 (void) fr_bio_queue_list_remove(&my->pending,
item);
458 fr_bio_queue_list_insert_head(&my->free,
item);
459 item->cancelled =
true;
static int const char char buffer[256]
fr_bio_write_t _CONST write
write to the underlying bio
static fr_bio_t * fr_bio_next(fr_bio_t *bio)
fr_bio_t * fr_bio_queue_alloc(TALLOC_CTX *ctx, size_t max_saved, fr_bio_queue_saved_t saved, fr_bio_queue_callback_t sent, fr_bio_queue_callback_t cancel, fr_bio_t *next)
Allocate a packet-based bio.
fr_bio_queue_callback_t cancel
static int fr_bio_queue_destructor(fr_bio_queue_t *my)
static ssize_t fr_bio_queue_list_push(fr_bio_queue_t *my, void *packet_ctx, const void *buffer, size_t size, size_t already_written)
Push a packet onto a list.
int fr_bio_queue_cancel(fr_bio_t *bio, fr_bio_queue_entry_t *item)
Cancel the write for a packet.
fr_bio_queue_callback_t sent
static ssize_t fr_bio_queue_write_flush(fr_bio_queue_t *my, size_t size)
Flush the packet list.
struct fr_bio_queue_list_s fr_bio_queue_list_t
struct fr_bio_queue_s fr_bio_queue_t
fr_bio_queue_saved_t saved
static int fr_bio_queue_shutdown(fr_bio_t *bio)
Shutdown.
static ssize_t fr_bio_queue_write_next(fr_bio_t *bio, void *packet_ctx, void const *buffer, size_t size)
Write one packet to the next bio.
static ssize_t fr_bio_queue_write_buffer(fr_bio_t *bio, void *packet_ctx, void const *buffer, size_t size)
Write to the packet list buffer.
static void fr_bio_queue_list_cancel(fr_bio_queue_t *my)
Forcibly cancel all outstanding packets.
void(* fr_bio_queue_callback_t)(fr_bio_t *bio, void *packet_ctx, const void *buffer, size_t size)
struct fr_bio_queue_entry_s fr_bio_queue_entry_t
void(* fr_bio_queue_saved_t)(fr_bio_t *bio, void *packet_ctx, const void *buffer, size_t size, fr_bio_queue_entry_t *queue_ctx)
static int packet_ctx
the tests pass only the address of packet_ctx
static void fr_bio_chain(fr_bio_t *first, fr_bio_t *second)
Chain one bio after another.
#define FR_BIO_DESTRUCTOR_COMMON
Define a common destructor pattern.
#define FR_DLIST_TYPES(_name)
Define type specific wrapper structs for dlists.
#define FR_DLIST_ENTRY(_name)
Expands to the type name used for the entry wrapper structure.
#define FR_DLIST_FUNCS(_name, _element_type, _element_entry)
Define type specific wrapper functions for dlists.
#define FR_DLIST_HEAD(_name)
Expands to the type name used for the head wrapper structure.
int fr_bio_destructor(fr_bio_t *bio)
Free this bio.
ssize_t fr_bio_shutdown_write(UNUSED fr_bio_t *bio, UNUSED void *packet_ctx, UNUSED void const *buffer, UNUSED size_t size)
ssize_t fr_bio_next_read(fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)
Internal bio function which just reads from the "next" bio.
static void * item(fr_lst_t const *lst, fr_lst_index_t idx)