From 029c558802de530114cd1a15c45e0825b1566d33 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 2 Jul 2025 23:11:37 -0400 Subject: [PATCH] tiny_httpd_lwt: fix bug in ic refill; revert to `bytes` --- src/lwt/tiny_httpd_lwt.ml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/lwt/tiny_httpd_lwt.ml b/src/lwt/tiny_httpd_lwt.ml index a5dbe7b7..e78926ed 100644 --- a/src/lwt/tiny_httpd_lwt.ml +++ b/src/lwt/tiny_httpd_lwt.ml @@ -21,7 +21,7 @@ let get_max_connection_ ?(max_connections = 64) () : int = let max_connections = max 4 max_connections in max_connections -let default_buf_size = 4 * 1024 +let default_buf_size = 16 * 1024 let show_sockaddr = function | Unix.ADDR_UNIX s -> s @@ -30,16 +30,15 @@ let show_sockaddr = function let ic_of_fd ~(num_open : int ref) ~bytes (fd : Lwt_unix.file_descr) : IO.Input.t = - let lwt_bytes = Lwt_bytes.create (Bytes.length bytes) in object inherit Iostream.In_buf.t_from_refill ~bytes () method private refill (sl : Slice.t) = assert (sl.len = 0); + sl.off <- 0; let n = - Lwt_bytes.read fd lwt_bytes 0 (Lwt_bytes.length lwt_bytes) |> Task.await + Lwt_unix.read fd sl.bytes 0 (Bytes.length sl.bytes) |> Task.await in - Lwt_bytes.blit_to_bytes lwt_bytes 0 bytes 0 n; sl.len <- n method close () = @@ -49,17 +48,15 @@ let ic_of_fd ~(num_open : int ref) ~bytes (fd : Lwt_unix.file_descr) : let oc_of_fd ~(num_open : int ref) ~bytes (fd : Lwt_unix.file_descr) : IO.Output.t = - let lwt_bytes = Lwt_bytes.create (Bytes.length bytes) in object inherit IO.Output.t_from_output ~bytes () (* method flush () : unit = Lwt_io.flush oc |> Task.await *) method private output_underlying buf i len = - Lwt_bytes.blit_from_bytes buf i lwt_bytes 0 len; - let i = ref 0 in + let i = ref i in let len = ref len in while !len > 0 do - let n = Lwt_bytes.write fd lwt_bytes !i !len |> Task.await in + let n = Lwt_unix.write fd buf !i !len |> Task.await in i := !i + n; len := !len - n done