Skip to content

Commit

Permalink
add write_pause API
Browse files Browse the repository at this point in the history
so that we can pause / buffer / resume writes for possible
performance improvements
  • Loading branch information
alandekok committed Jan 8, 2025
1 parent 4542a85 commit 4147d90
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/lib/bio/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,3 +942,22 @@ int fr_bio_mem_write_resume(fr_bio_t *bio)

return my->cb.write_resume(bio);
}

/** Pause writes.
*
* Calls to fr_bio_write() will write to the memory buffer, and not
* to the next bio. You MUST call fr_bio_mem_write_resume() after
* this to flush any data.
*/
int fr_bio_mem_write_pause(fr_bio_t *bio)
{
fr_bio_mem_t *my = talloc_get_type_abort(bio, fr_bio_mem_t);

if (my->bio.write == fr_bio_mem_write_buffer) return 0;

if (my->bio.write != fr_bio_mem_write_buffer) return -1;

my->bio.write = fr_bio_mem_write_buffer;

return 0;
}
2 changes: 2 additions & 0 deletions src/lib/bio/mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ void fr_bio_mem_read_discard(fr_bio_t *bio, size_t size) CC_HINT(nonnull);
int fr_bio_mem_set_verify(fr_bio_t *bio, fr_bio_verify_t verify, void *verify_ctx, bool datagram) CC_HINT(nonnull);

int fr_bio_mem_write_resume(fr_bio_t *bio) CC_HINT(nonnull);

int fr_bio_mem_write_pause(fr_bio_t *bio) CC_HINT(nonnull);

0 comments on commit 4147d90

Please sign in to comment.