diff --git a/src/Tiny_httpd.ml b/src/Tiny_httpd.ml index 4ba154cd..0270ca90 100644 --- a/src/Tiny_httpd.ml +++ b/src/Tiny_httpd.ml @@ -676,13 +676,14 @@ end module Sem_ = struct type t = { mutable n : int; + max : int; mutex : Mutex.t; cond : Condition.t; } let create n = if n <= 0 then invalid_arg "Semaphore.create"; - { n; mutex=Mutex.create(); cond=Condition.create(); } + { n; max=n; mutex=Mutex.create(); cond=Condition.create(); } let acquire m t = Mutex.lock t.mutex; @@ -699,6 +700,8 @@ module Sem_ = struct t.n <- t.n + m; Condition.broadcast t.cond; Mutex.unlock t.mutex + + let num_acquired t = t.max - t.n end module Route = struct @@ -843,6 +846,8 @@ type t = { let addr self = self.addr let port self = self.port +let active_connections self = Sem_.num_acquired self.sem_max_connections - 1 + let add_decode_request_cb self f = self.cb_decode_req <- f :: self.cb_decode_req let add_encode_response_cb self f = self.cb_encode_resp <- f :: self.cb_encode_resp let set_top_handler self f = self.handler <- f diff --git a/src/Tiny_httpd.mli b/src/Tiny_httpd.mli index ffa8e639..f9bf9a15 100644 --- a/src/Tiny_httpd.mli +++ b/src/Tiny_httpd.mli @@ -476,6 +476,9 @@ val is_ipv6 : t -> bool val port : t -> int (** Port on which the server listens. *) +val active_connections : t -> int +(** Number of active connections *) + val add_decode_request_cb : t -> (unit Request.t -> (unit Request.t * (byte_stream -> byte_stream)) option) -> unit