Skip to content

Commit 10558df

Browse files
committed
Merge pull request #41 from antron/lwt.unix
2 parents dae8673 + 21d5e97 commit 10558df

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

faraday-lwt-unix.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ build-test: [
1515
depends: [
1616
"jbuilder" {build & >= "1.0+beta10"}
1717
"faraday-lwt"
18-
"lwt"
18+
"lwt" {>= "2.7.0"}
1919
"base-unix"
2020
]
2121
available: [ ocaml-version >= "4.02.0" ]

lwt_unix/faraday_lwt_unix.ml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
open Lwt
2-
31
include Faraday_lwt
42

5-
let write_bigstring fd buf off len =
6-
try Lwt_bytes.write fd buf off len >|= fun n -> `Ok n
7-
with Unix.Unix_error (Unix.EBADF, "check_descriptor", _) -> return `Closed
3+
open Lwt.Infix
84

95
let writev_of_fd fd =
10-
(* XXX(seliopou): This function only writes the first iovec because lwt
11-
currently does not expose a writev function. That system call should be
12-
bound manually at some point in the future. *)
13-
function
14-
| [] -> assert false
15-
| { Faraday.buffer; off; len }::_ -> write_bigstring fd buffer off len
6+
fun iovecs ->
7+
let lwt_iovecs = Lwt_unix.IO_vectors.create () in
8+
iovecs |> List.iter (fun {Faraday.buffer; off; len} ->
9+
Lwt_unix.IO_vectors.append_bigarray lwt_iovecs buffer off len);
10+
11+
Lwt.catch
12+
(fun () ->
13+
Lwt_unix.writev fd lwt_iovecs
14+
>|= fun n -> `Ok n)
15+
(function
16+
| Unix.Unix_error (Unix.EBADF, "check_descriptor", _) ->
17+
Lwt.return `Closed
18+
| exn ->
19+
Lwt.fail exn)

lwt_unix/jbuild

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
(public_name faraday-lwt-unix)
66
(wrapped false)
77
(libraries
8-
(faraday lwt faraday-lwt))
8+
(faraday lwt lwt.unix faraday-lwt))
99
(flags (:standard -safe-string))))

0 commit comments

Comments
 (0)