]> matita.cs.unibo.it Git - helm.git/blobdiff - daemons/graphs/tools/uriSetQueue.ml
ensure connections get closed after having been served
[helm.git] / daemons / graphs / tools / uriSetQueue.ml
index 43027580016fe58101457ccc8ae38398ff8f0e8c..86bfe35f38c631237c402dddaa73cd4f428e4cbd 100644 (file)
@@ -76,7 +76,7 @@ let queue_mem item queue =  (* mem function over queues *)
   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;
@@ -181,6 +181,13 @@ let callback (req: Http_types.request) outchan =
         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;