Skip to content

Commit

Permalink
write_from->write, zap comment, change wording on flow.mli
Browse files Browse the repository at this point in the history
  • Loading branch information
haesbaert committed Sep 28, 2022
1 parent 82b41f6 commit e8e2f26
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
8 changes: 4 additions & 4 deletions lib_eio/flow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ let string_source s = cstruct_source [Cstruct.of_string s]
class virtual sink = object (_ : <Generic.t; ..>)
method probe _ = None
method virtual copy : 'a. (#source as 'a) -> unit
method virtual write_from : Cstruct.t -> unit
method virtual write : Cstruct.t -> unit
end

let write (t : #sink) (buf : Cstruct.t) = t#write_from buf
let write (t : #sink) (buf : Cstruct.t) = t#write buf

let copy (src : #source) (dst : #sink) = dst#copy src

Expand All @@ -82,8 +82,8 @@ let buffer_sink b =
done
with End_of_file -> ()

method write_from buf =
Buffer.add_bytes b (Cstruct.to_bytes buf) (* XXX slow *)
method write buf =
Buffer.add_bytes b (Cstruct.to_bytes buf)
end

class virtual two_way = object (_ : <source; sink; ..>)
Expand Down
6 changes: 4 additions & 2 deletions lib_eio/flow.mli
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ type read_method += Read_source_buffer of ((Cstruct.t list -> int) -> unit)
class virtual sink : object
inherit Generic.t
method virtual copy : 'a. (#source as 'a) -> unit
method virtual write_from : Cstruct.t -> unit
method virtual write : Cstruct.t -> unit
end

val write : #sink -> Cstruct.t -> unit
(** [write dst buf] writes one or more bytes from [buf] *)
(** [write dst buf] writes one or more bytes from [buf]. This is a low
level API, consider using [copy] if possible as it may allow
optimizations. *)

val copy : #source -> #sink -> unit
(** [copy src dst] copies data from [src] to [dst] until end-of-file. *)
Expand Down
2 changes: 1 addition & 1 deletion lib_eio/mock/flow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ let make ?(pp=pp_default) label =
traceln "%s: read @[<v>%a@]" label pp data;
len

method write_from buf =
method write buf =
Handler.run on_write;
traceln "%s: wrote @[<v>%a@]" label pp Cstruct.(to_string (sub buf 0 (length buf)))

Expand Down
2 changes: 1 addition & 1 deletion lib_eio_linux/eio_linux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ let flow fd =

method read_methods = []

method write_from buf = Low_level.writev fd [buf]
method write buf = Low_level.writev fd [buf]

method copy src =
match get_fd_opt src with
Expand Down
4 changes: 2 additions & 2 deletions lib_eio_luv/eio_luv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ let flow fd = object (_ : <source; sink; ..>)

method read_methods = []

method write_from buf =
method write buf =
File.write fd [Cstruct.to_bigarray buf] |> or_raise

method copy src =
Expand Down Expand Up @@ -597,7 +597,7 @@ let socket sock = object
let buf = Cstruct.to_bigarray buf in
Stream.read_into sock buf

method write_from buf =
method write buf =
let buf = Cstruct.to_bigarray buf in
Stream.write sock [buf]

Expand Down

0 comments on commit e8e2f26

Please sign in to comment.