<commit_before>(* This unikernel is based on tracing documentation:
   https://mirage.io/wiki/profiling
*)

open Lwt.Infix
let target_ip = Ipaddr.V4.of_string_exn "10.0.0.1"

module Main (S: V1_LWT.STACKV4) = struct

  let send_data t =
    let buffer = Io_page.get 1 |> Io_page.to_cstruct in

    S.TCPV4.create_connection t (target_ip, 7001) >>= function
    | `Error _err -> failwith "Connection to port 7001 failed"
    | `Ok flow ->

    let payload = Cstruct.sub buffer 0 1 in
    Cstruct.set_char payload 0 '!';

    S.TCPV4.write flow payload >>= function
    | `Error _ | `Eof -> assert false
    | `Ok () ->

    S.TCPV4.close flow

  let start s =
    let t = S.tcpv4 s in
    Lwt.pick [
      S.listen s;
      send_data t;
    ]

end<commit_msg>Revert "have tracing example explicitly call STACKV4.listen"<commit_after>(* This unikernel is based on tracing documentation:
   https://mirage.io/wiki/profiling
*)

open Lwt.Infix
let target_ip = Ipaddr.V4.of_string_exn "10.0.0.1"

module Main (S: V1_LWT.STACKV4) = struct
  let buffer = Io_page.get 1 |> Io_page.to_cstruct

  let start s =
    let t = S.tcpv4 s in

    S.TCPV4.create_connection t (target_ip, 7001) >>= function
    | `Error _err -> failwith "Connection to port 7001 failed"
    | `Ok flow ->

    let payload = Cstruct.sub buffer 0 1 in
    Cstruct.set_char payload 0 '!';

    S.TCPV4.write flow payload >>= function
    | `Error _ | `Eof -> assert false
    | `Ok () ->

    S.TCPV4.close flow
end
{'fraction_non_alphanumeric': 0.11502029769959404, 'fraction_numerical': 0.033152909336941816, 'mean_word_length': 2.7729591836734695, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3178444', 'n_tokens_mistral': 583, 'n_tokens_neox': 547, 'n_words': 154}