Module type Rig_edge.Io
Devices of memory that the host reads and writes through calls.
An io device holds memory that the host does not address, such as a file, and runs no work. Its reads and writes are synchronous, in the caller. Of the exceptions its library raises, only Io.Fault loses the device. Any other reaches the caller, since no work of the device can see a change it left half done. The library must leave each region it made readable, writable and freeable after an exception escapes any of its calls.
The library must count its locks, check its own functions and give back its locks as a driver does (Drivers).
type tThe type for open io devices.
type regionThe type for memory of an io device.
exception Fault of stringFault why reports that the device failed, such as a closed connection.
region_key identifies the io library and its regions. Rig.Buffer.of_io and Rig.Buffer.io cast regions by it, and a device's name stays with the library that opened it.
alloc d n is n new bytes of d's memory, or None if d has no room. n is positive and a multiple of 4, Rig.word.
Raises Invalid_argument if d's memory is only what its library opens and hands to Rig.Buffer.of_io, such as a disk's files. Rig.Buffer.create raises it in turn.
read d r ~at ~dst ~len reads the len bytes at at in r into host memory at dst.
Raises Sys_error for a failure of the memory alone, such as a file truncated since it was opened, which loses nothing, and Fault, which loses d.
write d r ~at ~src ~len writes the len bytes of host memory at src at at in r.
Raises as read.
val pages :
t ->
region ->
(char, Stdlib.Bigarray.int8_unsigned_elt, Stdlib.Bigarray.c_layout)
Stdlib.Bigarray.Array1.t
optionpages d r is r's bytes as host memory, or None if d maps none. The mapping is r's memory, so read and write see writes through it, and it sees theirs. For r that d holds for reading (Rig.Buffer.access), a write through the mapping must not reach r. rig asks once per allocation, at its first borrow that gets a result, and keeps the result.
A device other than the host maps the pages where its driver maps host memory (Driver.map_host). Some drivers refuse pages mapped read-only, so a library maps a region it holds for reading as the process's own copy, as a private mapping of a file is. Some refuse a shared mapping of a file, and their devices then copy through staging memory.
Raises Sys_error for a transient failure of the memory alone, such as too many open files, which loses nothing. The borrow raises it, and the next borrow asks again. Raises Fault, which loses d.
prefetch d r ~at ~len asks d to read the len bytes at at in r ahead, before a device other than the host reaches them through pages. It is a hint, and must raise nothing.