···5050 Sys.remove filename_out;
5151 Sys.remove filename_err)
52525353+let (let*) = Lwt.bind
5454+5555+5356let binary_handler process s =
5454- let ic = Unix.in_channel_of_descr s in
5555- let oc = Unix.out_channel_of_descr s in
5657 (* Read a 16 byte length encoded as a string *)
5758 let len_buf = Bytes.make 16 '\000' in
5858- really_input ic len_buf 0 (Bytes.length len_buf);
5959+ let* _ = Lwt_unix.read s len_buf 0 (Bytes.length len_buf) in
5960 let len = int_of_string (Bytes.unsafe_to_string len_buf) in
6061 let msg_buf = Bytes.make len '\000' in
6161- really_input ic msg_buf 0 (Bytes.length msg_buf);
6262- let ( >>= ) = M.bind in
6363- process msg_buf >>= fun result ->
6262+ let* _ = Lwt_unix.read s msg_buf 0 (Bytes.length msg_buf) in
6363+ let* result = process msg_buf in
6464 let len_buf = Printf.sprintf "%016d" (String.length result) in
6565- output_string oc len_buf;
6666- output_string oc result;
6767- flush oc;
6868- M.return ()
6565+ let* _ = Lwt_unix.write s (Bytes.of_string len_buf) 0 16 in
6666+ let* _ = Lwt_unix.write s (Bytes.of_string result) 0 (String.length result) in
6767+ Lwt.return ()
69687069let mkdir_rec dir perm =
7170 let rec p_mkdir dir =
···7675 p_mkdir dir
77767877let serve_requests rpcfn path =
7878+ let (let*) = Lwt.bind in
7979 (try Unix.unlink path with Unix.Unix_error (Unix.ENOENT, _, _) -> ());
8080 mkdir_rec (Filename.dirname path) 0o0755;
8181- let sock = Unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in
8282- Unix.bind sock (Unix.ADDR_UNIX path);
8383- Unix.listen sock 5;
8484- while true do
8585- let this_connection, _ = Unix.accept sock in
8686- Fun.protect
8787- ~finally:(fun () -> Unix.close this_connection)
8888- (fun () ->
8181+ let sock = Lwt_unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in
8282+ let* () = Lwt_unix.bind sock (Unix.ADDR_UNIX path) in
8383+ Lwt_unix.listen sock 5;
8484+ let rec loop () =
8585+ let* this_connection, _ = Lwt_unix.accept sock in
8686+ let* () =
8787+ Lwt.finalize (fun () ->
8988 (* Here I am calling M.run to make sure that I am running the process,
9089 this is not much of a problem with IdM or ExnM, but in general you
9190 should ensure that the computation is started by a runner. *)
9292- binary_handler rpcfn this_connection |> M.run)
9393- done
9191+ binary_handler rpcfn this_connection)
9292+ (fun () -> Lwt_unix.close this_connection)
9393+ in
9494+ loop ()
9595+ in
9696+ loop ()
94979598let handle_findlib_error = function
9699 | Failure msg -> Printf.fprintf stderr "%s" msg
···108111109112 let capture = capture
110113 let sync_get _ = None
114114+ let async_get _ = Lwt.return (Error (`Msg "Not implemented"))
111115 let create_file ~name:_ ~content:_ = failwith "Not implemented"
112116113117 let import_scripts urls =
···155159 Logs.set_level (Some Logs.Info);
156160 (* let pid = Unix.getpid () in *)
157161 Server.exec execute;
158158- Server.setup setup;
159159- Server.init init;
162162+ Server.setup (IdlM.T.lift setup);
163163+ Server.init (IdlM.T.lift init);
160164 Server.typecheck typecheck_phrase;
161165 Server.complete_prefix complete_prefix;
162166 Server.query_errors query_errors;
···165169 Server.exec_toplevel exec_toplevel;
166170 let rpc_fn = IdlM.server Server.implementation in
167171 let process x =
168168- let open M in
172172+ let open Lwt in
169173 rpc_fn (Jsonrpc.call_of_string (Bytes.unsafe_to_string x))
170174 >>= fun response -> Jsonrpc.string_of_response response |> return
171175 in
172176 serve_requests process Js_top_worker_rpc.Toplevel_api_gen.sockpath
173177174174-let _ = start_server ()
178178+let _ = Lwt_main.run (start_server ())