From a12b805c6b62beb007b835fca96515b8c8bda8a5 Mon Sep 17 00:00:00 2001 From: Norman Scaife Date: Tue, 13 Sep 2011 16:02:00 +0200 Subject: [PATCH] [feature] appruntime: Added read_more4, same as read_more2 but for Buf instead of Buffer. --- appruntime/connection.ml | 5 +++++ appruntime/scheduler.ml | 38 ++++++++++++++++++++++++++++++++++++++ appruntime/scheduler.mli | 10 ++++++++++ 3 files changed, 53 insertions(+) diff --git a/appruntime/connection.ml b/appruntime/connection.ml index a3f08002..2b1895e7 100644 --- a/appruntime/connection.ml +++ b/appruntime/connection.ml @@ -109,6 +109,11 @@ let read_more2 conn buf = let () = Buffer.add_substring buf read_buff 0 nread in 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 nread, addr = read_aux conn read_buff read_buff_length in let get_peer = lazy (Unix.getpeername (NA.get_fd conn)) in diff --git a/appruntime/scheduler.ml b/appruntime/scheduler.ml index 43515f07..bc8c212d 100644 --- a/appruntime/scheduler.ml +++ b/appruntime/scheduler.ml @@ -311,6 +311,44 @@ let read_more2 sched conn ?read_max ?timeout buf ?(size_max=(-1)) ?err_cont fina in () +let read_more4 sched conn ?read_max ?timeout buf ?(size_max=(-1)) ?err_cont finalize = + (* TODO: read_max and size_max (windows) unused *) + # L.info_conn "read_more4" conn.addr #; + 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 -> + # L.info_conn "read" ~s:"busy" conn.addr #; + (-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 = # L.info_conn "read" conn.addr #; let decide (nb_read, str) = diff --git a/appruntime/scheduler.mli b/appruntime/scheduler.mli index dd061215..6bdff082 100644 --- a/appruntime/scheduler.mli +++ b/appruntime/scheduler.mli @@ -226,6 +226,16 @@ val read_more2 : ?err_cont:(exn -> 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 : t -> connection_info ->