@@ -3,7 +3,7 @@ module H = Tiny_httpd.Server
33module Pool = Tiny_httpd. Pool
44module Slice = IO. Slice
55module Log = Tiny_httpd. Log
6- module Task = Task
6+ module Lwt_direct = Lwt_direct
77
88let spf = Printf. sprintf
99let ( let @ ) = ( @@ )
@@ -37,33 +37,33 @@ let ic_of_fd ~(num_open : int ref) ~bytes (fd : Lwt_unix.file_descr) :
3737 assert (sl.len = 0 );
3838 sl.off < - 0 ;
3939 let n =
40- Lwt_unix. read fd sl.bytes 0 (Bytes. length sl.bytes) |> Task . await
40+ Lwt_unix. read fd sl.bytes 0 (Bytes. length sl.bytes) |> Lwt_direct . await
4141 in
4242 sl.len < - n
4343
4444 method close () =
4545 decr num_open;
46- if ! num_open < = 0 then Lwt_unix. close fd |> Task . await
46+ if ! num_open < = 0 then Lwt_unix. close fd |> Lwt_direct . await
4747 end
4848
4949let oc_of_fd ~(num_open : int ref ) ~bytes (fd : Lwt_unix.file_descr ) :
5050 IO.Output. t =
5151 object
5252 inherit IO.Output. t_from_output ~bytes ()
53- (* method flush () : unit = Lwt_io.flush oc |> Task .await *)
53+ (* method flush () : unit = Lwt_io.flush oc |> Lwt_direct .await *)
5454
5555 method private output_underlying buf i len =
5656 let i = ref i in
5757 let len = ref len in
5858 while ! len > 0 do
59- let n = Lwt_unix. write fd buf ! i ! len |> Task . await in
59+ let n = Lwt_unix. write fd buf ! i ! len |> Lwt_direct . await in
6060 i := ! i + n;
6161 len := ! len - n
6262 done
6363
6464 method private close_underlying () =
6565 decr num_open;
66- if ! num_open < = 0 then Lwt_unix. close fd |> Task . await
66+ if ! num_open < = 0 then Lwt_unix. close fd |> Lwt_direct . await
6767 end
6868
6969let io_backend ?addr ?port ?unix_sock ?max_connections ?max_buf_pool_size
@@ -80,7 +80,7 @@ let io_backend ?addr ?port ?unix_sock ?max_connections ?max_buf_pool_size
8080 | addr , port , None ->
8181 let addr = Option. value ~default: " 127.0.0.1" addr in
8282 let sockaddr, port =
83- match Lwt_unix. getaddrinfo addr " " [] |> Task . await, port with
83+ match Lwt_unix. getaddrinfo addr " " [] |> Lwt_direct . await, port with
8484 | { Unix. ai_addr = ADDR_INET (h , _ ); _ } :: _ , None ->
8585 let p = 8080 in
8686 Unix. ADDR_INET (h, p), p
@@ -115,7 +115,7 @@ let io_backend ?addr ?port ?unix_sock ?max_connections ?max_buf_pool_size
115115 let port = ref port in
116116
117117 let server_loop : unit Lwt.t =
118- let @ () = Task . run in
118+ let @ () = Lwt_direct . run in
119119 let backlog = max_connections in
120120 let sock =
121121 Lwt_unix. socket ~cloexec: true
@@ -126,7 +126,7 @@ let io_backend ?addr ?port ?unix_sock ?max_connections ?max_buf_pool_size
126126 Lwt_unix. setsockopt_optint sock Unix. SO_LINGER None ;
127127 Lwt_unix. setsockopt sock Unix. SO_REUSEADDR true ;
128128 Lwt_unix. setsockopt sock Unix. SO_REUSEPORT true ;
129- Lwt_unix. bind sock sockaddr |> Task . await;
129+ Lwt_unix. bind sock sockaddr |> Lwt_direct . await;
130130 Lwt_unix. listen sock backlog;
131131
132132 (* recover real port, if any *)
@@ -136,8 +136,7 @@ let io_backend ?addr ?port ?unix_sock ?max_connections ?max_buf_pool_size
136136
137137 let handle_client client_addr fd : unit =
138138 Atomic. incr active_conns;
139- let @ () = Task. run_async in
140-
139+ Lwt_direct. run_in_the_background @@ fun () ->
141140 let cleanup () =
142141 Log. debug (fun k ->
143142 k " Tiny_httpd_lwt: client handler returned" );
@@ -169,7 +168,7 @@ let io_backend ?addr ?port ?unix_sock ?max_connections ?max_buf_pool_size
169168 in
170169
171170 while Atomic. get running do
172- let fd, addr = Lwt_unix. accept sock |> Task . await in
171+ let fd, addr = Lwt_unix. accept sock |> Lwt_direct . await in
173172 handle_client addr fd
174173 done
175174 in
@@ -181,21 +180,21 @@ let io_backend ?addr ?port ?unix_sock ?max_connections ?max_buf_pool_size
181180 (fun () ->
182181 Atomic. set running false ;
183182 Lwt. wakeup_later set_server_done () ;
184- Task . await server_loop);
183+ Lwt_direct . await server_loop);
185184 endpoint = (fun () -> addr, ! port);
186185 active_connections = (fun () -> Atomic. get active_conns);
187186 }
188187 in
189188
190189 after_init tcp_server;
191- Task . await server_done);
190+ Lwt_direct . await server_done);
192191 }
193192 end in
194193 (module M )
195194
196195let create ?addr ?port ?unix_sock ?max_connections ?max_buf_pool_size ?buf_size
197196 ?middlewares () : H.t Lwt.t =
198- let @ () = Task . run in
197+ let @ () = Lwt_direct . run in
199198 let backend =
200199 io_backend ?addr ?port ?unix_sock ?max_buf_pool_size ?max_connections
201200 ?buf_size ()
0 commit comments