Skip to content

Commit

Permalink
Make read buffer size configurable again
Browse files Browse the repository at this point in the history
This refs #18 in that users can now set the buffer size they want. It
also gets rid of a pending `TODO` in the code.
  • Loading branch information
anmonteiro committed Dec 15, 2018
1 parent ea1b913 commit 23773ea
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
9 changes: 5 additions & 4 deletions async/httpaf_async.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,17 @@ let read fd buffer =
open Httpaf

module Server = struct
let create_connection_handler ?config ~request_handler ~error_handler =
module Config = Server_connection.Config

let create_connection_handler ?(config=Config.default) ~request_handler ~error_handler =
fun client_addr socket ->
let fd = Socket.fd socket in
let writev = Faraday_async.writev_of_fd fd in
let request_handler = request_handler client_addr in
let error_handler = error_handler client_addr in
let conn = Server_connection.create ?config ~error_handler request_handler in
let conn = Server_connection.create ~config ~error_handler request_handler in
let read_complete = Ivar.create () in
(* XXX(seliopou): Make this configurable *)
let buffer = Buffer.create 0x1000 in
let buffer = Buffer.create config.read_buffer_size in
let rec reader_thread () =
match Server_connection.next_read_operation conn with
| `Read ->
Expand Down
3 changes: 2 additions & 1 deletion lib/httpaf.mli
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,8 @@ end
module Server_connection : sig
module Config : sig
type t =
{ response_buffer_size : int (** Default is [1024] *)
{ read_buffer_size : int (** Default is [4096] *)
; response_buffer_size : int (** Default is [1024] *)
; response_body_buffer_size : int (** Default is [4096] *)
}

Expand Down
8 changes: 5 additions & 3 deletions lib/server_connection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ module Writer = Serialize.Writer

module Config = struct
type t =
{ response_buffer_size : int
{ read_buffer_size : int
; response_buffer_size : int
; response_body_buffer_size : int }

let default =
{ response_buffer_size = 0x400
{ read_buffer_size = 0x1000
; response_buffer_size = 0x400
; response_body_buffer_size = 0x1000 }
end

Expand Down Expand Up @@ -128,7 +130,7 @@ let create ?(config=Config.default) ?(error_handler=default_error_handler) reque
{ Config
. response_buffer_size
; response_body_buffer_size
} = config
; _ } = config
in
let writer = Writer.create ~buffer_size:response_buffer_size () in
let request_queue = Queue.create () in
Expand Down
9 changes: 4 additions & 5 deletions lwt/httpaf_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,19 @@ module Server = struct
type request_handler =
Lwt_unix.file_descr Httpaf.Server_connection.request_handler

module Config = Httpaf.Server_connection.Config


let create_connection_handler ?config ~request_handler ~error_handler =
let create_connection_handler ?(config=Config.default) ~request_handler ~error_handler =
fun client_addr socket ->
let module Server_connection = Httpaf.Server_connection in
let connection =
Server_connection.create
?config
~config
~error_handler:(error_handler client_addr)
(request_handler client_addr)
in


let read_buffer = Buffer.create 0x1000 in
let read_buffer = Buffer.create config.read_buffer_size in
let read_loop_exited, notify_read_loop_exited = Lwt.wait () in

let rec read_loop () =
Expand Down

0 comments on commit 23773ea

Please sign in to comment.