Skip to content

Commit

Permalink
[feature] appruntime: Added read_more4, same as read_more2 but for Bu…
Browse files Browse the repository at this point in the history
…f instead of Buffer.
  • Loading branch information
nrs135 committed Nov 14, 2011
1 parent 4268e9e commit a12b805
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions appruntime/connection.ml
Expand Up @@ -109,6 +109,11 @@ let read_more2 conn buf =
let () = Buffer.add_substring buf read_buff 0 nread in let () = Buffer.add_substring buf read_buff 0 nread in
nread, buf nread, buf


let read_more4 conn buf =
let nread, _ = read_aux conn read_buff read_buff_length in
let () = Buf.add_substring buf read_buff 0 nread in
nread, buf

let read_from conn = let read_from conn =
let nread, addr = read_aux conn read_buff read_buff_length in let nread, addr = read_aux conn read_buff read_buff_length in
let get_peer = lazy (Unix.getpeername (NA.get_fd conn)) in let get_peer = lazy (Unix.getpeername (NA.get_fd conn)) in
Expand Down
38 changes: 38 additions & 0 deletions appruntime/scheduler.ml
Expand Up @@ -311,6 +311,44 @@ let read_more2 sched conn ?read_max ?timeout buf ?(size_max=(-1)) ?err_cont fina
in in
() ()


let read_more4 sched conn ?read_max ?timeout buf ?(size_max=(-1)) ?err_cont finalize =
(* TODO: read_max and size_max (windows) unused *)
#<If> L.info_conn "read_more4" conn.addr #<End>;
let _ = read_max in
let _ = size_max in
let decide (nb_read, buf) =
if nb_read = -1 then Job.Execute buf
else if nb_read = 0 then Job.Error Connection_closed
else Job.Finalize (nb_read, buf)
in
let execute buf =
try
let nread, buf = C.read_more4 conn.addr buf in
NetStats.register_recv ~size:nread ~conn:conn.addr sched.stats;
nread, buf
with
| C.Busy ->
#<If> L.info_conn "read" ~s:"busy" conn.addr #<End>;
(-1, buf)
| e -> raise e
in
let error = get_err_cont sched conn err_cont in
let _ =
Job.make
sched.operation
sched.priority
sched.counter
(NA.get_fd conn.addr)
K.Operation.In
timeout
decide
execute
error
finalize
(-1, buf)
in
()

let read sched conn ?timeout ?err_cont finalize = let read sched conn ?timeout ?err_cont finalize =
#<If> L.info_conn "read" conn.addr #<End>; #<If> L.info_conn "read" conn.addr #<End>;
let decide (nb_read, str) = let decide (nb_read, str) =
Expand Down
10 changes: 10 additions & 0 deletions appruntime/scheduler.mli
Expand Up @@ -226,6 +226,16 @@ val read_more2 :
?err_cont:(exn -> unit) -> ?err_cont:(exn -> unit) ->
(int * Buffer.t -> unit) -> unit (int * Buffer.t -> unit) -> unit


val read_more4 :
t ->
connection_info ->
?read_max:int ->
?timeout:Time.t ->
Buf.t ->
?size_max:int ->
?err_cont:(exn -> unit) ->
(int * Buf.t -> unit) -> unit

val read : val read :
t -> t ->
connection_info -> connection_info ->
Expand Down

0 comments on commit a12b805

Please sign in to comment.