Skip to content

Commit

Permalink
cohttp-eio: Add wired data debug logs like cohttp-lwt-unix.
Browse files Browse the repository at this point in the history
  • Loading branch information
mefyl committed Jan 23, 2024
1 parent 5da40ec commit b1875e7
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions cohttp-eio/src/io.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
let src = Logs.Src.create "cohttp.eio.io" ~doc:"Cohttp Eio IO module"

module Logs = (val Logs.src_log src : Logs.LOG)

module IO = struct
type 'a t = 'a

Expand All @@ -22,16 +26,30 @@ module IO = struct
let () = Eio.Buf_read.consume ic consumed in
res

let read_line ic = try Some (Eio.Buf_read.line ic) with End_of_file -> None
let read_line ic =
try
let line = Eio.Buf_read.line ic in
let () = Logs.debug (fun f -> f "<<< %s" line) in
Some line
with End_of_file ->
let () = Logs.debug (fun f -> f "<<< EOF") in
None

let read ic len =
match Eio.Buf_read.ensure ic 1 with
| exception End_of_file -> ""
| exception End_of_file ->
let () = Logs.debug (fun f -> f "<<< EOF") in
""
| () ->
let len = Int.min len (Eio.Buf_read.buffered_bytes ic) in
Eio.Buf_read.take len ic
let read = Eio.Buf_read.take len ic in
let () = Logs.debug (fun f -> f "<<< %s" read) in
read

let write oc string =
let () = Logs.debug (fun f -> f ">>> %s" (String.trim string)) in
Eio.Buf_write.string oc string

let write oc string = Eio.Buf_write.string oc string
let flush = Eio.Buf_write.flush
end

Expand Down

0 comments on commit b1875e7

Please sign in to comment.