Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use iostream with timeouts #84

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
base-threads
result
hmap
base-unix
(iostream (>= 0.2))
(ocaml (>= 4.08))
(odoc :with-doc)
Expand Down
2 changes: 1 addition & 1 deletion examples/echo_ws.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let handle_ws _client_addr ic oc =
let buf = Bytes.create 32 in
let continue = ref true in
while !continue do
let n = IO.Input.input ic buf 0 (Bytes.length buf) in
let n = IO.Input_with_timeout.input ic buf 0 (Bytes.length buf) in
Log.debug (fun k ->
k "echo %d bytes from websocket: %S" n (Bytes.sub_string buf 0 n));

Expand Down
1 change: 1 addition & 0 deletions src/Tiny_httpd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Meth = Tiny_httpd_core.Meth
module Pool = Tiny_httpd_core.Pool
module Log = Tiny_httpd_core.Log
module Server = Tiny_httpd_core.Server
module Time = Time
module Util = Tiny_httpd_core.Util
include Server
module Dir = Tiny_httpd_unix.Dir
Expand Down
4 changes: 4 additions & 0 deletions src/Tiny_httpd.mli
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ module Buf = Buf

module IO = Tiny_httpd_core.IO

(** {2 Time} *)

module Time = Time

(** {2 Logging *)

module Log = Tiny_httpd_core.Log
Expand Down
9 changes: 5 additions & 4 deletions src/camlzip/Tiny_httpd_camlzip.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module W = IO.Writer

let decode_deflate_stream_ ~buf_size (ic : IO.Input.t) : IO.Input.t =
let decode_deflate_stream_ ~buf_size (ic : #IO.Input_with_timeout.t) :
IO.Input_with_timeout.t =
Log.debug (fun k -> k "wrap stream with deflate.decode");
Iostream_camlzip.decompress_in_buf ~buf_size ic
Iostream_camlzip.decompress_in_buf_with_timeout ~now_s:Time.now_s ~buf_size ic

let encode_deflate_writer_ ~buf_size (w : W.t) : W.t =
Log.debug (fun k -> k "wrap writer with deflate.encode");
Expand All @@ -27,8 +28,8 @@ let has_deflate s =
try Scanf.sscanf s "deflate, %s" (fun _ -> true) with _ -> false

(* decompress [req]'s body if needed *)
let decompress_req_stream_ ~buf_size (req : IO.Input.t Request.t) : _ Request.t
=
let decompress_req_stream_ ~buf_size (req : #IO.Input_with_timeout.t Request.t)
: _ Request.t =
match Request.get_header ~f:String.trim req "Transfer-Encoding" with
(* TODO
| Some "gzip" ->
Expand Down
Loading
Loading