Skip to content

Commit

Permalink
Merge pull request #132 from ComanderP/eio-fix
Browse files Browse the repository at this point in the history
Fix send_all on eio
  • Loading branch information
andersfugmann authored May 19, 2024
2 parents 7cca40d + c94e954 commit 614de51
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
8 changes: 4 additions & 4 deletions zmq-eio/src/socket.ml
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ let send t message =
let send_msg t message =
request t t.senders (fun () -> Zmq.Socket.send_msg ~block:false t.socket message)

let send_all t =
request t t.receivers (fun () -> Zmq.Socket.send_all ~block:false t.socket)
let send_all t messages =
request t t.senders (fun () -> Zmq.Socket.send_all ~block:false t.socket messages)

let send_msg_all t =
request t t.receivers (fun () -> Zmq.Socket.send_msg_all ~block:false t.socket)
let send_msg_all t messages =
request t t.senders (fun () -> Zmq.Socket.send_msg_all ~block:false t.socket messages)

let recv t =
request t t.receivers (fun () -> Zmq.Socket.recv ~block:false t.socket)
Expand Down
44 changes: 35 additions & 9 deletions zmq-eio/test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ let send env ?(delay = 0.0) s count =
in
fun () -> inner count

let send_all env ?(delay = 0.0) s count =
let rec inner = function
| 0 -> ()
| n ->
Zmq_eio.Socket.send_all s ["test1"; "test2"; "test3"];
sleepf env delay;
inner (n - 1)
in
fun () -> inner count

let recv env ?(delay = 0.0) s count =
let rec inner = function
| 0 -> ()
Expand All @@ -48,6 +58,16 @@ let recv env ?(delay = 0.0) s count =
in
fun () -> inner count

let recv_all env ?(delay = 0.0) s count =
let rec inner = function
| 0 -> ()
| n ->
let _ = Zmq_eio.Socket.recv_all s in
sleepf env delay;
inner (n - 1)
in
fun () -> inner count

(** Test functions *)
let test_setup_teardown ~sw:_ _env _s = ()

Expand All @@ -59,6 +79,12 @@ let test_send_receive ~sw:_ env (_, s1, s2) =
recv env s1 count;
]

let test_send_receive_all ~sw:_ env (_, s1, s2) =
all_ok [
send_all env s2 count;
recv_all env s1 count;
]

let test_msend_mreceive ~sw:_ env (_, s1, s2) =
all_ok [
send env s2 count; send env s2 count; send env s2 count; send env s2 count;
Expand Down Expand Up @@ -124,15 +150,15 @@ let suite () =
in

__MODULE__ >::: [
"test_setup_teardown" >:: bracket test_setup_teardown;
"test_send_receive" >:: bracket test_send_receive;
"test_msend_mreceive" >:: bracket test_msend_mreceive;
"test_mix" >:: bracket test_mix;
"test_slow_send" >:: bracket test_slow_send;
"test_slow_receive" >:: bracket test_slow_receive;
"test_slow_mix" >:: bracket test_slow_mix1;
"test_slow_mix" >:: bracket test_slow_mix2;
"test_send_receive" >:: bracket test_send_receive;
"test_setup_teardown" >:: bracket test_setup_teardown;
"test_send_receive" >:: bracket test_send_receive;
"test_msend_mreceive" >:: bracket test_msend_mreceive;
"test_mix" >:: bracket test_mix;
"test_slow_send" >:: bracket test_slow_send;
"test_slow_receive" >:: bracket test_slow_receive;
"test_slow_mix" >:: bracket test_slow_mix1;
"test_slow_mix" >:: bracket test_slow_mix2;
"test_send_receive_all" >:: bracket test_send_receive_all;
]


Expand Down

0 comments on commit 614de51

Please sign in to comment.