diff options
author | Alex AUVOLAT <alex.auvolat@ens.fr> | 2014-03-20 15:58:02 +0100 |
---|---|---|
committer | Alex AUVOLAT <alex.auvolat@ens.fr> | 2014-03-20 15:58:02 +0100 |
commit | 084745ffe51234e366ed6627d9f697c47d87bb4a (patch) | |
tree | d8c34ec6602e74f690137225305445e3ac05d7b2 | |
parent | bfafa7dbc3325749358538a95cbb4831db66b03c (diff) | |
download | SystemeReseaux-Projet-084745ffe51234e366ed6627d9f697c47d87bb4a.tar.gz SystemeReseaux-Projet-084745ffe51234e366ed6627d9f697c47d87bb4a.zip |
Work on KHB/KHS
-rw-r--r-- | khb/khs_exec_local.ml | 37 | ||||
-rw-r--r-- | khb/test.ml | 2 |
2 files changed, 10 insertions, 29 deletions
diff --git a/khb/khs_exec_local.ml b/khb/khs_exec_local.ml index fb97b47..09f14a8 100644 --- a/khb/khs_exec_local.ml +++ b/khb/khs_exec_local.ml @@ -12,30 +12,6 @@ let wait_childs () = List.iter (fun pid -> ignore (Unix.waitpid [] pid)) !childs) () -let max_chans = 12 -let ochans = Hashtbl.create 12 -let ochans_time = ref Smap.empty -let get_chan id = - ochans_time := Smap.map (fun v -> v+1) !ochans_time; - ochans_time := Smap.add id 0 !ochans_time; - if Smap.cardinal !ochans_time > max_chans then begin - let maxchan, _ = - Smap.fold - (fun k v (mk, mv) -> if v > mv then (k, v) else (mk, mv)) - !ochans_time ("", 0) in - let i_fd, o_fd = Hashtbl.find ochans maxchan in - Unix.close i_fd; Unix.close o_fd; - Hashtbl.remove ochans maxchan; - ochans_time := Smap.remove maxchan !ochans_time - end; - try - Hashtbl.find ochans id - with Not_found -> - let i, o = Unix.openfile ("/tmp/"^id) [Unix.O_RDONLY] 0, - Unix.openfile ("/tmp/"^id) [Unix.O_WRONLY] 0 in - Hashtbl.add ochans id (i, o); - i, o - let newchan proc = let id = "khs_ch_" ^ string_of_int (Random.int 1000000) ^ "-" ^ string_of_int (Random.int 1000000) in @@ -50,17 +26,22 @@ let exec_proc proc = | PSExec | PSExecRecvd _ -> exec_stmt proc | PSSend(c, kv) -> + let c = str_of_kbval c in proc.xstatus <- PSExec; begin if c == "stdout" then Format.printf "%s@." (kval_descr kv) else - let _, c_out = get_chan c in - Marshal.to_channel (Unix.out_channel_of_descr c_out) kv [] + let c_out = Unix.openfile ("/tmp/"^c) [Unix.O_WRONLY] 0 in + Marshal.to_channel (Unix.out_channel_of_descr c_out) kv []; + Unix.close c_out end | PSRecv c -> - let c_in, _ = get_chan c in - proc.xstatus <- PSExecRecvd (Marshal.from_channel (Unix.in_channel_of_descr c_in)) + let c = str_of_kbval c in + let c_in = Unix.openfile ("/tmp/"^c) [Unix.O_RDONLY] 0 in + let data = Marshal.from_channel (Unix.in_channel_of_descr c_in) in + proc.xstatus <- PSExecRecvd data; + Unix.close c_in done let spawn proc pos = diff --git a/khb/test.ml b/khb/test.ml index 68e3697..edc155e 100644 --- a/khb/test.ml +++ b/khb/test.ml @@ -98,4 +98,4 @@ let primes_khs = [| let () = Array.iter Ksh_print.print_stmt primes_khs; - Khs_exec_seq.exec_program (load_program primes_khs) + Khs_exec_local.exec_program (load_program primes_khs) |