type t = { pool : Cstruct.t Eio.Stream.t; buf_size : int; capacity : int } let create ~size ~count = let pool = Eio.Stream.create count in for _ = 1 to count do Eio.Stream.add pool (Cstruct.create size) done; { pool; buf_size = size; capacity = count } let acquire t = Eio.Stream.take t.pool let release t buf = Eio.Stream.add t.pool buf let with_buffer t f = let buf = acquire t in Fun.protect ~finally:(fun () -> release t buf) (fun () -> f buf) let available t = Eio.Stream.length t.pool let total t = t.capacity let size t = t.buf_size