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

faraday-async limit iovecs to iovec max #75

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions async/faraday_async.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ let serialize t ~yield ~writev =
shutdown ();
raise exn

let limit_iovecs_length_to_iov_max iovecs =
match Unix.sysconf Unix.IOV_MAX with
| None -> iovecs
| Some iov_max ->
match Int64.to_int iov_max with
| None -> iovecs
| Some iov_max ->
match List.length iovecs with
| l when l > iov_max -> List.sub iovecs ~pos:0 ~len:iov_max
| _ -> iovecs

let writev_of_fd fd =
let badfd =
failwithf "writev_of_fd got bad fd: %s" (Fd.to_string fd)
Expand All @@ -55,6 +66,7 @@ let writev_of_fd fd =
raise exn
in
fun iovecs ->
let iovecs = limit_iovecs_length_to_iov_max iovecs in
let iovecs = Array.of_list_map iovecs ~f:(fun iovec ->
let { Faraday.buffer; off = pos; len } = iovec in
Unix.IOVec.of_bigstring ~pos ~len buffer)
Expand Down