mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 03:05:29 -05:00
wip: use statmemprof-notty
This commit is contained in:
parent
3f0e427bbf
commit
64e232e459
3 changed files with 6 additions and 8 deletions
|
|
@ -775,13 +775,6 @@ let run (self:t) : (unit,_) result =
|
||||||
let inet_addr = Unix.inet_addr_of_string self.addr in
|
let inet_addr = Unix.inet_addr_of_string self.addr in
|
||||||
Unix.bind sock (Unix.ADDR_INET (inet_addr, self.port));
|
Unix.bind sock (Unix.ADDR_INET (inet_addr, self.port));
|
||||||
Unix.listen sock (self.sem_max_connections.Sem_.n);
|
Unix.listen sock (self.sem_max_connections.Sem_.n);
|
||||||
|
|
||||||
ignore @@ Thread.create (fun () ->
|
|
||||||
while true do
|
|
||||||
_debug (fun k->k "sem: %d" self.sem_max_connections.n);
|
|
||||||
Unix.sleep 1;
|
|
||||||
done) ();
|
|
||||||
|
|
||||||
while self.running do
|
while self.running do
|
||||||
(* limit concurrency *)
|
(* limit concurrency *)
|
||||||
Sem_.acquire self.sem_max_connections;
|
Sem_.acquire self.sem_max_connections;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
|
|
||||||
(executables
|
(executables
|
||||||
(names echo)
|
(names echo)
|
||||||
(libraries tiny_httpd))
|
(libraries tiny_httpd statmemprof-notty))
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,10 @@ let () =
|
||||||
"/echo" (fun req -> S.Response.make_string (Ok (Format.asprintf "echo:@ %a@." S.Request.pp req)));
|
"/echo" (fun req -> S.Response.make_string (Ok (Format.asprintf "echo:@ %a@." S.Request.pp req)));
|
||||||
S.add_path_handler ~meth:`POST server
|
S.add_path_handler ~meth:`POST server
|
||||||
"/debug/%B" (fun b _req -> S._enable_debug b; S.Response.make_string (Ok "ok"));
|
"/debug/%B" (fun b _req -> S._enable_debug b; S.Response.make_string (Ok "ok"));
|
||||||
|
S.add_path_handler ~meth:`POST server
|
||||||
|
"/compact/" (fun _req -> Gc.compact(); S.Response.make_string (Ok "gc.compact: done"));
|
||||||
|
S.add_path_handler ~meth:`POST server
|
||||||
|
"/quit/" (fun _req -> S.stop server; S.Response.make_string (Ok "bye"));
|
||||||
S.add_path_handler ~meth:`PUT server
|
S.add_path_handler ~meth:`PUT server
|
||||||
"/upload/%s" (fun path req ->
|
"/upload/%s" (fun path req ->
|
||||||
S._debug (fun k->k "start upload %S\n%!" path);
|
S._debug (fun k->k "start upload %S\n%!" path);
|
||||||
|
|
@ -31,6 +35,7 @@ let () =
|
||||||
S.Response.fail ~code:500 "couldn't upload file: %s" (Printexc.to_string e)
|
S.Response.fail ~code:500 "couldn't upload file: %s" (Printexc.to_string e)
|
||||||
);
|
);
|
||||||
Printf.printf "listening on http://%s:%d\n%!" (S.addr server) (S.port server);
|
Printf.printf "listening on http://%s:%d\n%!" (S.addr server) (S.port server);
|
||||||
|
ignore @@ Thread.create (fun () -> Statmemprof_inuit.start 1e-4 300 2) ();
|
||||||
match S.run server with
|
match S.run server with
|
||||||
| Ok () -> ()
|
| Ok () -> ()
|
||||||
| Error e -> raise e
|
| Error e -> raise e
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue