mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 11:15:35 -05:00
Unix.accept may raise an exception (typicall Unix.EINTR, even with sigpipe blocked ?)
This avoids the server to stop
This commit is contained in:
parent
a58372b9a7
commit
6ccd8314a3
1 changed files with 15 additions and 11 deletions
|
|
@ -1088,17 +1088,21 @@ let run (self:t) : (unit,_) result =
|
||||||
while self.running do
|
while self.running do
|
||||||
(* limit concurrency *)
|
(* limit concurrency *)
|
||||||
Sem_.acquire 1 self.sem_max_connections;
|
Sem_.acquire 1 self.sem_max_connections;
|
||||||
let client_sock, _ = Unix.accept sock in
|
try
|
||||||
self.new_thread
|
let client_sock, _ = Unix.accept sock in
|
||||||
(fun () ->
|
self.new_thread
|
||||||
try
|
(fun () ->
|
||||||
handle_client_ self client_sock;
|
try
|
||||||
Sem_.release 1 self.sem_max_connections;
|
handle_client_ self client_sock;
|
||||||
with e ->
|
Sem_.release 1 self.sem_max_connections;
|
||||||
(try Unix.close client_sock with _ -> ());
|
with e ->
|
||||||
Sem_.release 1 self.sem_max_connections;
|
(try Unix.close client_sock with _ -> ());
|
||||||
raise e
|
Sem_.release 1 self.sem_max_connections;
|
||||||
);
|
raise e
|
||||||
|
);
|
||||||
|
with e ->
|
||||||
|
Printf.eprintf "accept raised an exception: %s"
|
||||||
|
(Printexc.to_string e)
|
||||||
done;
|
done;
|
||||||
Ok ()
|
Ok ()
|
||||||
with e -> Error e
|
with e -> Error e
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue