Skip to content

Commit

Permalink
perf: only call select in accept loop if accept would have blocked
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Feb 17, 2024
1 parent 217defe commit 20a3691
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Tiny_httpd_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,6 @@ module Unix_tcp_server_ = struct
Unix.set_nonblock sock;
while self.running do
ignore (Unix.select [ sock ] [] [ sock ] 1.0 : _ * _ * _);
match Unix.accept sock with
| client_sock, client_addr ->
(* limit concurrency *)
Expand Down Expand Up @@ -1012,7 +1011,8 @@ module Unix_tcp_server_ = struct
ignore Unix.(sigprocmask SIG_UNBLOCK Sys.[ sigint; sighup ])
| exception Unix.Unix_error ((Unix.EAGAIN | Unix.EWOULDBLOCK), _, _)
->
()
(* wait for the socket to be ready, and re-enter the loop *)
ignore (Unix.select [ sock ] [] [ sock ] 1.0 : _ * _ * _)
| exception e ->
Log.error (fun k ->
k "Unix.accept or Thread.create raised an exception: %s"
Expand Down

0 comments on commit 20a3691

Please sign in to comment.