TCP/TLS connection pooling for Eio
0
fork

Configure Feed

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

conpool: fix README — correct Stats/Config API names, handler signature

+16 -14
+16 -14
README.md
··· 32 32 let endpoint = Conpool.Endpoint.v ~host:"example.com" ~port:80 in 33 33 34 34 (* Use a connection from the pool *) 35 - Conpool.with_connection pool endpoint (fun conn -> 36 - Eio.Flow.copy_string "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" conn; 37 - let buf = Eio.Buf_read.of_flow conn ~max_size:4096 in 35 + Eio.Switch.run (fun conn_sw -> 36 + let conn = Conpool.connection ~sw:conn_sw pool endpoint in 37 + Eio.Flow.copy_string "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" conn.flow; 38 + let buf = Eio.Buf_read.of_flow conn.flow ~max_size:4096 in 38 39 Eio.Buf_read.take_all buf 39 40 ) 40 41 ) ··· 58 59 in 59 60 60 61 let endpoint = Conpool.Endpoint.v ~host:"example.com" ~port:443 in 61 - Conpool.with_connection pool endpoint (fun conn -> 62 - (* Use TLS-encrypted connection *) 63 - ... 62 + Eio.Switch.run (fun conn_sw -> 63 + let conn = Conpool.connection ~sw:conn_sw pool endpoint in 64 + (* Use TLS-encrypted conn.flow *) 65 + ignore conn.flow 64 66 ) 65 67 ) 66 68 ``` ··· 70 72 ```ocaml 71 73 let config = Conpool.Config.v 72 74 ~max_connections_per_endpoint:20 73 - ~max_idle_per_endpoint:5 74 - ~connection_timeout:10.0 75 - ~validation_interval:300.0 75 + ~max_idle_time:60.0 76 + ~max_connection_lifetime:300.0 77 + ~connect_timeout:10.0 76 78 () 77 79 in 78 80 ··· 83 85 84 86 ```ocaml 85 87 let stats = Conpool.stats pool endpoint in 86 - Printf.printf "Active: %d, Idle: %d, Hits: %d, Misses: %d\n" 87 - (Conpool.Stats.active_connections stats) 88 - (Conpool.Stats.idle_connections stats) 89 - (Conpool.Stats.cache_hits stats) 90 - (Conpool.Stats.cache_misses stats) 88 + Printf.printf "Active: %d, Idle: %d, Created: %d, Reused: %d\n" 89 + (Conpool.Stats.active stats) 90 + (Conpool.Stats.idle stats) 91 + (Conpool.Stats.total_created stats) 92 + (Conpool.Stats.total_reused stats) 91 93 ``` 92 94 93 95 ## Installation