···1+(** Conpool - Protocol-agnostic TCP/IP connection pooling library for Eio *)
2+3+(** {1 Logging} *)
4+5+val src : Logs.Src.t
6+(** Logs source for conpool. Configure logging with:
7+ {[
8+ Logs.Src.set_level Conpool.src (Some Logs.Debug);
9+ Logs.set_reporter (Logs_fmt.reporter ());
10+ ]}
11+*)
12+13+(** {1 Core Types} *)
14+15+(** Network endpoint *)
16+module Endpoint : sig
17+ type t
18+ (** Network endpoint identified by host and port *)
19+20+ val make : host:string -> port:int -> t
21+ (** Create an endpoint *)
22+23+ val host : t -> string
24+ (** Get the hostname *)
25+26+ val port : t -> int
27+ (** Get the port number *)
28+29+ val pp : Format.formatter -> t -> unit
30+ (** Pretty-print an endpoint *)
31+32+ val equal : t -> t -> bool
33+ (** Compare two endpoints for equality *)
34+35+ val hash : t -> int
36+ (** Hash an endpoint *)
37+end
38+39+(** TLS configuration *)
40+module Tls_config : sig
41+ type t
42+ (** TLS configuration applied to all connections in a pool *)
43+44+ val make : config:Tls.Config.client -> ?servername:string -> unit -> t
45+ (** Create TLS configuration.
46+ @param config TLS client configuration
47+ @param servername Optional SNI server name override. If None, uses endpoint host *)
48+49+ val config : t -> Tls.Config.client
50+ (** Get the TLS client configuration *)
51+52+ val servername : t -> string option
53+ (** Get the SNI server name override *)
54+55+ val pp : Format.formatter -> t -> unit
56+ (** Pretty-print TLS configuration *)
57+end
58+59+60+(** Pool configuration *)
61+module Config : sig
62+ type t
63+ (** Pool configuration *)
64+65+ val make :
66+ ?max_connections_per_endpoint:int ->
67+ ?max_idle_time:float ->
68+ ?max_connection_lifetime:float ->
69+ ?max_connection_uses:int ->
70+ ?health_check:([ `Close | `Flow | `R | `Shutdown | `W] Eio.Resource.t -> bool) ->
71+ ?connect_timeout:float ->
72+ ?connect_retry_count:int ->
73+ ?connect_retry_delay:float ->
74+ ?on_connection_created:(Endpoint.t -> unit) ->
75+ ?on_connection_closed:(Endpoint.t -> unit) ->
76+ ?on_connection_reused:(Endpoint.t -> unit) ->
77+ unit -> t
78+ (** Create pool configuration with optional parameters.
79+ See field descriptions for defaults. *)
80+81+ val default : t
82+ (** Sensible defaults for most use cases:
83+ - max_connections_per_endpoint: 10
84+ - max_idle_time: 60.0s
85+ - max_connection_lifetime: 300.0s
86+ - max_connection_uses: None (unlimited)
87+ - health_check: None
88+ - connect_timeout: 10.0s
89+ - connect_retry_count: 3
90+ - connect_retry_delay: 0.1s
91+ - hooks: None *)
92+93+ val max_connections_per_endpoint : t -> int
94+ val max_idle_time : t -> float
95+ val max_connection_lifetime : t -> float
96+ val max_connection_uses : t -> int option
97+ val health_check : t -> ([ `Close | `Flow | `R | `Shutdown | `W] Eio.Resource.t -> bool) option
98+ val connect_timeout : t -> float option
99+ val connect_retry_count : t -> int
100+ val connect_retry_delay : t -> float
101+102+ val pp : Format.formatter -> t -> unit
103+ (** Pretty-print configuration *)
104+end
105+106+(** Statistics for an endpoint *)
107+module Stats : sig
108+ type t
109+ (** Statistics for a specific endpoint *)
110+111+ val active : t -> int
112+ (** Connections currently in use *)
113+114+ val idle : t -> int
115+ (** Connections in pool waiting to be reused *)
116+117+ val total_created : t -> int
118+ (** Total connections created (lifetime) *)
119+120+ val total_reused : t -> int
121+ (** Total times connections were reused *)
122+123+ val total_closed : t -> int
124+ (** Total connections closed *)
125+126+ val errors : t -> int
127+ (** Total connection errors *)
128+129+ val pp : Format.formatter -> t -> unit
130+ (** Pretty-print endpoint statistics *)
131+end
132+133+(** {1 Connection Pool} *)
134+135+type ('clock, 'net) t
136+(** Connection pool managing multiple endpoints, parameterized by clock and network types *)
137+138+val create :
139+ sw:Eio.Switch.t ->
140+ net:'net Eio.Net.t ->
141+ clock:'clock Eio.Time.clock ->
142+ ?tls:Tls_config.t ->
143+ ?config:Config.t ->
144+ unit -> ('clock Eio.Time.clock, 'net Eio.Net.t) t
145+(** Create connection pool bound to switch.
146+ All connections will be closed when switch is released.
147+148+ @param sw Switch for resource management
149+ @param net Network interface for creating connections
150+ @param clock Clock for timeouts and time-based validation
151+ @param tls Optional TLS configuration applied to all connections
152+ @param config Optional pool configuration (uses Config.default if not provided) *)
153+154+(** {1 Connection Usage} *)
155+156+val with_connection :
157+ ('clock Eio.Time.clock, 'net Eio.Net.t) t ->
158+ Endpoint.t ->
159+ ([ `Close | `Flow | `R | `Shutdown | `W ] Eio.Resource.t -> 'a) ->
160+ 'a
161+(** Acquire connection, use it, automatically release back to pool.
162+163+ This is the only way to use connections from the pool. All resource management
164+ is handled automatically through Eio's switch mechanism.
165+166+ If idle connection available and healthy:
167+ - Reuse from pool (validates health first)
168+ Else:
169+ - Create new connection (may block if endpoint at limit)
170+171+ On success: connection returned to pool for reuse
172+ On error: connection closed, not returned to pool
173+174+ Example:
175+ {[
176+ let endpoint = Conpool.Endpoint.make ~host:"example.com" ~port:443 in
177+ Conpool.with_connection pool endpoint (fun conn ->
178+ (* Use conn for HTTP request, Redis command, etc. *)
179+ Eio.Flow.copy_string "GET / HTTP/1.1\r\n\r\n" conn;
180+ let buf = Eio.Buf_read.of_flow conn ~max_size:4096 in
181+ Eio.Buf_read.take_all buf
182+ )
183+ ]}
184+*)
185+186+(** {1 Statistics & Monitoring} *)
187+188+val stats :
189+ ('clock Eio.Time.clock, 'net Eio.Net.t) t ->
190+ Endpoint.t ->
191+ Stats.t
192+(** Get statistics for specific endpoint *)
193+194+val all_stats :
195+ ('clock Eio.Time.clock, 'net Eio.Net.t) t ->
196+ (Endpoint.t * Stats.t) list
197+(** Get statistics for all endpoints in pool *)
198+199+(** {1 Pool Management} *)
200+201+val clear_endpoint :
202+ ('clock Eio.Time.clock, 'net Eio.Net.t) t ->
203+ Endpoint.t ->
204+ unit
205+(** Clear all cached connections for a specific endpoint.
206+207+ This removes the endpoint from the pool, discarding all idle connections.
208+ Active connections will continue to work but won't be returned to the pool.
209+210+ Use this when you know an endpoint's connections are no longer valid
211+ (e.g., server restarted, network reconfigured, credentials changed).
212+213+ The pool will be automatically cleaned up when its switch is released. *)