diff --git a/src/lib/bio/mem.c b/src/lib/bio/mem.c index c66df4f187d40..432be24f978ba 100644 --- a/src/lib/bio/mem.c +++ b/src/lib/bio/mem.c @@ -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; +} diff --git a/src/lib/bio/mem.h b/src/lib/bio/mem.h index a3f9468b7a532..914acbda46e49 100644 --- a/src/lib/bio/mem.h +++ b/src/lib/bio/mem.h @@ -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);