mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-07 11:45:36 -05:00
parent
bc34363f60
commit
e07e9298e3
4 changed files with 12 additions and 6 deletions
|
|
@ -1,3 +1,6 @@
|
||||||
|
## Pending
|
||||||
|
|
||||||
|
- fix: No setting of sigprocmask on Windows
|
||||||
|
|
||||||
## 0.16
|
## 0.16
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ open struct
|
||||||
slice.len <- 0
|
slice.len <- 0
|
||||||
end
|
end
|
||||||
|
|
||||||
let create ?(masksigpipe = true) ?max_connections ?(timeout = 0.0) ?buf_size
|
let create ?(masksigpipe = not (Sys.win32)) ?max_connections ?(timeout = 0.0) ?buf_size
|
||||||
?(get_time_s = Unix.gettimeofday)
|
?(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 =
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,8 @@ val create :
|
||||||
{!set_top_handler} to specify how to handle incoming requests.
|
{!set_top_handler} to specify how to handle incoming requests.
|
||||||
|
|
||||||
@param masksigpipe if true, block the signal {!Sys.sigpipe} which otherwise
|
@param masksigpipe if true, block the signal {!Sys.sigpipe} which otherwise
|
||||||
tends to kill client threads when they try to write on broken sockets. Default: [true].
|
tends to kill client threads when they try to write on broken sockets.
|
||||||
|
Default: [true] except when on Windows, which defaults to [false].
|
||||||
|
|
||||||
@param buf_size size for buffers (since 0.11)
|
@param buf_size size for buffers (since 0.11)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 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 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,6 +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
|
||||||
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
|
||||||
|
|
@ -136,6 +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
|
||||||
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), _, _)
|
||||||
->
|
->
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue