TCP/TLS connection pooling for Eio
at main 2.1 kB view raw
1(*--------------------------------------------------------------------------- 2 Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 SPDX-License-Identifier: ISC 4 ---------------------------------------------------------------------------*) 5 6(** Cmdliner terms for connection pool configuration *) 7 8open Cmdliner 9 10let max_connections_per_endpoint = 11 let doc = "Maximum concurrent connections per endpoint." in 12 Arg.( 13 value & opt int 10 14 & info [ "max-connections-per-endpoint" ] ~doc ~docv:"NUM") 15 16let max_idle_time = 17 let doc = "Maximum time a connection can sit idle in seconds." in 18 Arg.(value & opt float 60.0 & info [ "max-idle-time" ] ~doc ~docv:"SECONDS") 19 20let max_connection_lifetime = 21 let doc = "Maximum connection age in seconds." in 22 Arg.( 23 value & opt float 300.0 24 & info [ "max-connection-lifetime" ] ~doc ~docv:"SECONDS") 25 26let max_connection_uses = 27 let doc = "Maximum times a connection can be reused (omit for unlimited)." in 28 Arg.( 29 value 30 & opt (some int) None 31 & info [ "max-connection-uses" ] ~doc ~docv:"NUM") 32 33let connect_timeout = 34 let doc = "Connection timeout in seconds." in 35 Arg.(value & opt float 10.0 & info [ "connect-timeout" ] ~doc ~docv:"SECONDS") 36 37let connect_retry_count = 38 let doc = "Number of connection retry attempts." in 39 Arg.(value & opt int 3 & info [ "connect-retry-count" ] ~doc ~docv:"NUM") 40 41let connect_retry_delay = 42 let doc = "Initial retry delay in seconds (with exponential backoff)." in 43 Arg.( 44 value & opt float 0.1 & info [ "connect-retry-delay" ] ~doc ~docv:"SECONDS") 45 46let config = 47 let make max_conn max_idle max_lifetime max_uses timeout retry_count 48 retry_delay = 49 Config.make ~max_connections_per_endpoint:max_conn ~max_idle_time:max_idle 50 ~max_connection_lifetime:max_lifetime ?max_connection_uses:max_uses 51 ~connect_timeout:timeout ~connect_retry_count:retry_count 52 ~connect_retry_delay:retry_delay () 53 in 54 Term.( 55 const make $ max_connections_per_endpoint $ max_idle_time 56 $ max_connection_lifetime $ max_connection_uses $ connect_timeout 57 $ connect_retry_count $ connect_retry_delay)