this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

more

+11 -20
+10 -19
stack/conpool/lib/conpool.ml
··· 3 3 let src = Logs.Src.create "conpool" ~doc:"Connection pooling library" 4 4 module Log = (val Logs.src_log src : Logs.LOG) 5 5 6 - (** {1 Public Module Types} *) 7 - 8 6 module Endpoint = struct 9 7 type t = { 10 8 host : string; ··· 51 49 endpoint : Endpoint.t; 52 50 } 53 51 54 - let get_flow t = t.flow 52 + let flow t = t.flow 55 53 let endpoint t = t.endpoint 56 54 let created_at t = t.created_at 57 55 let last_used t = t.last_used ··· 171 169 t.errors 172 170 end 173 171 174 - (** {1 Internal Types} *) 175 - 176 - type endpoint_stats_mutable = { 172 + type endp_stats = { 177 173 mutable active : int; 178 174 mutable idle : int; 179 175 mutable total_created : int; ··· 184 180 185 181 type endpoint_pool = { 186 182 pool : Connection.t Eio.Pool.t; 187 - stats : endpoint_stats_mutable; 183 + stats : endp_stats; 188 184 mutex : Eio.Mutex.t; 189 185 } 190 186 ··· 198 194 endpoints_mutex : Eio.Mutex.t; 199 195 } 200 196 201 - (** {1 Endpoint Hashing} *) 202 - 203 197 module EndpointTbl = Hashtbl.Make(struct 204 198 type t = Endpoint.t 205 199 let equal = Endpoint.equal 206 200 let hash = Endpoint.hash 207 201 end) 208 202 209 - (** {1 Helper Functions} *) 210 - 211 203 let get_time pool = 212 204 Eio.Time.now pool.clock 213 205 214 - let create_mutable_stats () = { 206 + let create_endp_stats () = { 215 207 active = 0; 216 208 idle = 0; 217 209 total_created = 0; ··· 220 212 errors = 0; 221 213 } 222 214 223 - let snapshot_stats (stats : endpoint_stats_mutable) : Stats.t = { 215 + let snapshot_stats (stats : endp_stats) : Stats.t = { 224 216 active = stats.active; 225 217 idle = stats.idle; 226 218 total_created = stats.total_created; ··· 232 224 (** {1 DNS Resolution} *) 233 225 234 226 let resolve_endpoint pool endpoint = 235 - (* Simple DNS resolution - returns socket address *) 236 227 Log.debug (fun m -> m "Resolving %a..." Endpoint.pp endpoint); 237 228 let addrs = Eio.Net.getaddrinfo_stream pool.net (Endpoint.host endpoint) ~service:(string_of_int (Endpoint.port endpoint)) in 238 229 Log.debug (fun m -> m "Got address list for %a" Endpoint.pp endpoint); ··· 274 265 275 266 Log.debug (fun m -> m "TCP connection established to %a" Endpoint.pp endpoint); 276 267 277 - let flow : [`Close | `Flow | `R | `Shutdown | `W] Eio.Resource.t = match pool.tls with 268 + let flow = match pool.tls with 278 269 | None -> (socket :> [`Close | `Flow | `R | `Shutdown | `W] Eio.Resource.t) 279 270 | Some tls_cfg -> 280 271 Log.debug (fun m -> m "Initiating TLS handshake with %a" Endpoint.pp endpoint); ··· 352 343 else if (match pool.config.health_check with 353 344 | Some check -> 354 345 (try 355 - let healthy = check (Connection.get_flow conn) in 346 + let healthy = check (Connection.flow conn) in 356 347 if not healthy then 357 348 Log.debug (fun m -> m "Connection to %a failed custom health check" 358 349 Endpoint.pp (Connection.endpoint conn)); ··· 391 382 392 383 Eio.Cancel.protect (fun () -> 393 384 try 394 - Eio.Flow.close (Connection.get_flow conn) 385 + Eio.Flow.close (Connection.flow conn) 395 386 with _ -> () 396 387 ); 397 388 ··· 419 410 ep_pool 420 411 | None -> 421 412 (* Create new endpoint pool *) 422 - let stats = create_mutable_stats () in 413 + let stats = create_endp_stats () in 423 414 let mutex = Eio.Mutex.create () in 424 415 425 416 Log.info (fun m -> m "Creating new endpoint pool for %a (max_connections=%d)" ··· 448 439 (* Run health check if configured *) 449 440 match pool.config.health_check with 450 441 | Some check -> 451 - (try check (Connection.get_flow conn) 442 + (try check (Connection.flow conn) 452 443 with _ -> false) 453 444 | None -> true 454 445 ) else begin
+1 -1
stack/conpool/lib/conpool.mli
··· 61 61 type t 62 62 (** Opaque connection handle with metadata *) 63 63 64 - val get_flow : t -> [ `Close | `Flow | `R | `Shutdown | `W] Eio.Resource.t 64 + val flow : t -> [ `Close | `Flow | `R | `Shutdown | `W] Eio.Resource.t 65 65 (** Extract underlying Eio flow from connection *) 66 66 67 67 val endpoint : t -> Endpoint.t