Skip to content

Commit e13df5a

Browse files
author
Marcello Seri
committed
fd_send_recv: add fd_send_substring as for write in the ocaml std library
See https://github.com/ocaml/ocaml/blob/trunk/otherlibs/unix/unix.ml#L328-L332 Signed-off-by: Marcello Seri <[email protected]>
1 parent e746181 commit e13df5a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/fd_send_recv.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ let _ = Callback.register_exception "fd_send_recv.unix_error" (Unix_error (0))
1919
external send_fd : Unix.file_descr -> bytes -> int -> int -> Unix.msg_flag list -> Unix.file_descr -> int = "stub_unix_send_fd_bytecode" "stub_unix_send_fd"
2020
external recv_fd : Unix.file_descr -> bytes -> int -> int -> Unix.msg_flag list -> int * Unix.sockaddr * Unix.file_descr = "stub_unix_recv_fd"
2121

22+
let send_fd_substring channel_fd buf ofs len flags fd_to_send =
23+
send_fd channel_fd (Bytes.unsafe_of_string buf) ofs len flags fd_to_send
24+
2225
let fd_of_int (x: int) : Unix.file_descr = Obj.magic x
2326

2427
let int_of_fd (x: Unix.file_descr) : int = Obj.magic x

lib/fd_send_recv.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ val recv_fd : Unix.file_descr -> bytes -> int -> int ->
3232
substring [buf] [ofs] [len] with [flags], returning the number of
3333
bytes read, the address of the peer and a file descriptor. *)
3434

35+
val send_fd_substring : Unix.file_descr -> string -> int -> int ->
36+
Unix.msg_flag list -> Unix.file_descr -> int
37+
(** Like [send_fd] but takes a string *)
38+
3539
val int_of_fd : Unix.file_descr -> int
3640
(** [int_of_fd fd] returns the underlying unix integer file descriptor
3741
associated with OCaml Unix.file_descr [fd]. *)

0 commit comments

Comments
 (0)