mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-07 11:45:36 -05:00
fix: do not block in accept
This commit is contained in:
parent
38680e080c
commit
b2b637041b
1 changed files with 11 additions and 6 deletions
|
|
@ -937,11 +937,14 @@ module Unix_tcp_server_ = struct
|
||||||
()
|
()
|
||||||
in
|
in
|
||||||
|
|
||||||
|
Unix.set_nonblock sock;
|
||||||
while self.running do
|
while self.running do
|
||||||
|
ignore (Unix.select [ sock ] [] [ sock ] 1.0 : _ * _ * _);
|
||||||
|
match Unix.accept sock with
|
||||||
|
| client_sock, client_addr ->
|
||||||
(* limit concurrency *)
|
(* limit concurrency *)
|
||||||
Sem_.acquire 1 self.sem_max_connections;
|
Sem_.acquire 1 self.sem_max_connections;
|
||||||
try
|
|
||||||
let client_sock, client_addr = Unix.accept sock in
|
|
||||||
Unix.setsockopt client_sock Unix.TCP_NODELAY true;
|
Unix.setsockopt client_sock Unix.TCP_NODELAY true;
|
||||||
(* 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. *)
|
||||||
|
|
@ -955,8 +958,10 @@ module Unix_tcp_server_ = struct
|
||||||
Sem_.release 1 self.sem_max_connections;
|
Sem_.release 1 self.sem_max_connections;
|
||||||
raise e);
|
raise e);
|
||||||
ignore Unix.(sigprocmask SIG_UNBLOCK Sys.[ sigint; sighup ])
|
ignore Unix.(sigprocmask SIG_UNBLOCK Sys.[ sigint; sighup ])
|
||||||
with e ->
|
| exception Unix.Unix_error ((Unix.EAGAIN | Unix.EWOULDBLOCK), _, _)
|
||||||
Sem_.release 1 self.sem_max_connections;
|
->
|
||||||
|
()
|
||||||
|
| exception e ->
|
||||||
_debug (fun k ->
|
_debug (fun k ->
|
||||||
k "Unix.accept or Thread.create raised an exception: %s"
|
k "Unix.accept or Thread.create raised an exception: %s"
|
||||||
(Printexc.to_string e))
|
(Printexc.to_string e))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue