Skip to content

Commit

Permalink
Merge pull request #22 from craff/master
Browse files Browse the repository at this point in the history
Unix.accept may raise an exception
  • Loading branch information
c-cube authored Nov 30, 2021
2 parents a58372b + a65734e commit ac05b9e
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/Tiny_httpd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1088,17 +1088,22 @@ let run (self:t) : (unit,_) result =
while self.running do
(* limit concurrency *)
Sem_.acquire 1 self.sem_max_connections;
let client_sock, _ = Unix.accept sock in
self.new_thread
(fun () ->
try
handle_client_ self client_sock;
Sem_.release 1 self.sem_max_connections;
with e ->
(try Unix.close client_sock with _ -> ());
Sem_.release 1 self.sem_max_connections;
raise e
);
try
let client_sock, _ = Unix.accept sock in
self.new_thread
(fun () ->
try
handle_client_ self client_sock;
Sem_.release 1 self.sem_max_connections;
with e ->
(try Unix.close client_sock with _ -> ());
Sem_.release 1 self.sem_max_connections;
raise e
);
with e ->
_debug (fun k -> k
"Unix.accept or Thread.create raised an exception: %s"
(Printexc.to_string e))
done;
Ok ()
with e -> Error e

0 comments on commit ac05b9e

Please sign in to comment.