<commit_before>
open Lwt
open Ex_common

let serve_ssl port callback =

  let tag = "server" in

  lwt cert =
    X509_lwt.private_of_pems
      ~cert:server_cert
      ~priv_key:server_key in

  let server_s =
    let open Lwt_unix in
    let s = socket PF_INET SOCK_STREAM 0 in
    bind s (ADDR_INET (Unix.inet_addr_any, port)) ;
    listen s 10 ;
    s in

  yap ~tag ("-> start @ " ^ string_of_int port)
  >>
  lwt (channels, addr) = Tls_lwt.accept cert server_s in
  yap ~tag "-> connect"
  >>
  callback channels addr
  >>
  yap ~tag "<- handler done"


let test_server port =
  lwt () = Tls_lwt.rng_init () in
  serve_ssl port @@ fun (ic, oc) addr ->
    Lwt_io.read_line ic >>= fun line ->
    yap "handler" ("+ " ^ line)
    >>
    Lwt_io.write_line oc line
    >>
    Lwt_io.close oc

let () =
  let port =
    try int_of_string Sys.argv.(1) with _ -> 4433
  in
  Lwt_main.run (test_server port)<commit_msg>do not close the channel, the other side (openssl) already does this<commit_after>
open Lwt
open Ex_common

let serve_ssl port callback =

  let tag = "server" in

  lwt cert =
    X509_lwt.private_of_pems
      ~cert:server_cert
      ~priv_key:server_key in

  let server_s =
    let open Lwt_unix in
    let s = socket PF_INET SOCK_STREAM 0 in
    bind s (ADDR_INET (Unix.inet_addr_any, port)) ;
    listen s 10 ;
    s in

  yap ~tag ("-> start @ " ^ string_of_int port)
  >>
  lwt (channels, addr) = Tls_lwt.accept cert server_s in
  yap ~tag "-> connect"
  >>
  callback channels addr
  >>
  yap ~tag "<- handler done"


let test_server port =
  lwt () = Tls_lwt.rng_init () in
  serve_ssl port @@ fun (ic, oc) addr ->
    Lwt_io.read_line ic >>= fun line ->
    yap "handler" ("+ " ^ line)
    >>
    Lwt_io.write_line oc line

let () =
  let port =
    try int_of_string Sys.argv.(1) with _ -> 4433
  in
  Lwt_main.run (test_server port)
{'fraction_non_alphanumeric': 0.10741138560687433, 'fraction_numerical': 0.011815252416756176, 'mean_word_length': 2.6673228346456694, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1752928', 'n_tokens_mistral': 752, 'n_tokens_neox': 717, 'n_words': 208}