Permalink
Browse files

[feature] appruntime: Added read_more4, same as read_more2 but for Bu…

…f instead of Buffer.
  • Loading branch information...
nrs135 committed Sep 13, 2011
1 parent 4268e9e commit a12b805c6b62beb007b835fca96515b8c8bda8a5
Showing with 53 additions and 0 deletions.
  1. +5 −0 appruntime/connection.ml
  2. +38 −0 appruntime/scheduler.ml
  3. +10 −0 appruntime/scheduler.mli
View
@@ -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
View
@@ -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 *)
+ #<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 =
#<If> L.info_conn "read" conn.addr #<End>;
let decide (nb_read, str) =
View
@@ -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 ->

0 comments on commit a12b805

Please sign in to comment.