mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 11:15:35 -05:00
format
This commit is contained in:
parent
0fbfd9df43
commit
de9760d786
14 changed files with 82 additions and 74 deletions
|
|
@ -27,8 +27,8 @@ open struct
|
||||||
slice.len <- 0
|
slice.len <- 0
|
||||||
end
|
end
|
||||||
|
|
||||||
let create ?(masksigpipe = not (Sys.win32)) ?max_connections ?(timeout = 0.0) ?buf_size
|
let create ?(masksigpipe = not Sys.win32) ?max_connections ?(timeout = 0.0)
|
||||||
?(get_time_s = Unix.gettimeofday)
|
?buf_size ?(get_time_s = Unix.gettimeofday)
|
||||||
?(new_thread = fun f -> ignore (Thread.create f () : Thread.t))
|
?(new_thread = fun f -> ignore (Thread.create f () : Thread.t))
|
||||||
?(addr = "127.0.0.1") ?(port = 8080) ?sock ?middlewares () : t =
|
?(addr = "127.0.0.1") ?(port = 8080) ?sock ?middlewares () : t =
|
||||||
let max_connections = get_max_connection_ ?max_connections () in
|
let max_connections = get_max_connection_ ?max_connections () in
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
(public_name tiny_httpd_camlzip)
|
(public_name tiny_httpd_camlzip)
|
||||||
(synopsis "A wrapper around camlzip to bring compression to Tiny_httpd")
|
(synopsis "A wrapper around camlzip to bring compression to Tiny_httpd")
|
||||||
(flags :standard -open Tiny_httpd_core -safe-string -warn-error -a+8)
|
(flags :standard -open Tiny_httpd_core -safe-string -warn-error -a+8)
|
||||||
(libraries (re_export tiny_httpd.core)
|
(libraries
|
||||||
(re_export iostream-camlzip)
|
(re_export tiny_httpd.core)
|
||||||
camlzip))
|
(re_export iostream-camlzip)
|
||||||
|
camlzip))
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,17 @@
|
||||||
|
|
||||||
(library
|
(library
|
||||||
(name tiny_httpd_core)
|
(name tiny_httpd_core)
|
||||||
(public_name tiny_httpd.core)
|
(public_name tiny_httpd.core)
|
||||||
(private_modules parse_ common_)
|
(private_modules parse_ common_)
|
||||||
(libraries threads seq hmap iostream
|
(libraries
|
||||||
(select log.ml from
|
threads
|
||||||
(logs -> log.logs.ml)
|
seq
|
||||||
(-> log.default.ml))))
|
hmap
|
||||||
|
iostream
|
||||||
|
(select
|
||||||
|
log.ml
|
||||||
|
from
|
||||||
|
(logs -> log.logs.ml)
|
||||||
|
(-> log.default.ml))))
|
||||||
|
|
||||||
(rule
|
(rule
|
||||||
(targets Atomic_.ml)
|
(targets Atomic_.ml)
|
||||||
|
|
|
||||||
18
src/dune
18
src/dune
|
|
@ -1,8 +1,12 @@
|
||||||
(library
|
(library
|
||||||
(name tiny_httpd)
|
(name tiny_httpd)
|
||||||
(public_name tiny_httpd)
|
(public_name tiny_httpd)
|
||||||
(flags :standard -open Tiny_httpd_core)
|
(flags :standard -open Tiny_httpd_core)
|
||||||
(libraries threads seq unix hmap
|
(libraries
|
||||||
(re_export tiny_httpd.core)
|
threads
|
||||||
(re_export tiny_httpd.html)
|
seq
|
||||||
(re_export tiny_httpd.unix)))
|
unix
|
||||||
|
hmap
|
||||||
|
(re_export tiny_httpd.core)
|
||||||
|
(re_export tiny_httpd.html)
|
||||||
|
(re_export tiny_httpd.unix)))
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
|
|
||||||
|
|
||||||
(library
|
(library
|
||||||
(name tiny_httpd_html)
|
(name tiny_httpd_html)
|
||||||
(public_name tiny_httpd.html)
|
(public_name tiny_httpd.html)
|
||||||
(flags :standard -open Tiny_httpd_core)
|
(flags :standard -open Tiny_httpd_core)
|
||||||
(libraries seq tiny_httpd.core))
|
(libraries seq tiny_httpd.core))
|
||||||
|
|
||||||
(rule
|
(rule
|
||||||
(targets html_.ml)
|
(targets html_.ml)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
(library
|
(library
|
||||||
(name tiny_httpd_prometheus)
|
(name tiny_httpd_prometheus)
|
||||||
(public_name tiny_httpd.prometheus)
|
(public_name tiny_httpd.prometheus)
|
||||||
|
|
@ -7,7 +5,10 @@
|
||||||
(private_modules common_p_ time_)
|
(private_modules common_p_ time_)
|
||||||
(flags :standard -open Tiny_httpd_core)
|
(flags :standard -open Tiny_httpd_core)
|
||||||
(libraries
|
(libraries
|
||||||
(re_export tiny_httpd.core) unix
|
(re_export tiny_httpd.core)
|
||||||
(select time_.ml from
|
unix
|
||||||
|
(select
|
||||||
|
time_.ml
|
||||||
|
from
|
||||||
(mtime mtime.clock.os -> time_.mtime.ml)
|
(mtime mtime.clock.os -> time_.mtime.ml)
|
||||||
(-> time_.default.ml))))
|
(-> time_.default.ml))))
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
|
|
||||||
(library
|
(library
|
||||||
(name tiny_httpd_unix)
|
(name tiny_httpd_unix)
|
||||||
(public_name tiny_httpd.unix)
|
(public_name tiny_httpd.unix)
|
||||||
(synopsis "Backend based on Unix and blocking IOs for Tiny_httpd")
|
(synopsis "Backend based on Unix and blocking IOs for Tiny_httpd")
|
||||||
(flags :standard -open Tiny_httpd_core)
|
(flags :standard -open Tiny_httpd_core)
|
||||||
(private_modules mime_)
|
(private_modules mime_)
|
||||||
(libraries tiny_httpd.core tiny_httpd.html unix
|
(libraries
|
||||||
(select mime_.ml from
|
tiny_httpd.core
|
||||||
(magic-mime -> mime_.magic.ml)
|
tiny_httpd.html
|
||||||
( -> mime_.dummy.ml))
|
unix
|
||||||
))
|
(select
|
||||||
|
mime_.ml
|
||||||
|
from
|
||||||
|
(magic-mime -> mime_.magic.ml)
|
||||||
|
(-> mime_.dummy.ml))))
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1 @@
|
||||||
|
val mime_of_path : string -> string
|
||||||
val mime_of_path : string -> string
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ module Unix_tcp_server_ = struct
|
||||||
{
|
{
|
||||||
IO.TCP_server.serve =
|
IO.TCP_server.serve =
|
||||||
(fun ~after_init ~handle () : unit ->
|
(fun ~after_init ~handle () : unit ->
|
||||||
if self.masksigpipe && not (Sys.win32) then
|
if self.masksigpipe && not Sys.win32 then
|
||||||
ignore (Unix.sigprocmask Unix.SIG_BLOCK [ Sys.sigpipe ] : _ list);
|
ignore (Unix.sigprocmask Unix.SIG_BLOCK [ Sys.sigpipe ] : _ list);
|
||||||
let sock, should_bind =
|
let sock, should_bind =
|
||||||
match self.sock with
|
match self.sock with
|
||||||
|
|
@ -83,7 +83,7 @@ module Unix_tcp_server_ = struct
|
||||||
(Thread.id @@ Thread.self ())
|
(Thread.id @@ Thread.self ())
|
||||||
(Util.show_sockaddr client_addr));
|
(Util.show_sockaddr client_addr));
|
||||||
|
|
||||||
if self.masksigpipe && not (Sys.win32) then
|
if self.masksigpipe && not Sys.win32 then
|
||||||
ignore (Unix.sigprocmask Unix.SIG_BLOCK [ Sys.sigpipe ] : _ list);
|
ignore (Unix.sigprocmask Unix.SIG_BLOCK [ Sys.sigpipe ] : _ list);
|
||||||
Unix.set_nonblock client_sock;
|
Unix.set_nonblock client_sock;
|
||||||
Unix.setsockopt client_sock Unix.TCP_NODELAY true;
|
Unix.setsockopt client_sock Unix.TCP_NODELAY true;
|
||||||
|
|
@ -113,7 +113,7 @@ module Unix_tcp_server_ = struct
|
||||||
Sem.acquire 1 self.sem_max_connections;
|
Sem.acquire 1 self.sem_max_connections;
|
||||||
(* Block INT/HUP while cloning to avoid children handling them.
|
(* Block INT/HUP while cloning to avoid children handling them.
|
||||||
When thread gets them, our Unix.accept raises neatly. *)
|
When thread gets them, our Unix.accept raises neatly. *)
|
||||||
if not (Sys.win32) then
|
if not Sys.win32 then
|
||||||
ignore Unix.(sigprocmask SIG_BLOCK Sys.[ sigint; sighup ]);
|
ignore Unix.(sigprocmask SIG_BLOCK Sys.[ sigint; sighup ]);
|
||||||
self.new_thread (fun () ->
|
self.new_thread (fun () ->
|
||||||
try
|
try
|
||||||
|
|
@ -137,7 +137,7 @@ module Unix_tcp_server_ = struct
|
||||||
(Util.show_sockaddr client_addr)
|
(Util.show_sockaddr client_addr)
|
||||||
(Printexc.to_string e)
|
(Printexc.to_string e)
|
||||||
(Printexc.raw_backtrace_to_string bt)));
|
(Printexc.raw_backtrace_to_string bt)));
|
||||||
if not (Sys.win32) then
|
if not Sys.win32 then
|
||||||
ignore Unix.(sigprocmask SIG_UNBLOCK Sys.[ sigint; sighup ])
|
ignore Unix.(sigprocmask SIG_UNBLOCK Sys.[ sigint; sighup ])
|
||||||
| exception Unix.Unix_error ((Unix.EAGAIN | Unix.EWOULDBLOCK), _, _)
|
| exception Unix.Unix_error ((Unix.EAGAIN | Unix.EWOULDBLOCK), _, _)
|
||||||
->
|
->
|
||||||
|
|
|
||||||
23
src/ws/dune
23
src/ws/dune
|
|
@ -1,12 +1,13 @@
|
||||||
|
|
||||||
(library
|
(library
|
||||||
(name tiny_httpd_ws)
|
(name tiny_httpd_ws)
|
||||||
(public_name tiny_httpd.ws)
|
(public_name tiny_httpd.ws)
|
||||||
(synopsis "Websockets for tiny_httpd")
|
(synopsis "Websockets for tiny_httpd")
|
||||||
(private_modules common_ws_ utils_)
|
(private_modules common_ws_ utils_)
|
||||||
(flags :standard -open Tiny_httpd_core)
|
(flags :standard -open Tiny_httpd_core)
|
||||||
(foreign_stubs
|
(foreign_stubs
|
||||||
(language c)
|
(language c)
|
||||||
(names tiny_httpd_ws_stubs)
|
(names tiny_httpd_ws_stubs)
|
||||||
(flags :standard -std=c99 -fPIC -O2))
|
(flags :standard -std=c99 -fPIC -O2))
|
||||||
(libraries (re_export tiny_httpd.core) threads))
|
(libraries
|
||||||
|
(re_export tiny_httpd.core)
|
||||||
|
threads))
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
(test
|
(test
|
||||||
(name t_prom)
|
(name t_prom)
|
||||||
(libraries tiny_httpd.prometheus))
|
(libraries tiny_httpd.prometheus))
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
|
|
||||||
(tests
|
(tests
|
||||||
(names t_util t_buf t_server t_io)
|
(names t_util t_buf t_server t_io)
|
||||||
(package tiny_httpd)
|
(package tiny_httpd)
|
||||||
(libraries tiny_httpd.core qcheck-core qcheck-core.runner test_util))
|
(libraries tiny_httpd.core qcheck-core qcheck-core.runner test_util))
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
|
|
||||||
(library
|
(library
|
||||||
(name test_util)
|
(name test_util)
|
||||||
(modules test_util)
|
(modules test_util)
|
||||||
(libraries logs qcheck-core qcheck-core.runner))
|
(libraries logs qcheck-core qcheck-core.runner))
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
|
|
||||||
(tests
|
(tests
|
||||||
(names t_ws t_ws_q)
|
(names t_ws t_ws_q)
|
||||||
(package tiny_httpd)
|
(package tiny_httpd)
|
||||||
(deps masked.data)
|
(deps masked.data)
|
||||||
(libraries tiny_httpd.ws qcheck-core qcheck-core.runner test_util))
|
(libraries tiny_httpd.ws qcheck-core qcheck-core.runner test_util))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue