diff --git a/CHANGES.md b/CHANGES.md index bde9a5a..2f67007 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,6 @@ +## Pending + +- fix: No setting of sigprocmask on Windows ## 0.16 diff --git a/src/Tiny_httpd.ml b/src/Tiny_httpd.ml index cbffe69..6d8cd7c 100644 --- a/src/Tiny_httpd.ml +++ b/src/Tiny_httpd.ml @@ -27,7 +27,7 @@ open struct slice.len <- 0 end -let create ?(masksigpipe = true) ?max_connections ?(timeout = 0.0) ?buf_size +let create ?(masksigpipe = not (Sys.win32)) ?max_connections ?(timeout = 0.0) ?buf_size ?(get_time_s = Unix.gettimeofday) ?(new_thread = fun f -> ignore (Thread.create f () : Thread.t)) ?(addr = "127.0.0.1") ?(port = 8080) ?sock ?middlewares () : t = diff --git a/src/Tiny_httpd.mli b/src/Tiny_httpd.mli index 2490646..fbd30be 100644 --- a/src/Tiny_httpd.mli +++ b/src/Tiny_httpd.mli @@ -144,7 +144,8 @@ val create : {!set_top_handler} to specify how to handle incoming requests. @param masksigpipe if true, block the signal {!Sys.sigpipe} which otherwise - tends to kill client threads when they try to write on broken sockets. Default: [true]. + tends to kill client threads when they try to write on broken sockets. + Default: [true] except when on Windows, which defaults to [false]. @param buf_size size for buffers (since 0.11) diff --git a/src/unix/tiny_httpd_unix.ml b/src/unix/tiny_httpd_unix.ml index f1de393..d3e01ef 100644 --- a/src/unix/tiny_httpd_unix.ml +++ b/src/unix/tiny_httpd_unix.ml @@ -31,7 +31,7 @@ module Unix_tcp_server_ = struct { IO.TCP_server.serve = (fun ~after_init ~handle () : unit -> - if self.masksigpipe then + if self.masksigpipe && not (Sys.win32) then ignore (Unix.sigprocmask Unix.SIG_BLOCK [ Sys.sigpipe ] : _ list); let sock, should_bind = match self.sock with @@ -83,7 +83,7 @@ module Unix_tcp_server_ = struct (Thread.id @@ Thread.self ()) (Util.show_sockaddr client_addr)); - if self.masksigpipe then + if self.masksigpipe && not (Sys.win32) then ignore (Unix.sigprocmask Unix.SIG_BLOCK [ Sys.sigpipe ] : _ list); Unix.set_nonblock client_sock; Unix.setsockopt client_sock Unix.TCP_NODELAY true; @@ -113,7 +113,8 @@ module Unix_tcp_server_ = struct Sem.acquire 1 self.sem_max_connections; (* Block INT/HUP while cloning to avoid children handling them. When thread gets them, our Unix.accept raises neatly. *) - ignore Unix.(sigprocmask SIG_BLOCK Sys.[ sigint; sighup ]); + if not (Sys.win32) then + ignore Unix.(sigprocmask SIG_BLOCK Sys.[ sigint; sighup ]); self.new_thread (fun () -> try handle_client_unix_ client_sock client_addr; @@ -136,7 +137,8 @@ module Unix_tcp_server_ = struct (Util.show_sockaddr client_addr) (Printexc.to_string e) (Printexc.raw_backtrace_to_string bt))); - ignore Unix.(sigprocmask SIG_UNBLOCK Sys.[ sigint; sighup ]) + if not (Sys.win32) then + 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 *)