From 8414efc3e034b840c9ff9feef8848a9f22a333ab Mon Sep 17 00:00:00 2001 From: Yawar Amin Date: Sat, 25 Sep 2021 02:03:28 -0400 Subject: [PATCH] Adjust implementation Only do things that are relevant for binding a socket if we actually should. --- src/Tiny_httpd.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tiny_httpd.ml b/src/Tiny_httpd.ml index 408f4c8c..a7aebbf0 100644 --- a/src/Tiny_httpd.ml +++ b/src/Tiny_httpd.ml @@ -1078,10 +1078,10 @@ let run (self:t) : (unit,_) result = true (* Because we're creating the socket ourselves *) in Unix.clear_nonblock sock; - Unix.setsockopt sock Unix.SO_REUSEADDR true; Unix.setsockopt_optint sock Unix.SO_LINGER None; - let inet_addr = Unix.inet_addr_of_string self.addr in begin if should_bind then + let inet_addr = Unix.inet_addr_of_string self.addr in + Unix.setsockopt sock Unix.SO_REUSEADDR true; Unix.bind sock (Unix.ADDR_INET (inet_addr, self.port)); Unix.listen sock (2 * self.sem_max_connections.Sem_.n) end;