@ -59,24 +59,28 @@ 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 read () =
let fname = DB . filename_to_string fname_ in
try
match open_in_bin fname with
let fname = DB . filename_to_string _ fname in
| exception Sys_error _ ->
let inc = open_in_bin fname in
None
let value_option = match_data ( Marshal . from_channel inc ) fname in
| inc ->
close_in inc ;
let read () =
value_option
try
with
seek_in inc 0 ;
| Sys_error _ -> None in
match_data ( Marshal . from_channel inc ) fname
let timeout = 1 . 0 in
with
let catch_exn = function
| Sys_error _ -> None in
| End_of_file -> true
let timeout = 1 . 0 in
| Failure _ -> true (* handle input_value: truncated object *)
let catch_exn = function
| _ -> false in
| End_of_file -> true
(* Retry to read for 1 second in case of end of file, *)
| Failure _ -> true (* handle input_value: truncated object *)
(* which indicates that another process is writing the same file. *)
| _ -> false in
retry_exception timeout catch_exn read () in
(* Retry to read for 1 second in case of end of file, *)
(* which indicates that another process is writing the same file. *)
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: *)