From 47d9ace8fd50e053b1076ba0489cc0ed14190940 Mon Sep 17 00:00:00 2001 From: craff Date: Sat, 11 Dec 2021 20:29:58 -1000 Subject: [PATCH] add stdlibshims + catch EBADF --- src/Tiny_httpd.ml | 6 +++++- src/dune | 2 +- tiny_httpd.opam | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Tiny_httpd.ml b/src/Tiny_httpd.ml index 3406deab..53891e53 100644 --- a/src/Tiny_httpd.ml +++ b/src/Tiny_httpd.ml @@ -39,8 +39,12 @@ let rec write_out ({buf;fd;_} as oc) i len = with Sys_blocked_io | Unix.Unix_error((EAGAIN|EWOULDBLOCK),_,_) -> write_out oc i len - | Unix.Unix_error(EPIPE,_,_) -> + | Unix.Unix_error((EPIPE|EBADF),_,_) -> raise (Sys_error "broken pipe") + | e -> + Printf.eprintf "unexpected exception in write_out: %s\n%!" + (Printexc.to_string e); + assert false let rec output ({buf;pos;_} as oc) s i len = let buf_len = Bytes.length buf in diff --git a/src/dune b/src/dune index 29a2fb12..26789fb1 100644 --- a/src/dune +++ b/src/dune @@ -2,6 +2,6 @@ (library (name tiny_httpd) (public_name tiny_httpd) - (libraries threads) + (libraries threads stdlib-shims) (flags :standard -safe-string -warn-error -a+8) (wrapped false)) diff --git a/tiny_httpd.opam b/tiny_httpd.opam index 8a0df3ff..f551c67f 100644 --- a/tiny_httpd.opam +++ b/tiny_httpd.opam @@ -11,6 +11,7 @@ build: [ ] depends: [ "dune" { >= "2.0" } + "stdlib-shims" "base-threads" "ocaml" { >= "4.04.0" } "odoc" {with-doc}