TCP/TLS connection pooling for Eio

fix-reuse

Changed files
+5 -2
lib
+5 -2
lib/conpool.ml
···
Eio.Mutex.use_rw ~protect:true ep_pool.mutex (fun () ->
ep_pool.stats.active <- ep_pool.stats.active + 1);
-
(* Fork a daemon fiber to manage the connection lifecycle *)
-
Eio.Fiber.fork_daemon ~sw (fun () ->
+
(* Fork a daemon fiber to manage the connection lifecycle.
+
Important: Fork under pool.sw, not the caller's sw, so the daemon
+
survives when the caller's switch ends and can return the connection
+
to the pool for reuse. *)
+
Eio.Fiber.fork_daemon ~sw:pool.sw (fun () ->
Fun.protect
~finally:(fun () ->
(* Decrement active count *)