mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 11:15:35 -05:00
refactor: pass explicit buf_pool; add create_buf_pool
This commit is contained in:
parent
0c6966e171
commit
8e791421a6
2 changed files with 23 additions and 5 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
type buf = Tiny_httpd_buf.t
|
type buf = Tiny_httpd_buf.t
|
||||||
type byte_stream = Tiny_httpd_stream.t
|
type byte_stream = Tiny_httpd_stream.t
|
||||||
|
type buf_pool = buf Tiny_httpd_pool.t
|
||||||
|
|
||||||
module Buf = Tiny_httpd_buf
|
module Buf = Tiny_httpd_buf
|
||||||
module Byte_stream = Tiny_httpd_stream
|
module Byte_stream = Tiny_httpd_stream
|
||||||
|
|
@ -871,7 +872,20 @@ let get_max_connection_ ?(max_connections = 64) () : int =
|
||||||
let max_connections = max 4 max_connections in
|
let max_connections = max 4 max_connections in
|
||||||
max_connections
|
max_connections
|
||||||
|
|
||||||
let create_from ?(buf_size = 16 * 1_024) ?(middlewares = []) ~backend () : t =
|
let _default_buf_size = 16 * 1024
|
||||||
|
|
||||||
|
let create_buf_pool ?(buf_size = _default_buf_size) () : buf_pool =
|
||||||
|
Pool.create ~clear:Buf.clear_and_zero
|
||||||
|
~mk_item:(fun () -> Buf.create ~size:buf_size ())
|
||||||
|
()
|
||||||
|
|
||||||
|
let create_from ?(buf_size = _default_buf_size) ?buf_pool ?(middlewares = [])
|
||||||
|
~backend () : t =
|
||||||
|
let buf_pool =
|
||||||
|
match buf_pool with
|
||||||
|
| Some p -> p
|
||||||
|
| None -> create_buf_pool ~buf_size ()
|
||||||
|
in
|
||||||
let handler _req = Response.fail ~code:404 "no top handler" in
|
let handler _req = Response.fail ~code:404 "no top handler" in
|
||||||
let self =
|
let self =
|
||||||
{
|
{
|
||||||
|
|
@ -882,10 +896,7 @@ let create_from ?(buf_size = 16 * 1_024) ?(middlewares = []) ~backend () : t =
|
||||||
path_handlers = [];
|
path_handlers = [];
|
||||||
middlewares = [];
|
middlewares = [];
|
||||||
middlewares_sorted = lazy [];
|
middlewares_sorted = lazy [];
|
||||||
buf_pool =
|
buf_pool;
|
||||||
Pool.create ~clear:Buf.clear_and_zero
|
|
||||||
~mk_item:(fun () -> Buf.create ~size:buf_size ())
|
|
||||||
();
|
|
||||||
}
|
}
|
||||||
in
|
in
|
||||||
List.iter (fun (stage, m) -> add_middleware self ~stage m) middlewares;
|
List.iter (fun (stage, m) -> add_middleware self ~stage m) middlewares;
|
||||||
|
|
@ -1223,6 +1234,7 @@ let client_handle_for (self : t) ~client_addr ic oc : unit =
|
||||||
try
|
try
|
||||||
if Headers.get "connection" r.Response.headers = Some "close" then
|
if Headers.get "connection" r.Response.headers = Some "close" then
|
||||||
continue := false;
|
continue := false;
|
||||||
|
Log.debug (fun k -> k "got response: %a" Response.pp r);
|
||||||
log_response req r;
|
log_response req r;
|
||||||
Response.output_ ~buf:buf_res oc r
|
Response.output_ ~buf:buf_res oc r
|
||||||
with Sys_error _ -> continue := false
|
with Sys_error _ -> continue := false
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
type buf = Tiny_httpd_buf.t
|
type buf = Tiny_httpd_buf.t
|
||||||
type byte_stream = Tiny_httpd_stream.t
|
type byte_stream = Tiny_httpd_stream.t
|
||||||
|
type buf_pool = buf Tiny_httpd_pool.t
|
||||||
|
|
||||||
(** {2 HTTP Methods} *)
|
(** {2 HTTP Methods} *)
|
||||||
|
|
||||||
|
|
@ -469,8 +470,13 @@ module type IO_BACKEND = sig
|
||||||
on a port and handle clients. *)
|
on a port and handle clients. *)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
val create_buf_pool : ?buf_size:int -> unit -> buf_pool
|
||||||
|
(** [create_buf_pool ()] creates a new buffer pool.
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val create_from :
|
val create_from :
|
||||||
?buf_size:int ->
|
?buf_size:int ->
|
||||||
|
?buf_pool:buf_pool ->
|
||||||
?middlewares:([ `Encoding | `Stage of int ] * Middleware.t) list ->
|
?middlewares:([ `Encoding | `Stage of int ] * Middleware.t) list ->
|
||||||
backend:(module IO_BACKEND) ->
|
backend:(module IO_BACKEND) ->
|
||||||
unit ->
|
unit ->
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue