@@ -22,29 +22,10 @@ let _print_request fmt request =
2222
2323let connections = Hashtbl. create 256
2424
25- let ( get_number_of_connected
26- , incr_connected
27- , decr_connected
28- , _wait_fewer_connected )
29- =
25+ let get_number_of_connected, incr_connected, decr_connected =
26+ (* TODO: Use Atomic once the 4.12 dependency is acceptable. *)
3027 let connected = ref 0 in
31- let maxr = ref (- 1000 ) in
32- let mvar = Lwt_mvar. create_empty () in
33- ( (fun () -> ! connected)
34- , (fun n -> connected := ! connected + n)
35- , (fun () ->
36- let c = ! connected in
37- connected := c - 1 ;
38- if ! connected < 0 then exit 1 ;
39- if c = ! maxr
40- then (
41- Lwt_log. ign_warning ~section " Number of connections now ok" ;
42- maxr := - 1000 ;
43- Lwt_mvar. put mvar () )
44- else Lwt. return () )
45- , fun max ->
46- maxr := max;
47- Lwt_mvar. take mvar )
28+ (fun () -> ! connected), (fun () -> incr connected), fun () -> decr connected
4829
4930exception Ocsigen_is_dir of (Ocsigen_request. t -> Uri. t)
5031
@@ -116,7 +97,7 @@ let handler ~ssl ~address ~port ~connector (flow, conn) request body =
11697 with Not_found ->
11798 let ((connection_closed, _) as p ) = Lwt. wait () in
11899 Hashtbl. add connections conn p;
119- incr_connected 1 ;
100+ incr_connected () ;
120101 connection_closed
121102 in
122103 let handle_error exn =
@@ -212,7 +193,7 @@ let conn_closed (_flow, conn) =
212193 (Cohttp.Connection. to_string conn);
213194 Lwt. wakeup (snd (Hashtbl. find connections conn)) () ;
214195 Hashtbl. remove connections conn;
215- Lwt. async decr_connected
196+ decr_connected ()
216197 with Not_found -> ()
217198
218199let stop, stop_wakener = Lwt. wait ()
0 commit comments