TCP/TLS connection pooling for Eio
0
fork

Configure Feed

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

fix(lint): resolve E410, E415, E505, E510 doc and structure issues

- E410: Fix remaining doc style issues (periods, [name args] format)
in conpool, cookeio, cookeio_jar
- E415: Add pp function for Conpool.t type
- E505: Create connection.mli interface file for conpool
- E510: Add log source to crow/bin/main.ml
- E331: Apply linter-triggered renames (afl_fuzz_path→fuzz_path,
create_connection→connection)

+75 -6
+2 -2
lib/config.mli
··· 52 52 Initial retry delay in seconds, with exponential backoff (default: 0.1) 53 53 @param on_connection_created Hook called when a connection is created 54 54 @param on_connection_closed Hook called when a connection is closed 55 - @param on_connection_reused Hook called when a connection is reused *) 55 + @param on_connection_reused Hook called when a connection is reused. *) 56 56 57 57 val default : t 58 58 (** [default] provides sensible defaults for most use cases. ··· 64 64 - connect_timeout: 10.0s 65 65 - connect_retry_count: 3 66 66 - connect_retry_delay: 0.1s 67 - - hooks: none *) 67 + - hooks: none. *) 68 68 69 69 (** {1 Accessors} *) 70 70
+45
lib/connection.mli
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 6 + (** Internal connection representation. *) 7 + 8 + val src : Logs.Src.t 9 + (** Logs source for connection management. *) 10 + 11 + type t = { 12 + flow : [ Eio.Resource.close_ty | Eio.Flow.two_way_ty ] Eio.Resource.t; 13 + tls_flow : Tls_eio.t option; 14 + created_at : float; 15 + mutable last_used : float; 16 + mutable use_count : int; 17 + endpoint : Endpoint.t; 18 + mutex : Eio.Mutex.t; 19 + } 20 + (** Connection record with flow, TLS state, and usage tracking. *) 21 + 22 + val flow : t -> [ Eio.Resource.close_ty | Eio.Flow.two_way_ty ] Eio.Resource.t 23 + (** [flow t] returns the underlying connection flow. *) 24 + 25 + val tls_flow : t -> Tls_eio.t option 26 + (** [tls_flow t] returns the TLS flow if the connection uses TLS. *) 27 + 28 + val endpoint : t -> Endpoint.t 29 + (** [endpoint t] returns the endpoint this connection is to. *) 30 + 31 + val created_at : t -> float 32 + (** [created_at t] returns the time the connection was created. *) 33 + 34 + val last_used : t -> float 35 + (** [last_used t] returns the time the connection was last used. *) 36 + 37 + val use_count : t -> int 38 + (** [use_count t] returns the number of times the connection has been used. *) 39 + 40 + val update_usage : t -> now:float -> unit 41 + (** [update_usage t ~now] updates the connection's last-used time and increments 42 + the use count. *) 43 + 44 + val pp : t Fmt.t 45 + (** Pretty-printer for connections. *)
+20 -2
lib/conpool.ml
··· 174 174 175 175 (** {1 Connection Creation} *) 176 176 177 - let create_connection pool endpoint = 177 + let connection pool endpoint = 178 178 Log.debug (fun m -> m "Creating connection to %a" Endpoint.pp endpoint); 179 179 180 180 (* DNS resolution *) ··· 519 519 end 520 520 else begin 521 521 (* Create new connection *) 522 - let conn = create_connection pool endpoint in 522 + let conn = connection pool endpoint in 523 523 conn.pc_active_users <- 1; 524 524 ep_pool.connections := conn :: !(ep_pool.connections); 525 525 ··· 671 671 in 672 672 (endpoint, stats) :: acc) 673 673 pool.endpoints []) 674 + 675 + let pp ppf (Pool pool) = 676 + let endpoint_count = Hashtbl.length pool.endpoints in 677 + let all = 678 + Hashtbl.fold 679 + (fun endpoint ep_pool acc -> 680 + let stats = 681 + Eio.Mutex.use_ro ep_pool.stats_mutex (fun () -> 682 + snapshot_stats ep_pool.stats) 683 + in 684 + (endpoint, stats) :: acc) 685 + pool.endpoints [] 686 + in 687 + Fmt.pf ppf "@[<v>Pool:@,- endpoints: %d@,- %a@]" endpoint_count 688 + Fmt.( 689 + list ~sep:cut (fun ppf (ep, stats) -> 690 + Fmt.pf ppf " %a: %a" Endpoint.pp ep Stats.pp stats)) 691 + all 674 692 675 693 let clear_endpoint (Pool pool) endpoint = 676 694 Log.info (fun m -> m "Clearing endpoint %a from pool" Endpoint.pp endpoint);
+8 -2
lib/conpool.mli
··· 146 146 ?config:Config.t -> 147 147 unit -> 148 148 unit t 149 - (** Create a basic connection pool with no protocol state. 149 + (** [basic ~sw ~net ~clock ()] creates a basic connection pool with no protocol 150 + state. 150 151 151 - This is a convenience function equivalent to: 152 + A convenience function equivalent to: 152 153 {[ 153 154 Conpool.v ~sw ~net ~clock ?tls ?config ~protocol:Conpool.default_protocol 154 155 () ··· 203 204 204 205 val clear_endpoint : 'state t -> Endpoint.t -> unit 205 206 (** Clear all connections for an endpoint. *) 207 + 208 + (** {1 Pretty-printing} *) 209 + 210 + val pp : 'state t Fmt.t 211 + (** Pretty-printer for connection pools. *)