aboutsummaryrefslogtreecommitdiff
path: root/lib/cThread.ml
diff options
context:
space:
mode:
authorEnrico Tassi2014-06-26 15:38:49 +0200
committerEnrico Tassi2014-07-10 15:22:58 +0200
commit19d2075236c4c3fd932f7cf003b9f7283dafaeca (patch)
tree2a0d7c5a12ddbb88084fbb896ed221bd0aba2e33 /lib/cThread.ml
parentedee36d00147dfaa99acf52a7b4d7ebf329b013f (diff)
more APIs in TQueue and CThread
These are now sufficient to implement PIDE
Diffstat (limited to 'lib/cThread.ml')
-rw-r--r--lib/cThread.ml19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/cThread.ml b/lib/cThread.ml
index a38c88d802..76e975d2d0 100644
--- a/lib/cThread.ml
+++ b/lib/cThread.ml
@@ -34,6 +34,25 @@ let really_read_fd fd s off len =
i := !i + r
done
+let thread_friendly_really_read ic s ~off ~len =
+ try
+ let fd = Unix.descr_of_in_channel ic in
+ really_read_fd fd s off len
+ with Unix.Unix_error _ -> raise End_of_file
+
+let thread_friendly_really_read_line ic =
+ try
+ let fd = Unix.descr_of_in_channel ic in
+ let b = Buffer.create 1024 in
+ let s = String.make 1 '\000' in
+ while s <> "\n" do
+ let n = thread_friendly_read_fd fd s ~off:0 ~len:1 in
+ if n = 0 then raise End_of_file;
+ if s <> "\n" then Buffer.add_string b s;
+ done;
+ Buffer.contents b
+ with Unix.Unix_error _ -> raise End_of_file
+
let thread_friendly_input_value ic =
try
let fd = Unix.descr_of_in_channel ic in