From e8d750e4fd4aeaba6a5e5c5a24ac6ab8aa3c10a5 Mon Sep 17 00:00:00 2001 From: Fardale Date: Wed, 29 May 2019 13:10:27 +0200 Subject: [PATCH] use write_line and read_line to send and receive data By doing this node and server will be able to acknowledge the good reception of the data and if not communication can be repeat. --- src/client.ml | 2 +- src/master.ml | 4 ++-- src/node.ml | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/client.ml b/src/client.ml index 02ad9a5..ab5171e 100644 --- a/src/client.ml +++ b/src/client.ml @@ -6,4 +6,4 @@ let cmd cpu ram time iteration port script_file pass addr = Lwt_io.with_connection (Lwt_unix.ADDR_INET (Unix.inet_addr_of_string addr, port)) (fun (_ic, oc) -> - Lwt_io.write oc (Serialization_j.string_of_query (`JOB submission)) ) + Lwt_io.write_line oc (Serialization_j.string_of_query (`JOB submission)) ) diff --git a/src/master.ml b/src/master.ml index 36c9804..bd75fdb 100644 --- a/src/master.ml +++ b/src/master.ml @@ -60,7 +60,7 @@ let rec launch_job () = n.port ) >>= fun () -> Lwt_io.with_connection sockaddr (fun (_ic, oc) -> - Lwt_io.write oc (Serialization_j.string_of_query (`COMPUTATION j)) + Lwt_io.write_line oc (Serialization_j.string_of_query (`COMPUTATION j)) ) (* TODO: check return value *) >>= Lwt.pause @@ -68,7 +68,7 @@ let rec launch_job () = else Logs_lwt.debug (fun m -> m "No compuatiton") let server_handler pass port sockaddr (ic, _oc) = - Lwt_io.read ic + Lwt_io.read_line ic >>= fun json -> match CCResult.guard (fun () -> Serialization_j.query_of_string json) with | Result.Ok query -> ( diff --git a/src/node.ml b/src/node.ml index ca00456..bd1f7a1 100644 --- a/src/node.ml +++ b/src/node.ml @@ -13,7 +13,7 @@ let process_status_to_ret_code = function let run_computation (computation : computation) = Lwt_io.with_temp_file ~prefix:"ocluster" ~perm:0o700 (fun (name, oc) -> - Lwt_io.write oc computation.script + Lwt_io.write_line oc computation.script >>= fun () -> Lwt_io.close oc >>= fun () -> @@ -52,16 +52,16 @@ let handle_computation sockaddr computation () = s in Lwt_io.with_connection sockaddr (fun (_ic, oc) -> - Lwt_io.write oc (Serialization_j.string_of_query (`RESULT result)) ) + Lwt_io.write_line oc (Serialization_j.string_of_query (`RESULT result)) ) (* TODO: rendre ça résistant au crash du serveur *) >>= fun () -> Logs_lwt.debug (fun m -> m "End computation %i,%i" (fst computation.id) (snd computation.id) ) -let stat oc = Lwt_io.write_value oc `OK +let stat oc = Lwt_io.write_line oc (Serialization_j.string_of_stat `OK) let server_handler pass sockaddr (ic, oc) = - Lwt_io.read ic + Lwt_io.read_line ic >>= fun json -> ( match CCResult.guard (fun () -> Serialization_j.query_of_string json) with | Result.Ok query -> ( -- GitLab