@ -59,14 +59,16 @@ let create_serializer (key : key) : 'a serializer =
try
try
match_data ( Marshal . from_string str 0 ) " string "
match_data ( Marshal . from_string str 0 ) " string "
with Sys_error _ -> None in
with Sys_error _ -> None in
let from_file ( _ fname : DB . filename ) : ' a option =
let from_file ( fname_ : DB . filename ) : ' a option =
let fname = DB . filename_to_string fname_ in
match open_in_bin fname with
| exception Sys_error _ ->
None
| inc ->
let read () =
let read () =
try
try
let fname = DB . filename_to_string _ fname in
seek_in inc 0 ;
let inc = open_in_bin fname in
match_data ( Marshal . from_channel inc ) fname
let value_option = match_data ( Marshal . from_channel inc ) fname in
close_in inc ;
value_option
with
with
| Sys_error _ -> None in
| Sys_error _ -> None in
let timeout = 1 . 0 in
let timeout = 1 . 0 in
@ -76,7 +78,9 @@ let create_serializer (key : key) : 'a serializer =
| _ -> false in
| _ -> false in
(* Retry to read for 1 second in case of end of file, *)
(* Retry to read for 1 second in case of end of file, *)
(* which indicates that another process is writing the same file. *)
(* which indicates that another process is writing the same file. *)
retry_exception timeout catch_exn read () in
SymOp . try_finally
( fun () -> retry_exception timeout catch_exn read () )
( fun () -> close_in inc ) in
let to_file ( fname : DB . filename ) ( value : ' a ) =
let to_file ( fname : DB . filename ) ( value : ' a ) =
let fname_str = DB . filename_to_string fname in
let fname_str = DB . filename_to_string fname in
(* support nonblocking reads and writes in parallel: *)
(* support nonblocking reads and writes in parallel: *)