TCP/TLS connection pooling for Eio

Documentation and code quality improvements across libraries

- Add README files for jsonwt, owntracks, monopam, and srcsetter
- Fix langdetect language count (47→49) in dune-project
- Remove unused variable in crockford encode function
- Improve retention type documentation in zulip channels.mli
- Refactor conpool is_healthy to reduce nesting and improve clarity
- Document unimplemented IDNA features in punycode README

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

+48 -56
+48 -56
lib/conpool.ml
··· 242 242 243 243 let is_healthy (pool : ('clock, 'net) internal) ?(check_readable = false) conn = 244 244 let now = get_time pool in 245 + let endpoint = Connection.endpoint conn in 246 + let age = now -. Connection.created_at conn in 247 + let idle_time = now -. Connection.last_used conn in 248 + let max_lifetime = Config.max_connection_lifetime pool.config in 249 + let max_idle = Config.max_idle_time pool.config in 245 250 246 251 (* Check age *) 247 - let age = now -. Connection.created_at conn in 248 - let max_lifetime = Config.max_connection_lifetime pool.config in 249 - if age > max_lifetime then begin 252 + if age > max_lifetime then ( 250 253 Log.debug (fun m -> 251 254 m "Connection to %a unhealthy: exceeded max lifetime (%.2fs > %.2fs)" 252 - Endpoint.pp (Connection.endpoint conn) age max_lifetime); 253 - false 254 - end 255 + Endpoint.pp endpoint age max_lifetime); 256 + false) 255 257 (* Check idle time *) 256 - else begin 257 - let max_idle = Config.max_idle_time pool.config in 258 - if now -. Connection.last_used conn > max_idle then begin 259 - let idle_time = now -. Connection.last_used conn in 260 - Log.debug (fun m -> 261 - m "Connection to %a unhealthy: exceeded max idle time (%.2fs > %.2fs)" 262 - Endpoint.pp (Connection.endpoint conn) idle_time max_idle); 263 - false 264 - end (* Check use count *) 265 - else if 266 - match Config.max_connection_uses pool.config with 267 - | Some max -> Connection.use_count conn >= max 268 - | None -> false 269 - then begin 270 - Log.debug (fun m -> 271 - m "Connection to %a unhealthy: exceeded max use count (%d)" 272 - Endpoint.pp (Connection.endpoint conn) 273 - (Connection.use_count conn)); 274 - false 275 - end (* Optional: custom health check *) 276 - else if 277 - match Config.health_check pool.config with 278 - | Some check -> ( 279 - try 280 - let healthy = check (Connection.flow conn) in 281 - if not healthy then 282 - Log.debug (fun m -> 283 - m "Connection to %a failed custom health check" Endpoint.pp 284 - (Connection.endpoint conn)); 285 - not healthy 286 - with e -> 258 + else if idle_time > max_idle then ( 259 + Log.debug (fun m -> 260 + m "Connection to %a unhealthy: exceeded max idle time (%.2fs > %.2fs)" 261 + Endpoint.pp endpoint idle_time max_idle); 262 + false) 263 + (* Check use count *) 264 + else if 265 + match Config.max_connection_uses pool.config with 266 + | Some max -> Connection.use_count conn >= max 267 + | None -> false 268 + then ( 269 + Log.debug (fun m -> 270 + m "Connection to %a unhealthy: exceeded max use count (%d)" 271 + Endpoint.pp endpoint (Connection.use_count conn)); 272 + false) 273 + (* Optional: custom health check *) 274 + else if 275 + match Config.health_check pool.config with 276 + | Some check -> ( 277 + try 278 + let healthy = check (Connection.flow conn) in 279 + if not healthy then 287 280 Log.debug (fun m -> 288 - m "Connection to %a health check raised exception: %s" 289 - Endpoint.pp (Connection.endpoint conn) (Printexc.to_string e)); 290 - true (* Exception in health check = unhealthy *)) 291 - | None -> false 292 - then false (* Optional: check if socket still connected *) 293 - else if check_readable then 294 - try 295 - (* TODO avsm: a sockopt for this? *) 296 - true 297 - with _ -> false 298 - else begin 299 - Log.debug (fun m -> 300 - m "Connection to %a is healthy (age=%.2fs, idle=%.2fs, uses=%d)" 301 - Endpoint.pp (Connection.endpoint conn) age 302 - (now -. Connection.last_used conn) 303 - (Connection.use_count conn)); 304 - true 305 - end 306 - end 281 + m "Connection to %a failed custom health check" 282 + Endpoint.pp endpoint); 283 + not healthy 284 + with e -> 285 + Log.debug (fun m -> 286 + m "Connection to %a health check raised exception: %s" 287 + Endpoint.pp endpoint (Printexc.to_string e)); 288 + true) 289 + | None -> false 290 + then false 291 + (* Optional: check if socket still connected *) 292 + else if check_readable then (try true with _ -> false) 293 + (* All checks passed *) 294 + else ( 295 + Log.debug (fun m -> 296 + m "Connection to %a is healthy (age=%.2fs, idle=%.2fs, uses=%d)" 297 + Endpoint.pp endpoint age idle_time (Connection.use_count conn)); 298 + true) 307 299 308 300 (** {1 Internal Pool Operations} *) 309 301