This commit is contained in:
Simon Cruanes 2026-02-15 16:13:24 -05:00
parent 32421a26bc
commit ffdcc1139c
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 17 additions and 10 deletions

View file

@ -56,10 +56,12 @@ let ic_of_flow ~closed ~buf_pool:ic_pool (flow : _ Eio.Net.stream_socket) :
method close () = method close () =
if not !closed then ( if not !closed then (
closed := true; closed := true;
Pool.Raw.release ic_pool cstruct); Pool.Raw.release ic_pool cstruct
);
if not !sent_shutdown then ( if not !sent_shutdown then (
sent_shutdown := true; sent_shutdown := true;
Eio.Flow.shutdown flow `Receive) Eio.Flow.shutdown flow `Receive
)
end end
let oc_of_flow ~closed ~buf_pool:oc_pool (flow : _ Eio.Net.stream_socket) : let oc_of_flow ~closed ~buf_pool:oc_pool (flow : _ Eio.Net.stream_socket) :
@ -100,10 +102,12 @@ let oc_of_flow ~closed ~buf_pool:oc_pool (flow : _ Eio.Net.stream_socket) :
method close () = method close () =
if not !closed then ( if not !closed then (
closed := true; closed := true;
Pool.Raw.release oc_pool wbuf); Pool.Raw.release oc_pool wbuf
);
if not !sent_shutdown then ( if not !sent_shutdown then (
sent_shutdown := true; sent_shutdown := true;
Eio.Flow.shutdown flow `Send) Eio.Flow.shutdown flow `Send
)
end end
let io_backend ?addr ?port ?unix_sock ?max_connections ?max_buf_pool_size let io_backend ?addr ?port ?unix_sock ?max_connections ?max_buf_pool_size
@ -189,9 +193,8 @@ let io_backend ?addr ?port ?unix_sock ?max_connections ?max_buf_pool_size
sock sock
(fun flow client_addr -> (fun flow client_addr ->
Eio.Semaphore.acquire sem; Eio.Semaphore.acquire sem;
Eio_unix.Fd.use_exn "setsockopt" Eio_unix.Fd.use_exn "setsockopt" (Eio_unix.Net.fd flow)
(Eio_unix.Net.fd flow) (fun fd -> (fun fd -> Unix.setsockopt fd Unix.TCP_NODELAY true);
Unix.setsockopt fd Unix.TCP_NODELAY true);
Atomic.incr active_conns; Atomic.incr active_conns;
let@ () = let@ () =
Fun.protect ~finally:(fun () -> Fun.protect ~finally:(fun () ->
@ -202,8 +205,12 @@ let io_backend ?addr ?port ?unix_sock ?max_connections ?max_buf_pool_size
in in
let ic_closed = ref false in let ic_closed = ref false in
let oc_closed = ref false in let oc_closed = ref false in
let ic = ic_of_flow ~closed:ic_closed ~buf_pool:cstruct_pool flow in let ic =
let oc = oc_of_flow ~closed:oc_closed ~buf_pool:cstruct_pool flow in ic_of_flow ~closed:ic_closed ~buf_pool:cstruct_pool flow
in
let oc =
oc_of_flow ~closed:oc_closed ~buf_pool:cstruct_pool flow
in
Log.debug (fun k -> Log.debug (fun k ->
k "handling client on %a…" Eio.Net.Sockaddr.pp client_addr); k "handling client on %a…" Eio.Net.Sockaddr.pp client_addr);

View file

@ -51,7 +51,7 @@
(public_name tiny_httpd.ws) (public_name tiny_httpd.ws)
(synopsis "Websockets for tiny_httpd") (synopsis "Websockets for tiny_httpd")
(private_modules common_ws_ utils_) (private_modules common_ws_ utils_)
(flags :standard -w -32 -open Tiny_httpd_core) (flags :standard -w -32 -open Tiny_httpd_core)
(foreign_stubs (foreign_stubs
(language c) (language c)
(names tiny_httpd_ws_stubs) (names tiny_httpd_ws_stubs)