mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-15 07:16:08 -05:00
put back active_connections
This commit is contained in:
parent
beacb64f05
commit
4c07bed496
3 changed files with 15 additions and 8 deletions
|
|
@ -181,7 +181,7 @@ module Byte_stream = struct
|
||||||
)
|
)
|
||||||
|
|
||||||
let to_chan (oc:out_channel) (self:t) =
|
let to_chan (oc:out_channel) (self:t) =
|
||||||
iter (fun s i len -> Stdlib.output oc s i len) self
|
iter (fun s i len -> output oc s i len) self
|
||||||
|
|
||||||
let of_bytes ?(i=0) ?len s : t =
|
let of_bytes ?(i=0) ?len s : t =
|
||||||
(* invariant: !i+!len is constant *)
|
(* invariant: !i+!len is constant *)
|
||||||
|
|
@ -762,14 +762,15 @@ end
|
||||||
(* semaphore, for limiting concurrency. *)
|
(* semaphore, for limiting concurrency. *)
|
||||||
module Sem_ = struct
|
module Sem_ = struct
|
||||||
type t = {
|
type t = {
|
||||||
mutable n : int;
|
mutable n : int;
|
||||||
mutex : Mutex.t;
|
max:int;
|
||||||
cond : Condition.t;
|
mutex : Mutex.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;
|
||||||
|
|
@ -786,6 +787,9 @@ 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 self = self.max - self.n
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Route = struct
|
module Route = struct
|
||||||
|
|
@ -928,6 +932,10 @@ 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 =
|
||||||
|
(* -1 because we decrease the semaphore before Unix.accept *)
|
||||||
|
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
|
||||||
|
|
|
||||||
2
src/dune
2
src/dune
|
|
@ -2,6 +2,6 @@
|
||||||
(library
|
(library
|
||||||
(name tiny_httpd)
|
(name tiny_httpd)
|
||||||
(public_name tiny_httpd)
|
(public_name tiny_httpd)
|
||||||
(libraries threads stdlib-shims)
|
(libraries threads)
|
||||||
(flags :standard -safe-string -warn-error -a+8)
|
(flags :standard -safe-string -warn-error -a+8)
|
||||||
(wrapped false))
|
(wrapped false))
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ build: [
|
||||||
]
|
]
|
||||||
depends: [
|
depends: [
|
||||||
"dune" { >= "2.0" }
|
"dune" { >= "2.0" }
|
||||||
"stdlib-shims"
|
|
||||||
"base-threads"
|
"base-threads"
|
||||||
"ocaml" { >= "4.04.0" }
|
"ocaml" { >= "4.04.0" }
|
||||||
"odoc" {with-doc}
|
"odoc" {with-doc}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue