1 (**************************************************************************)
2 (* *)
3 (* OCaml *)
4 (* *)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
6 (* *)
7 (* Copyright 1996 Institut National de Recherche en Informatique et *)
8 (* en Automatique. *)
9 (* *)
10 (* All rights reserved. This file is distributed under the terms of *)
11 (* the GNU Lesser General Public License version 2.1, with the *)
12 (* special exception on linking described in the file LICENSE. *)
13 (* *)
14 (**************************************************************************)
15
16 (* Module [ThreadUnix]: thread-compatible system calls *)
17
18 open Unix
19
20 (*** Process handling *)
21
22 external execv : string -> string array -> unit = "unix_execv"
23 external execve : string -> string array -> string array -> unit
24 = "unix_execve"
25 external execvp : string -> string array -> unit = "unix_execvp"
26 let wait = Unix.wait
27 let waitpid = Unix.waitpid
28 let system = Unix.system
29 let read = Unix.read
30 let write = Unix.write
31 let write_substring = Unix.write_substring
32 let select = Unix.select
33
34 let timed_read fd buff ofs len timeout =
35 if Thread.wait_timed_read fd timeout
36 then Unix.read fd buff ofs len
37 else raise (Unix_error(ETIMEDOUT, "timed_read", ""))
38
39 let timed_write fd buff ofs len timeout =
40 if Thread.wait_timed_write fd timeout
41 then Unix.write fd buff ofs len
42 else raise (Unix_error(ETIMEDOUT, "timed_write", ""))
43
44 let timed_write_substring fd buff ofs len timeout =
45 timed_write fd (Bytes.unsafe_of_string buff) ofs len timeout
46
47 let pipe = Unix.pipe
48
49 let open_process_in = Unix.open_process_in
50 let open_process_out = Unix.open_process_out
51 let open_process = Unix.open_process
52
53 external sleep : int -> unit = "unix_sleep"
54
55 let socket = Unix.socket
56 let accept = Unix.accept
57 external connect : file_descr -> sockaddr -> unit = "unix_connect"
58 let recv = Unix.recv
59 let recvfrom = Unix.recvfrom
60 let send = Unix.send
61 let send_substring = Unix.send_substring
62 let sendto = Unix.sendto
63 let sendto_substring = Unix.sendto_substring
64
65 let open_connection = Unix.open_connection
66