@@ -351,22 +351,6 @@ module Request = struct
351351 end
352352end
353353
354- (* $R
355- let q = "GET hello HTTP/1.1\r\nHost: coucou\r\nContent-Length: 11\r\n\r\nsalutationsSOMEJUNK" in
356- let str = Tiny_httpd.Byte_stream.of_string q in
357- let r = Request.Internal_.parse_req_start ~get_time_s:(fun _ -> 0.) str in
358- match r with
359- | None -> assert_failure "should parse"
360- | Some req ->
361- assert_equal (Some "coucou") (Headers.get "Host" req.Request.headers);
362- assert_equal (Some "coucou") (Headers.get "host" req.Request.headers);
363- assert_equal (Some "11") (Headers.get "content-length" req.Request.headers);
364- assert_equal "hello" req.Request.path;
365- let req = Request.Internal_.parse_body req str |> Request.read_body_full in
366- assert_equal ~printer:(fun s->s) "salutations" req.Request.body;
367- ()
368- *)
369-
370354module Response = struct
371355 type body =
372356 [ `String of string
@@ -958,20 +942,28 @@ module Unix_tcp_server_ = struct
958942 try
959943 let client_sock, client_addr = Unix. accept sock in
960944 Unix. setsockopt client_sock Unix. TCP_NODELAY true ;
945+ (* Block INT/HUP while cloning to avoid children handling them.
946+ When thread gets them, our Unix.accept raises neatly. *)
947+ ignore Unix. (sigprocmask SIG_BLOCK Sys. [ sigint; sighup ]);
961948 self.new_thread (fun () ->
962949 try
963950 handle_client_unix_ client_sock client_addr;
964951 Sem_. release 1 self.sem_max_connections
965952 with e ->
966953 (try Unix. close client_sock with _ -> () );
967954 Sem_. release 1 self.sem_max_connections;
968- raise e)
955+ raise e);
956+ ignore Unix. (sigprocmask SIG_UNBLOCK Sys. [ sigint; sighup ])
969957 with e ->
970958 Sem_. release 1 self.sem_max_connections;
971959 _debug (fun k ->
972960 k " Unix.accept or Thread.create raised an exception: %s"
973961 (Printexc. to_string e))
974962 done ;
963+
964+ (* Wait for all threads to be done: this only works if all threads are done. *)
965+ Unix. close sock;
966+ Sem_. acquire self.sem_max_connections.max self.sem_max_connections;
975967 () );
976968 }
977969end
0 commit comments