solution in Ocaml 3.09.2), we use the new ~auto_close feature of libhttp-ocaml.
| Unix.WSIGNALED n -> sprintf "Process killed by signal %d" n
| Unix.WSTOPPED n -> sprintf "Process stopped by signal %d" n
in
-let callback ((req: Http_types.request), outchan) =
+let callback (req: Http_types.request) outchan =
try
(match req#path with
| "/draw" ->
~body:(sprintf "Parameter '%s' is missing" attr_name)
outchan
in
-let callback req ch =
- HExtlib.finally
- (fun () -> try close_out ch with Sys_error _ -> ())
- callback (req, ch)
-in
Helm_registry.load_from configuration_file;
let port = Helm_registry.get_int "draw_graph.port" in
Sys.chdir (Helm_registry.get "draw_graph.dir");
printf "%s started and listening on port %d\n" daemon_name port;
printf "current directory is %s\n" (Sys.getcwd ());
flush stdout;
-let d_spec = Http_daemon.daemon_spec ~port ~callback () in
+let d_spec = Http_daemon.daemon_spec ~port ~callback ~auto_close:true () in
Http_daemon.main d_spec;
printf "%s is terminating, bye!\n" daemon_name
with Found -> true
;;
-let callback ((req: Http_types.request), outchan) =
+let callback (req: Http_types.request) outchan =
try
let res = new Http_response.response () in
res#addBasicHeaders;
outchan
in
-let callback req ch =
- HExtlib.finally
- (fun () -> try close_out ch with Sys_error _ -> ())
- callback (req, ch)
-
-in
-
Helm_registry.load_from configuration_file;
let port = Helm_registry.get_int "uri_set_queue.port" in
printf "%s started and listening on port %d\n" daemon_name port;
flush stdout;
-let d_spec = Http_daemon.daemon_spec ~port ~mode:`Thread ~callback () in
+let d_spec = Http_daemon.daemon_spec ~port ~mode:`Thread ~auto_close:true ~callback () in
Http_daemon.main d_spec;
printf "%s is terminating, bye!\n" daemon_name
(* thread action *)
-let callback ((req: Http_types.request), outchan) =
+let callback (req: Http_types.request) outchan =
try
Http_getter_logger.log ("Connection from " ^ req#clientAddr);
Http_getter_logger.log ("Received request: " ^ req#uri);
log_failure msg;
return_html_error ("uncaught_exception", msg) msg outchan)
-let callback req outchan =
- HExtlib.finally
- (fun () -> try close_out outchan with Sys_error _ -> ())
- callback (req, outchan)
-
let batch_update = ref false
let args = [ ]
let d_spec = Http_daemon.daemon_spec
~mode:`Thread ~timeout:(Some 600)
~port:(Lazy.force Http_getter_env.port)
+ ~auto_close:true
~callback:callback ()
in
try
flush !outchan)
;;
-let callback ((req : Http_types.request), outchan') =
+let callback (req : Http_types.request) outchan' =
match req#path with
| "/proofCheck" ->
begin
in
-let callback req ch =
- HExtlib.finally
- (fun () -> try close_out ch with Sys_error _ -> ())
- callback (req, ch)
-
-in
printf "Proof Checker started and listening on port %d\n" port;
flush stdout;
CicEnvironment.set_trust (fun _ -> false);
-let d_spec = Http_daemon.daemon_spec ~port ~mode:`Fork ~callback () in
+let d_spec = Http_daemon.daemon_spec ~port ~mode:`Fork ~callback ~auto_close:true () in
Http_daemon.main d_spec;
printf "Proof Checker is terminating, bye!\n"
let user = get_option "rdfly.mysql_connection.user";;
let daemonport = Helm_registry.get_int "rdfly.port";;
-let callback ((req: Http_types.request), ch) =
+let callback (req: Http_types.request) ch =
try
debug_print ("Connection from " ^ req#clientAddr) ;
debug_print ("Received request: " ^ req#uri) ;
| exc ->
return_html_error ("Uncaught exception: " ^ (Printexc.to_string exc)) ch
-let callback req ch =
- HExtlib.finally
- (fun () -> try close_out ch with Sys_error _ -> ())
- callback (req, ch)
-
let main () =
Sys.catch_break true;
try
let d_spec =
- Http_daemon.daemon_spec ~timeout:(Some 600) ~port:daemonport ~callback ()
+ Http_daemon.daemon_spec ~timeout:(Some 600) ~port:daemonport ~callback ~auto_close:true ()
in
Http_daemon.main d_spec
with Sys.Break -> ()
return_error ("Uncaught exception: " ^ (Printexc.to_string exc)) outchan
;;
-let callback
- ~syslogger ~styles ~cmd_pipe ~res_pipe () (req: Http_types.request) outchan
-=
- HExtlib.finally
- (fun () -> try close_out outchan with Sys_error _ -> ())
- (callback ~syslogger ~styles ~cmd_pipe ~res_pipe () req) outchan
-
(* UWOBO's startup *)
let main () =
(* (1) system logger *)
requests until it will get killed by father *)
let d_spec = Http_daemon.daemon_spec
~port ~mode:`Fork
- ~callback:(callback ~syslogger ~styles ~cmd_pipe ~res_pipe ()) ()
+ ~callback:(callback ~syslogger ~styles ~cmd_pipe ~res_pipe ())
+ ~auto_close:true ()
in
Http_daemon.main d_spec
| _ (* < 0 *) -> (* fork failed :-((( *)
^ " type")))
req outchan
-let callback (dbd, (req: Http_types.request), outchan) =
+let callback dbd (req: Http_types.request) outchan =
try
debug_print (sprintf "Received request: %s" req#path);
(match req#path with
let msg = MooglePp.pp_error "Uncaught exception" exn_string in
send_results (`Error msg) req outchan
-let callback dbd req ch =
- HExtlib.finally
- (fun () -> try close_out ch with Sys_error _ -> ())
- callback (dbd, req, ch)
-
let restore_environment () =
match
Helm_registry.get_opt Helm_registry.string "search_engine.environment_dump"
in
restore_environment ();
read_notation ();
- let d_spec = Http_daemon.daemon_spec ~port ~callback:(callback dbd) () in
+ let d_spec = Http_daemon.daemon_spec ~port ~callback:(callback dbd) ~auto_close:true () in
Http_daemon.main d_spec;
printf "%s is terminating, bye!\n" daemon_name