diff --git a/src/low_level.ml b/src/low_level.ml index 1703cf9..6e10f09 100644 --- a/src/low_level.ml +++ b/src/low_level.ml @@ -560,10 +560,15 @@ let writev fd bufs = let size = e.stat.size in (* If the position is equal to the size then we just append. *) if Optint.Int63.equal size e.pos then - let contents = Cstruct.concat (e.contents :: bufs) in - let new_size = Optint.Int63.of_int @@ Cstruct.length contents in - let stat = { e.stat with size = new_size } in - r := File { e with stat; contents; pos = new_size } + (* We do it one buf at a time so we can simulate some concurrency... *) + List.iter + (fun buf -> + let contents = Cstruct.concat (e.contents :: [ buf ]) in + let new_size = Optint.Int63.of_int @@ Cstruct.length contents in + let stat = { e.stat with size = new_size } in + r := File { e with stat; contents; pos = new_size }; + Eio.Fiber.yield ()) + bufs else (* Position is less than the size, so need to merge contents. *) let src = Cstruct.concat bufs in @@ -596,7 +601,8 @@ let readv fd bufs = let actual_len = if posi + len <= size then len else size - posi in Cstruct.blit e.contents (Optint.Int63.to_int !pos) buf 0 actual_len; pos := Optint.Int63.add !pos (Optint.Int63.of_int len); - read := !read + actual_len) + read := !read + actual_len; + Eio.Fiber.yield ()) bufs; r := File { e with pos = !pos } | r -> Fmt.failwith "TODO: readv %a" Resource.pp r