mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-06 16:58:48 +08:00
input buffered wrapper extended to accept any reading function
This commit is contained in:
@@ -93,7 +93,7 @@ let close = Unix.close
|
||||
type 'a closure = Closure of 'a
|
||||
|
||||
let buffer_len = 256
|
||||
let input = fun f ->
|
||||
let input = fun ?(read = Unix.read) f ->
|
||||
let buffer = String.create buffer_len
|
||||
and index = ref 0 in
|
||||
|
||||
@@ -102,7 +102,7 @@ let input = fun f ->
|
||||
index := n in
|
||||
|
||||
Closure (fun fd ->
|
||||
let n = !index + Unix.read fd buffer !index (buffer_len - !index) in
|
||||
let n = !index + read fd buffer !index (buffer_len - !index) in
|
||||
Debug.call 'T' (fun f -> fprintf f "input: %d %d\n" !index n);
|
||||
let rec parse = fun start n ->
|
||||
Debug.call 'T' (fun f -> fprintf f "input parse: %d %d\n" start n);
|
||||
|
||||
@@ -54,11 +54,13 @@ val close : Unix.file_descr -> unit
|
||||
val set_dtr : Unix.file_descr -> bool -> unit
|
||||
val set_speed : Unix.file_descr -> speed -> unit
|
||||
|
||||
val input : (string -> int) -> (Unix.file_descr -> unit) closure
|
||||
(** Buffered input. [input f] Returns a closure which must be called when
|
||||
val input :
|
||||
?read:(Unix.file_descr -> string -> int -> int -> int) ->
|
||||
(string -> int) -> (Unix.file_descr -> unit) closure
|
||||
(** Buffered input. [input ?read f] Returns a closure which must be called when
|
||||
characters are available on the stream. These characters are stored in a
|
||||
a buffer. [f] is then called on the buffer. [f] must return the number
|
||||
of consumed characters. *)
|
||||
of consumed characters. Default [read] is [Unix.read] *)
|
||||
|
||||
type payload
|
||||
|
||||
|
||||
Reference in New Issue
Block a user