mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 03:05:29 -05:00
put back active_connections
This commit is contained in:
parent
b539b4f9ba
commit
10b64c2a16
2 changed files with 9 additions and 1 deletions
|
|
@ -676,13 +676,14 @@ end
|
||||||
module Sem_ = struct
|
module Sem_ = struct
|
||||||
type t = {
|
type t = {
|
||||||
mutable n : int;
|
mutable n : int;
|
||||||
|
max : int;
|
||||||
mutex : Mutex.t;
|
mutex : Mutex.t;
|
||||||
cond : Condition.t;
|
cond : Condition.t;
|
||||||
}
|
}
|
||||||
|
|
||||||
let create n =
|
let create n =
|
||||||
if n <= 0 then invalid_arg "Semaphore.create";
|
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 =
|
let acquire m t =
|
||||||
Mutex.lock t.mutex;
|
Mutex.lock t.mutex;
|
||||||
|
|
@ -699,6 +700,8 @@ module Sem_ = struct
|
||||||
t.n <- t.n + m;
|
t.n <- t.n + m;
|
||||||
Condition.broadcast t.cond;
|
Condition.broadcast t.cond;
|
||||||
Mutex.unlock t.mutex
|
Mutex.unlock t.mutex
|
||||||
|
|
||||||
|
let num_acquired t = t.max - t.n
|
||||||
end
|
end
|
||||||
|
|
||||||
module Route = struct
|
module Route = struct
|
||||||
|
|
@ -843,6 +846,8 @@ type t = {
|
||||||
let addr self = self.addr
|
let addr self = self.addr
|
||||||
let port self = self.port
|
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_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 add_encode_response_cb self f = self.cb_encode_resp <- f :: self.cb_encode_resp
|
||||||
let set_top_handler self f = self.handler <- f
|
let set_top_handler self f = self.handler <- f
|
||||||
|
|
|
||||||
|
|
@ -476,6 +476,9 @@ val is_ipv6 : t -> bool
|
||||||
val port : t -> int
|
val port : t -> int
|
||||||
(** Port on which the server listens. *)
|
(** Port on which the server listens. *)
|
||||||
|
|
||||||
|
val active_connections : t -> int
|
||||||
|
(** Number of active connections *)
|
||||||
|
|
||||||
val add_decode_request_cb :
|
val add_decode_request_cb :
|
||||||
t ->
|
t ->
|
||||||
(unit Request.t -> (unit Request.t * (byte_stream -> byte_stream)) option) -> unit
|
(unit Request.t -> (unit Request.t * (byte_stream -> byte_stream)) option) -> unit
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue