let start_server () =
try
Unix.mkfifo socket_file 0o600 ;
let fd = Unix.openfile socket_file [Unix.O_RDONLY ; Unix.O_NONBLOCK] 0o600 in
let f () =
try
match Unix.select [fd] [] [] 0.0 with
[_],[],[] ->
handle_input fd
| _ -> true
with
Unix.Unix_error (e,s1,s2) ->
prerr_endline (Printf.sprintf "%s %s: %s" (Unix.error_message e) s1 s2);
true
| e ->
prerr_endline (Printexc.to_string e);
true
in
ignore (Glib.Timeout.add ~ms: 500 ~callback:f);
Pervasives.at_exit
(fun () ->
(try Unix.close fd with _ -> ());
(try Unix.unlink socket_file with _ -> ())
);
with
Unix.Unix_error (e,s1,s2) ->
failwith (Printf.sprintf "%s %s: %s" (Unix.error_message e) s1 s2)