···
let src = Logs.Src.create "conpool" ~doc:"Connection pooling library"
module Log = (val Logs.src_log src : Logs.LOG)
6
-
(** {1 Public Module Types} *)
···
54
-
let get_flow t = t.flow
let endpoint t = t.endpoint
let created_at t = t.created_at
let last_used t = t.last_used
···
174
-
(** {1 Internal Types} *)
176
-
type endpoint_stats_mutable = {
172
+
type endp_stats = {
mutable total_created : int;
···
pool : Connection.t Eio.Pool.t;
187
-
stats : endpoint_stats_mutable;
183
+
stats : endp_stats;
···
endpoints_mutex : Eio.Mutex.t;
201
-
(** {1 Endpoint Hashing} *)
module EndpointTbl = Hashtbl.Make(struct
let equal = Endpoint.equal
209
-
(** {1 Helper Functions} *)
214
-
let create_mutable_stats () = {
206
+
let create_endp_stats () = {
···
223
-
let snapshot_stats (stats : endpoint_stats_mutable) : Stats.t = {
215
+
let snapshot_stats (stats : endp_stats) : Stats.t = {
total_created = stats.total_created;
···
(** {1 DNS Resolution} *)
let resolve_endpoint pool endpoint =
235
-
(* Simple DNS resolution - returns socket address *)
Log.debug (fun m -> m "Resolving %a..." Endpoint.pp endpoint);
let addrs = Eio.Net.getaddrinfo_stream pool.net (Endpoint.host endpoint) ~service:(string_of_int (Endpoint.port endpoint)) in
Log.debug (fun m -> m "Got address list for %a" Endpoint.pp endpoint);
···
Log.debug (fun m -> m "TCP connection established to %a" Endpoint.pp endpoint);
277
-
let flow : [`Close | `Flow | `R | `Shutdown | `W] Eio.Resource.t = match pool.tls with
268
+
let flow = match pool.tls with
| None -> (socket :> [`Close | `Flow | `R | `Shutdown | `W] Eio.Resource.t)
Log.debug (fun m -> m "Initiating TLS handshake with %a" Endpoint.pp endpoint);
···
else if (match pool.config.health_check with
355
-
let healthy = check (Connection.get_flow conn) in
346
+
let healthy = check (Connection.flow conn) in
Log.debug (fun m -> m "Connection to %a failed custom health check"
Endpoint.pp (Connection.endpoint conn));
···
Eio.Cancel.protect (fun () ->
394
-
Eio.Flow.close (Connection.get_flow conn)
385
+
Eio.Flow.close (Connection.flow conn)
···
(* Create new endpoint pool *)
422
-
let stats = create_mutable_stats () in
413
+
let stats = create_endp_stats () in
let mutex = Eio.Mutex.create () in
Log.info (fun m -> m "Creating new endpoint pool for %a (max_connections=%d)"
···
(* Run health check if configured *)
match pool.config.health_check with
451
-
(try check (Connection.get_flow conn)
442
+
(try check (Connection.flow conn)