Debian Codegraph @

lib/spawn.mli

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 (* This module implements spawning/killing managed processes with a
12 * synchronous or asynchronous communication channel that works with
13 * threads or with a glib like main loop model.
14 *
15 * This module requires no threads and no main loop model. It takes care
16 * of using the fastest communication channel given the underlying OS and
17 * the requested kind of communication.
18 *
19 * The spawned process must use the Spawned module to init its communication
20 * channels.
21 *)
22
23 (* This is the control panel for managed processes *)
24 module type Control = sig
25 type handle
26
27 val kill : handle -> unit
28 val wait : handle -> Unix.process_status
29 val unixpid : handle -> int
30
31 (* What is used in debug messages *)
32 val uid : handle -> string
33
34 val is_alive : handle -> bool
35 end
36
37 (* Abstraction to work with both threads and main loop models *)
38 module type MainLoopModel = sig
39 type async_chan
40 type condition
41 type watch_id
42
43 val add_watch : callback:(condition list -> bool) -> async_chan -> watch_id
44 val remove_watch : watch_id -> unit
45 val read_all : async_chan -> string
46 val async_chan_of_file_or_socket : Unix.file_descr -> async_chan
47 end
48
49 (* spawn a process and read its output asynchronously *)
50 module Async(ML : MainLoopModel) : sig
51 type process
52
53 (* If the returned value is false the callback is never called again and
54 * the process is killed *)
55 type callback = ML.condition list -> read_all:(unit -> string) -> bool
56
57 val spawn :
58 ?prefer_sock:bool -> ?env:string array -> string -> string array ->
59 callback -> process * out_channel
60
61 include Control with type handle = process
62 end
63
64 (* spawn a process and read its output synchronously *)
65 module Sync () : sig
66 type process
67
68 val spawn :
69 ?prefer_sock:bool -> ?env:string array -> string -> string array ->
70 process * in_channel * out_channel
71
72 include Control with type handle = process
73 end
74
75 (* This is exported to separate the Spawned module, that for simplicity assumes
76 * Threads so it is in a separate file *)
77 type req = ReqDie | Hello of int * int
78 val proto_version : int