Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Leonard <[email protected]>
  • Loading branch information
mefyl and talex5 authored Jun 19, 2023
1 parent db930c6 commit 4b32c1c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
3 changes: 1 addition & 2 deletions cohttp-eio/examples/client1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ let () =
Client.get ~sw env#net (Uri.of_string "http://example.com")
in
if Http.Status.compare resp.status `OK = 0 then
Fmt.string Format.std_formatter
@@ Eio.Buf_read.(take_all @@ of_flow ~max_size:max_int body)
print_string @@ Eio.Buf_read.(parse_exn take_all) body ~max_size:max_int
else Fmt.epr "Unexpected HTTP status: %a" Http.Status.pp resp.status
2 changes: 1 addition & 1 deletion cohttp-eio/examples/server1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let () =
Eio_main.run @@ fun env ->
Eio.Switch.run @@ fun sw ->
let socket =
Eio.Net.listen env#net ~sw ~backlog:128 ~reuse_addr:true ~reuse_port:true
Eio.Net.listen env#net ~sw ~backlog:128 ~reuse_addr:true
(`Tcp (Eio.Net.Ipaddr.V4.loopback, !port))
and server = Cohttp_eio.Server.make ~callback:handler () in
Cohttp_eio.Server.run socket server
12 changes: 5 additions & 7 deletions cohttp-eio/src/io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ module IO = struct
Some line

let rec read ic len =
let contents = Eio.Buf_read.peek ic in
if Cstruct.length contents = 0 then
match refill ic with `Eof -> "" | `Ok -> read ic len
else
let consumed = Int.min len (Cstruct.length contents) in
let () = Eio.Buf_read.consume ic consumed in
Cstruct.to_string ~len:consumed contents
match Eio.Buf_read.ensure ic 1 with
| exception End_of_file -> ""
| () ->
let len = Int.min len (Eio.Buf_read.buffered_bytes ic) in
Eio.Buf_read.take len ic

let write oc string = Eio.Buf_write.string oc string
let flush = Eio.Buf_write.flush
Expand Down

0 comments on commit 4b32c1c

Please sign in to comment.