Skip to content

Commit

Permalink
Merge pull request #6 from inhabitedtype/pending-bytes
Browse files Browse the repository at this point in the history
Pending bytes
  • Loading branch information
seliopou authored Jun 23, 2017
2 parents 597835d + 8873491 commit 941558c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/faraday.ml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ let schedule_gen t ~length ~to_buffer ?(off=0) ?len a =
| None -> length a - off
| Some len -> len
in
schedule_iovec t ~off ~len (to_buffer a)
if len > 0 then schedule_iovec t ~off ~len (to_buffer a)

let schedule_string =
let to_buffer a = `String a in
Expand Down Expand Up @@ -393,8 +393,11 @@ let close t =
let is_closed t =
t.closed

let pending_bytes t =
(t.write_pos - t.scheduled_pos) + (t.bytes_received - t.bytes_written)

let has_pending_output t =
not (Buffers.is_empty t.scheduled)
pending_bytes t <> 0

let yield t =
t.yield <- true
Expand Down
4 changes: 4 additions & 0 deletions lib/faraday.mli
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ val has_pending_output : t -> bool
be the case that [t]'s queued output is being serviced by some other thread
of control, but has not yet completed. *)

val pending_bytes : t -> int
(** [pending_bytes t] is the size of the next write, in bytes, that [t] will
surface to the caller. *)


(** {2 Running} *)

Expand Down
6 changes: 3 additions & 3 deletions lib_test/test_faraday.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ let empty =
check ~iovecs:0 ~msg:"bigstring" [`Write_bigstring ""] ""
end
; "schedule", `Quick, begin fun () ->
check ~iovecs:1 ~msg:"string" [`Schedule_string ""] "";
check ~iovecs:1 ~msg:"bytes" [`Schedule_bytes ""] "";
check ~iovecs:1 ~msg:"bigstring" [`Schedule_bigstring ""] ""
check ~iovecs:0 ~msg:"string" [`Schedule_string ""] "";
check ~iovecs:0 ~msg:"bytes" [`Schedule_bytes ""] "";
check ~iovecs:0 ~msg:"bigstring" [`Schedule_bigstring ""] ""
end ]

let write =
Expand Down

0 comments on commit 941558c

Please sign in to comment.