fix echo_client to actually do its work

This commit is contained in:
Simon Cruanes 2024-02-14 21:26:58 -05:00
parent b991a78f3e
commit e789cbe4f7
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -19,19 +19,28 @@ let main ~port ~runner ~n ~n_conn () : unit Lwt.t =
(* Printf.printf "running task\n%!"; *) (* Printf.printf "running task\n%!"; *)
let n = Atomic.fetch_and_add remaining (-1) in let n = Atomic.fetch_and_add remaining (-1) in
if n > 0 then ( if n > 0 then (
( (* let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "connect.client" in *) (let _sp =
M_lwt.TCP_client.with_connect addr Trace.enter_manual_toplevel_span ~__FILE__ ~__LINE__ "connect.client"
@@ fun ic oc -> in
Trace.message "connecting new client…";
M_lwt.TCP_client.with_connect addr @@ fun ic oc ->
let buf = Bytes.create 32 in let buf = Bytes.create 32 in
for _j = 1 to 100 do for _j = 1 to 100 do
let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "write.loop" in let _sp =
Trace.enter_manual_sub_span ~parent:_sp ~__FILE__ ~__LINE__
"write.loop"
in
M_lwt.IO_out.output_string oc "hello"; M_lwt.IO_out.output_string oc "hello";
M_lwt.IO_out.flush oc;
(* read back something *) (* read back something *)
let _n = M_lwt.IO_in.really_input ic buf in M_lwt.IO_in.really_input ic buf 0 (String.length "hello");
Trace.exit_manual_span _sp;
() ()
done ); done;
Trace.exit_manual_span _sp);
(* run another task *) M.Runner.run_async runner run_task (* run another task *) M.Runner.run_async runner run_task
) else ( ) else (
@ -55,6 +64,7 @@ let main ~port ~runner ~n ~n_conn () : unit Lwt.t =
let () = let () =
let@ () = Trace_tef.with_setup () in let@ () = Trace_tef.with_setup () in
Trace.set_thread_name "main"; Trace.set_thread_name "main";
let port = ref 0 in let port = ref 0 in
let j = ref 4 in let j = ref 4 in
let n_conn = ref 100 in let n_conn = ref 100 in
@ -63,7 +73,7 @@ let () =
let opts = let opts =
[ [
"-p", Arg.Set_int port, " port"; "-p", Arg.Set_int port, " port";
"j", Arg.Set_int j, " number of threads"; "-j", Arg.Set_int j, " number of threads";
"-n", Arg.Set_int n, " total number of connections"; "-n", Arg.Set_int n, " total number of connections";
"--n-conn", Arg.Set_int n_conn, " number of parallel connections"; "--n-conn", Arg.Set_int n_conn, " number of parallel connections";
] ]