1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
|
(** Effects based parallel IO for OCaml.
Eio provides support for concurrency (juggling many tasks) and
parallelism (using multiple CPU cores for performance).
It provides facilities for creating and coordinating fibers (light-weight
threads) and domains (for parallel processing), as well as interfaces for
interacting with resources provided by the operating system.
These features must be used within an {e event loop},
provided by an Eio {e backend}.
Applications can use {!Eio_main.run} to run a suitable loop.
See {{:https://github.com/ocaml-multicore/eio}} for a tutorial. *)
(** Commonly used standard features. This module is intended to be [open]ed. *)
module Std = Std
(** {1 Fibers} *)
(** Grouping fibers and other resources so they can be turned off together. *)
module Switch = Eio__core.Switch
(** A fiber is a light-weight thread. *)
module Fiber = Eio__core.Fiber
(** Cancelling fibers. *)
module Cancel = Eio__core.Cancel
(** {1 Concurrency primitives} *)
(** A promise is a placeholder for result that will arrive in the future. *)
module Promise = Eio__core.Promise
(** A counting semaphore. *)
module Semaphore = Semaphore
(** Mutual exclusion. *)
module Mutex = Eio_mutex
(** Waiting for a condition to become true. *)
module Condition = Condition
(** Delayed evaluation. *)
module Lazy = Lazy
(** {1 Collections} *)
(** A stream/queue. *)
module Stream = Stream
(** A pool of resources. *)
module Pool = Pool
(** {1 Multiple domains} *)
(** Parallel computation across multiple CPU cores. *)
module Domain_manager = Domain_manager
(** A pool of domains for executing jobs. *)
module Executor_pool = Executor_pool
(** {1 Errors and debugging} *)
val traceln :
?__POS__:string * int * int * int ->
('a, Format.formatter, unit, unit) format4 -> 'a
(** [traceln fmt] outputs a debug message (typically to stderr).
Trace messages are printed by default and do not require logging to be configured first.
The message is printed with a newline, and is flushed automatically.
[traceln] is intended for quick debugging rather than for production code.
Unlike most Eio operations, [traceln] will never switch to another fiber;
if the OS is not ready to accept the message then the whole domain waits.
It is safe to call [traceln] from multiple domains at the same time.
Each line will be written atomically.
Examples:
{[
traceln "x = %d" x;
traceln "x = %d" x ~__POS__; (* With location information *)
]}
@param __POS__ Display [__POS__] as the location of the [traceln] call. *)
(** Eio exceptions. *)
module Exn = Eio__core.Exn
exception Io of Exn.err * Exn.context
(** Control over debugging. *)
module Debug : sig
(** Example:
{[
open Eio.Std
let my_traceln = {
Eio.Debug.traceln = fun ?__POS__:_ fmt -> Fmt.epr ("[custom-trace] " ^^ fmt ^^ "@.")
}
let () =
Eio_main.run @@ fun env ->
let debug = Eio.Stdenv.debug env in
Fiber.with_binding debug#traceln my_traceln @@ fun () ->
traceln "Traced with custom function"
]}
This will output:
{[ [custom-trace] Traced with custom function ]}
*)
type traceln = Eio__core.Private.Debug.traceln = {
traceln : 'a. ?__POS__:string * int * int * int -> ('a, Format.formatter, unit, unit) format4 -> 'a;
} [@@unboxed]
(** A function that writes trace logging to some trace output.
It must not switch fibers, as tracing must not affect scheduling.
If the system is not ready to receive the trace output,
the whole domain must block until it is. *)
val with_trace_prefix : (Format.formatter -> unit) -> (unit -> 'a) -> 'a
(** [with_trace_prefix fmt fn] runs [fn ()] with a traceln that outputs [fmt] before each message. *)
type t = <
traceln : traceln Fiber.key;
>
(** Fiber keys used to control debugging. Use {!Stdenv.debug} to get this. *)
end
(** {1 Cross-platform OS API}
The general pattern here is that each type of resource has a set of functions for using it,
plus a provider ([Pi]) module to allow defining your own implementations.
The system resources are available from the environment argument provided by your event loop
(e.g. {!Eio_main.run}). *)
(** Defines the base resource type. *)
module Resource = Resource
(** {2 Byte streams} *)
(** A flow can be used to read or write bytes. *)
module Flow : sig
include module type of Flow (** @inline *)
(** {2 Convenience wrappers} *)
val read_all : _ source -> string
(** [read_all src] is a convenience wrapper to read an entire flow.
It is the same as [Buf_read.(parse_exn take_all) src ~max_size:max_int] *)
end
(** Buffered input and parsing. *)
module Buf_read = Buf_read
(** Buffered output and formatting. *)
module Buf_write = Buf_write
(** {2 Networking} *)
(** Network sockets and addresses. *)
module Net = Net
(** {2 File-systems} *)
(** Accessing paths on a file-system. *)
module Path = Path
(** Operations on open files. *)
module File = File
(** File-system types. *)
module Fs = Fs
(** {2 Processes} *)
(** Managing child processes. *)
module Process = Process
(** {2 Time} *)
(** Clocks, time, sleeping and timeouts. *)
module Time = Time
(** {2 Main env} *)
(** The standard environment of a process. *)
module Stdenv : sig
(** All access to the outside world comes from running the event loop,
which provides an environment (e.g. an {!Eio_unix.Stdenv.base}).
Example:
{[
let () =
Eio_main.run @@ fun env ->
Eio.Path.with_open_dir env#fs "/srv/www" @@ fun www ->
serve_files www
~net:env#net
]}
*)
(** {1 Standard streams}
To use these, see {!Flow}. *)
val stdin : <stdin : _ Flow.source as 'a; ..> -> 'a
val stdout : <stdout : _ Flow.sink as 'a; ..> -> 'a
val stderr : <stderr : _ Flow.sink as 'a; ..> -> 'a
(** {1 File-system access}
To use these, see {!Path}. *)
val cwd : <cwd : _ Path.t as 'a; ..> -> 'a
(** [cwd t] is the current working directory of the process (this may change
over time if the process does a "chdir" operation, which is not recommended). *)
val fs : <fs : _ Path.t as 'a; ..> -> 'a
(** [fs t] is the process's full access to the filesystem.
Paths can be absolute or relative (to the current working directory).
Using relative paths with this is similar to using them with {!cwd},
except that this will follow ".." and symlinks to other parts of the filesystem.
[fs] is useful for handling paths passed in by the user. *)
(** {1 Network}
To use this, see {!Net}.
*)
val net : <net : _ Net.t as 'a; ..> -> 'a
(** [net t] gives access to the process's network namespace. *)
(** {1 Processes }
To use this, see {!Process}.
*)
val process_mgr : <process_mgr : _ Process.mgr as 'a; ..> -> 'a
(** [process_mgr t] allows you to manage child processes. *)
(** {1 Domains (using multiple CPU cores)}
To use this, see {!Domain_manager}.
*)
val domain_mgr : <domain_mgr : _ Domain_manager.t as 'a; ..> -> 'a
(** [domain_mgr t] allows running code on other cores. *)
(** {1 Time}
To use this, see {!Time}.
*)
val clock : <clock : _ Time.clock as 'a; ..> -> 'a
(** [clock t] is the system clock (used to get the current time and date). *)
val mono_clock : <mono_clock : _ Time.Mono.t as 'a; ..> -> 'a
(** [mono_clock t] is a monotonic clock (used for measuring intervals). *)
(** {1 Randomness} *)
val secure_random : <secure_random : _ Flow.source as 'a; ..> -> 'a
(** [secure_random t] is an infinite source of random bytes suitable for cryptographic purposes. *)
(** {1 Debugging} *)
val debug : <debug : <Debug.t; ..> as 'a; ..> -> 'a
(** [debug t] provides privileged controls for debugging. *)
val backend_id : <backend_id:string; ..> -> string
(** [backend_id t] provides the name of the backend being used.
The possible values are the same as the possible values of the "EIO_BACKEND"
environment variable used by {!Eio_main.run}. *)
end
(** {1 Provider API for OS schedulers} *)
(** API for use by the scheduler implementation. *)
module Private = Eio__core.Private
|