diff --git a/eio/Eio/.dummy b/eio/Eio/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/eio/Eio/Buf_read/BE/index.html b/eio/Eio/Buf_read/BE/index.html index 126ce88f4..1bbcb1de7 100644 --- a/eio/Eio/Buf_read/BE/index.html +++ b/eio/Eio/Buf_read/BE/index.html @@ -1,2 +1,2 @@ -
Buf_read.BE
Big endian parsers
val uint16 : int parser
uint16
parses the next 2 bytes as the lower 16 bits of an int
in big-endian byte order
val uint32 : int32 parser
uint32
parses the next 4 bytes as an int32
in big-endian byte order
val uint48 : int64 parser
uint48
parses the next 6 bytes as a 48-bit unsigned big-endian integer
val uint64 : int64 parser
uint64
parses the next 8 bytes as an int64
in big-endian byte order
val float : float parser
float
parses the next 4 bytes as a float
in big-endian byte order
val double : float parser
double
parses the next 8 bytes as a float
in big-endian byte order
Buf_read.BE
Big endian parsers
val uint16 : int parser
uint16
parses the next 2 bytes as the lower 16 bits of an int
in big-endian byte order
val uint32 : int32 parser
uint32
parses the next 4 bytes as an int32
in big-endian byte order
val uint48 : int64 parser
uint48
parses the next 6 bytes as a 48-bit unsigned big-endian integer
val uint64 : int64 parser
uint64
parses the next 8 bytes as an int64
in big-endian byte order
val float : float parser
float
parses the next 4 bytes as a float
in big-endian byte order
val double : float parser
double
parses the next 8 bytes as a float
in big-endian byte order
Buf_read.LE
Little endian parsers
val uint16 : int parser
uint16
parses the next 2 bytes as the lower 16 bits of an int
in little-endian byte order
val uint32 : int32 parser
uint32
parses the next 4 bytes as an int32
in little-endian byte order
val uint48 : int64 parser
uint48
parses the next 6 bytes as a 48-bit unsigned big-endian integer
val uint64 : int64 parser
uint64
parses the next 8 bytes as an int64
in little-endian byte order
val float : float parser
float
parses the next 4 bytes as a float
in little-endian byte order
val double : float parser
double
parses the next 8 bytes as a float
in little-endian byte order
Buf_read.LE
Little endian parsers
val uint16 : int parser
uint16
parses the next 2 bytes as the lower 16 bits of an int
in little-endian byte order
val uint32 : int32 parser
uint32
parses the next 4 bytes as an int32
in little-endian byte order
val uint48 : int64 parser
uint48
parses the next 6 bytes as a 48-bit unsigned big-endian integer
val uint64 : int64 parser
uint64
parses the next 8 bytes as an int64
in little-endian byte order
val float : float parser
float
parses the next 4 bytes as a float
in little-endian byte order
val double : float parser
double
parses the next 8 bytes as a float
in little-endian byte order
Buf_read.Syntax
Convenient syntax for some of the combinators.
a <* b
is map fst (pair a b)
. It parses two things and keeps only the first.
Buf_read.Syntax
Convenient syntax for some of the combinators.
a <* b
is map fst (pair a b)
. It parses two things and keeps only the first.
Eio.Buf_read
Buffered input and parsing
This module provides fairly efficient non-backtracking parsers. It is modelled on Angstrom's API, and you should use that if backtracking is needed.
Example:
let r = Buf_read.of_flow flow ~max_size:1_000_000 in +
Buf_read (eio.Eio.Buf_read) Module
Eio.Buf_read
Buffered input and parsing
This module provides fairly efficient non-backtracking parsers. It is modelled on Angstrom's API, and you should use that if backtracking is needed.
Example:
let r = Buf_read.of_flow flow ~max_size:1_000_000 in Buf_read.line r
\ No newline at end of file + ('a, [> `Msg of string ]) Stdlib.resultRaised if parsing an item would require enlarging the buffer beyond its configured limit.
type 'a parser = t -> 'a
An
'a parser
is a function that consumes and returns a value of type'a
.val parse : ?initial_size:int -> max_size:int -> 'a parser -> - Flow.source -> + _ Flow.source -> ('a, [> `Msg of string ]) Stdlib.result
parse p flow ~max_size
usesp
to parse everything inflow
.It is a convenience function that does
let buf = of_flow flow ~max_size in format_errors (p <* end_of_input) buf
val parse_exn : ?initial_size:int -> max_size:int -> 'a parser -> - Flow.source -> + _ Flow.source -> 'a
parse_exn
wrapsparse
, but raisesFailure msg
if that returnsError (`Msg msg)
.Catching exceptions with
parse
and then raising them might seem pointless, but this has the effect of turning e.g. anEnd_of_file
exception into aFailure
with a more user-friendly message.val parse_string : 'a parser -> string -> - ('a, [> `Msg of string ]) Stdlib.result
parse_string p s
usesp
to parse everything ins
. It is defined asformat_errors (p <* end_of_input) (of_string s)
val parse_string_exn : 'a parser -> string -> 'a
parse_string_exn
is likeparse_string
, but handles errors likeparse_exn
.val of_flow : ?initial_size:int -> max_size:int -> Flow.source -> t
of_flow ~max_size flow
is a buffered reader backed byflow
.val of_buffer : Cstruct.buffer -> t
of_buffer buf
is a reader that reads frombuf
.buf
is used directly, without being copied.eof_seen (of_buffer buf) = true
. This module will not modifybuf
itself, but it will expose it viapeek
.val of_string : string -> t
of_string s
is a reader that reads froms
.val as_flow : t -> Flow.source
as_flow t
is a buffered flow.Reading from it will return data from the buffer, only reading the underlying flow if the buffer is empty.
Reading data
val line : string parser
line
parses one line.Lines can be terminated by either LF or CRLF. The returned string does not include the terminator.
If
End_of_file
is reached after seeing some data but before seeing a line terminator, the data seen is returned as the last line.val lines : string Stdlib.Seq.t parser
lines
returns a sequence that lazily reads the next line until the end of the input is reached.
lines = seq line ~stop:at_end_of_input
val char : char -> unit parser
char c
checks that the next byte isc
and consumes it.val any_char : char parser
any_char
parses one character.val peek_char : char option parser
peek_char
returnsSome c
wherec
is the next character, but does not consume it.Returns
None
at the end of the input stream rather than raisingEnd_of_file
.val string : string -> unit parser
string s
checks thats
is the next string in the stream and consumes it.val uint8 : int parser
uint8
parses the next byte as an unsigned 8-bit integer.module BE : sig ... end
Big endian parsers
module LE : sig ... end
Little endian parsers
val take : int -> string parser
take n
takes exactlyn
bytes from the input.val take_all : string parser
take_all
takes all remaining data until end-of-file.Returns
""
if already at end-of-file.val take_while : (char -> bool) -> string parser
take_while p
finds the first byte for whichp
is false and consumes and returns all bytes before that.If
p
is true for all remaining bytes, it returns everything until end-of-file.It will return the empty string if there are no matching characters (and therefore never raises
End_of_file
).val take_while1 : (char -> bool) -> string parser
take_while1 p
is liketake_while
. However, the parser fails with "take_while1" if at least one character of input hasn't been consumed by the parser.val skip_while : (char -> bool) -> unit parser
skip_while p
skips zero or more bytes for whichp
istrue
.
skip_while p t
does the same thing asignore (take_while p t)
, except that it is not limited by the buffer size.val skip_while1 : (char -> bool) -> unit parser
skip_while1 p
is likeskip_while
. However, the parser fails with "skip_while1" if at least one character of input hasn't been skipped.val skip : int -> unit parser
skip n
discards the nextn
bytes.
skip n
=map ignore (take n)
, except that the number of skipped bytes may be larger than the buffer (it will not grow).Note: if
End_of_file
is raised, all bytes in the stream will have been consumed.val at_end_of_input : bool parser
at_end_of_input
returnstrue
when at the end of the stream, orfalse
if there is at least one more byte to be read.val end_of_input : unit parser
end_of_input
checks that there are no further bytes in the stream.Combinators
seq p
is a sequence that usesp
to get the next item.A sequence node can only be used while the stream is at the expected position, and will raise
Invalid_argument
if any bytes have been consumed in the meantime. This also means that each node can only be used once; useSeq
.memoize to make the sequence persistent.It is not necessary to consume all the elements of the sequence.
pair a b
is a parser that first usesa
to parse a valuex
, then usesb
to parse a valuey
, then returns(x, y)
.Note that this module does not support backtracking, so if
b
fails then the bytes consumed bya
are lost.val return : 'a -> 'a parser
return x
is a parser that consumes nothing and always returnsx
.return
is justFun.const
.
map f a
is a parser that parses the stream witha
to getv
, and then returnsf v
.
bind a f
is a parser that first usesa
to parse a valuev
, then usesf v
to select the next parser, and then uses that.
format_errors p
catchesFailure
,End_of_file
andBuffer_limit_exceeded
exceptions and returns them as a formatted error message.module Syntax : sig ... end
Convenient syntax for some of the combinators.
Low-level API
val buffered_bytes : t -> int
buffered_bytes t
is the number of bytes that can be read without reading from the underlying flow.val peek : t -> Cstruct.t
peek t
returns a view onto the active part oft
's internal buffer.Performing any operation that might add to the buffer may invalidate this, so it should be used immediately and then forgotten.
Cstruct.length (peek t) = buffered_bytes t
.val ensure : t -> int -> unit
ensure t n
ensures that the buffer contains at leastn
bytes of data.If not, it reads from the flow until there is.
buffered_bytes (ensure t n) >= n
.val consume : t -> int -> unit
val consumed_bytes : t -> int
consumed_bytes t
is the total number of bytes consumed.i.e. it is the offset into the stream of the next byte to be parsed.
val eof_seen : t -> bool
eof_seen t
indicates whether we've receivedEnd_of_file
from the underlying flow.If so, there will never be any further data beyond what
peek
already returns.Note that this returns
false
if we're at the end of the stream but don't know it yet. Useat_end_of_input
to be sure.
parse_string p s
usesp
to parse everything ins
. It is defined asformat_errors (p <* end_of_input) (of_string s)
val parse_string_exn : 'a parser -> string -> 'a
parse_string_exn
is likeparse_string
, but handles errors likeparse_exn
.val of_flow : ?initial_size:int -> max_size:int -> _ Flow.source -> t
of_flow ~max_size flow
is a buffered reader backed byflow
.val of_buffer : Cstruct.buffer -> t
of_buffer buf
is a reader that reads frombuf
.buf
is used directly, without being copied.eof_seen (of_buffer buf) = true
. This module will not modifybuf
itself, but it will expose it viapeek
.val of_string : string -> t
of_string s
is a reader that reads froms
.val as_flow : t -> Flow.source_ty Std.r
as_flow t
is a buffered flow.Reading from it will return data from the buffer, only reading the underlying flow if the buffer is empty.
Reading data
val line : string parser
line
parses one line.Lines can be terminated by either LF or CRLF. The returned string does not include the terminator.
If
End_of_file
is reached after seeing some data but before seeing a line terminator, the data seen is returned as the last line.val lines : string Stdlib.Seq.t parser
lines
returns a sequence that lazily reads the next line until the end of the input is reached.
lines = seq line ~stop:at_end_of_input
val char : char -> unit parser
char c
checks that the next byte isc
and consumes it.val any_char : char parser
any_char
parses one character.val peek_char : char option parser
peek_char
returnsSome c
wherec
is the next character, but does not consume it.Returns
None
at the end of the input stream rather than raisingEnd_of_file
.val string : string -> unit parser
string s
checks thats
is the next string in the stream and consumes it.val uint8 : int parser
uint8
parses the next byte as an unsigned 8-bit integer.module BE : sig ... end
Big endian parsers
module LE : sig ... end
Little endian parsers
val take : int -> string parser
take n
takes exactlyn
bytes from the input.val take_all : string parser
take_all
takes all remaining data until end-of-file.Returns
""
if already at end-of-file.val take_while : (char -> bool) -> string parser
take_while p
finds the first byte for whichp
is false and consumes and returns all bytes before that.If
p
is true for all remaining bytes, it returns everything until end-of-file.It will return the empty string if there are no matching characters (and therefore never raises
End_of_file
).val take_while1 : (char -> bool) -> string parser
take_while1 p
is liketake_while
. However, the parser fails with "take_while1" if at least one character of input hasn't been consumed by the parser.val skip_while : (char -> bool) -> unit parser
skip_while p
skips zero or more bytes for whichp
istrue
.
skip_while p t
does the same thing asignore (take_while p t)
, except that it is not limited by the buffer size.val skip_while1 : (char -> bool) -> unit parser
skip_while1 p
is likeskip_while
. However, the parser fails with "skip_while1" if at least one character of input hasn't been skipped.val skip : int -> unit parser
skip n
discards the nextn
bytes.
skip n
=map ignore (take n)
, except that the number of skipped bytes may be larger than the buffer (it will not grow).Note: if
End_of_file
is raised, all bytes in the stream will have been consumed.val at_end_of_input : bool parser
at_end_of_input
returnstrue
when at the end of the stream, orfalse
if there is at least one more byte to be read.val end_of_input : unit parser
end_of_input
checks that there are no further bytes in the stream.Combinators
seq p
is a sequence that usesp
to get the next item.A sequence node can only be used while the stream is at the expected position, and will raise
Invalid_argument
if any bytes have been consumed in the meantime. This also means that each node can only be used once; useSeq
.memoize to make the sequence persistent.It is not necessary to consume all the elements of the sequence.
pair a b
is a parser that first usesa
to parse a valuex
, then usesb
to parse a valuey
, then returns(x, y)
.Note that this module does not support backtracking, so if
b
fails then the bytes consumed bya
are lost.val return : 'a -> 'a parser
return x
is a parser that consumes nothing and always returnsx
.return
is justFun.const
.
map f a
is a parser that parses the stream witha
to getv
, and then returnsf v
.
bind a f
is a parser that first usesa
to parse a valuev
, then usesf v
to select the next parser, and then uses that.
format_errors p
catchesFailure
,End_of_file
andBuffer_limit_exceeded
exceptions and returns them as a formatted error message.module Syntax : sig ... end
Convenient syntax for some of the combinators.
Low-level API
val buffered_bytes : t -> int
buffered_bytes t
is the number of bytes that can be read without reading from the underlying flow.val peek : t -> Cstruct.t
peek t
returns a view onto the active part oft
's internal buffer.Performing any operation that might add to the buffer may invalidate this, so it should be used immediately and then forgotten.
Cstruct.length (peek t) = buffered_bytes t
.val ensure : t -> int -> unit
ensure t n
ensures that the buffer contains at leastn
bytes of data.If not, it reads from the flow until there is.
buffered_bytes (ensure t n) >= n
.val consume : t -> int -> unit
val consumed_bytes : t -> int
consumed_bytes t
is the total number of bytes consumed.i.e. it is the offset into the stream of the next byte to be parsed.
\ No newline at end of file diff --git a/eio/Eio/Buf_write/BE/index.html b/eio/Eio/Buf_write/BE/index.html index 8b2a74b9e..4e73a195a 100644 --- a/eio/Eio/Buf_write/BE/index.html +++ b/eio/Eio/Buf_write/BE/index.html @@ -1,2 +1,2 @@ -val eof_seen : t -> bool
eof_seen t
indicates whether we've receivedEnd_of_file
from the underlying flow.If so, there will never be any further data beyond what
peek
already returns.Note that this returns
false
if we're at the end of the stream but don't know it yet. Useat_end_of_input
to be sure.BE (eio.Eio.Buf_write.BE) Module
Buf_write.BE
Big endian serializers
\ No newline at end of file +val uint16 : t -> int -> unit
uint16 t n
copies the lower 16 bits ofn
into the serializer's internal buffer in big-endian byte order.val uint32 : t -> int32 -> unit
uint32 t n
copiesn
into the serializer's internal buffer in big-endian byte order.val uint48 : t -> int64 -> unit
uint48 t n
copies the lower 48 bits ofn
into the serializer's internal buffer in big-endian byte order.val uint64 : t -> int64 -> unit
uint64 t n
copiesn
into the serializer's internal buffer in big-endian byte order.val float : t -> float -> unit
float t n
copies the lower 32 bits ofn
into the serializer's internal buffer in big-endian byte order.val double : t -> float -> unit
double t n
copiesn
into the serializer's internal buffer in big-endian byte order.BE (eio.Eio.Buf_write.BE) Module
Buf_write.BE
Big endian serializers
\ No newline at end of file diff --git a/eio/Eio/Buf_write/LE/index.html b/eio/Eio/Buf_write/LE/index.html index f0ea66db2..d5eebcead 100644 --- a/eio/Eio/Buf_write/LE/index.html +++ b/eio/Eio/Buf_write/LE/index.html @@ -1,2 +1,2 @@ -val uint16 : t -> int -> unit
uint16 t n
copies the lower 16 bits ofn
into the serializer's internal buffer in big-endian byte order.val uint32 : t -> int32 -> unit
uint32 t n
copiesn
into the serializer's internal buffer in big-endian byte order.val uint48 : t -> int64 -> unit
uint48 t n
copies the lower 48 bits ofn
into the serializer's internal buffer in big-endian byte order.val uint64 : t -> int64 -> unit
uint64 t n
copiesn
into the serializer's internal buffer in big-endian byte order.val float : t -> float -> unit
float t n
copies the lower 32 bits ofn
into the serializer's internal buffer in big-endian byte order.val double : t -> float -> unit
double t n
copiesn
into the serializer's internal buffer in big-endian byte order.LE (eio.Eio.Buf_write.LE) Module
Buf_write.LE
Little endian serializers
\ No newline at end of file +val uint16 : t -> int -> unit
uint16 t n
copies the lower 16 bits ofn
into the serializer's internal buffer in little-endian byte order.val uint32 : t -> int32 -> unit
uint32 t n
copiesn
into the serializer's internal buffer in little-endian byte order.val uint48 : t -> int64 -> unit
uint48 t n
copies the lower 48 bits ofn
into the serializer's internal buffer in little-endian byte order.val uint64 : t -> int64 -> unit
uint64 t n
copiesn
into the serializer's internal buffer in little-endian byte order.val float : t -> float -> unit
float t n
copies the lower 32 bits ofn
into the serializer's internal buffer in little-endian byte order.val double : t -> float -> unit
double t n
copiesn
into the serializer's internal buffer in little-endian byte order.LE (eio.Eio.Buf_write.LE) Module
Buf_write.LE
Little endian serializers
\ No newline at end of file diff --git a/eio/Eio/Buf_write/index.html b/eio/Eio/Buf_write/index.html index dfb9277b3..ed41cfb2d 100644 --- a/eio/Eio/Buf_write/index.html +++ b/eio/Eio/Buf_write/index.html @@ -1,5 +1,5 @@ -val uint16 : t -> int -> unit
uint16 t n
copies the lower 16 bits ofn
into the serializer's internal buffer in little-endian byte order.val uint32 : t -> int32 -> unit
uint32 t n
copiesn
into the serializer's internal buffer in little-endian byte order.val uint48 : t -> int64 -> unit
uint48 t n
copies the lower 48 bits ofn
into the serializer's internal buffer in little-endian byte order.val uint64 : t -> int64 -> unit
uint64 t n
copiesn
into the serializer's internal buffer in little-endian byte order.val float : t -> float -> unit
float t n
copies the lower 32 bits ofn
into the serializer's internal buffer in little-endian byte order.val double : t -> float -> unit
double t n
copiesn
into the serializer's internal buffer in little-endian byte order.Buf_write (eio.Eio.Buf_write) Module
Eio.Buf_write
Buffered output
Serialization primitives built for speed and memory-efficiency.
Buf_write is designed for writing fast and memory-efficient serializers. It is based on the Faraday library, but adapted for Eio. Its core type and related operation gives the user fine-grained control over copying and allocation behavior while serializing user-defined types, and presents the output in a form that makes it possible to use vectorized write operations, such as the
writev
system call, or any other platform or application-specific output APIs.A Buf_write serializer manages an internal buffer and a queue of output buffers. The output bufferes may be a sub range of the serializer's internal buffer or one that is user-provided. Buffered writes such as
string
,char
,cstruct
, etc., copy the source bytes into the serializer's internal buffer. Unbuffered writes are done withschedule_cstruct
, which performs no copying. Instead, it enqueues the source bytes into the serializer's write queue directly.Example:
module Write = Eio.Buf_write +
Buf_write (eio.Eio.Buf_write) Module
Eio.Buf_write
Buffered output
Serialization primitives built for speed and memory-efficiency.
Buf_write is designed for writing fast and memory-efficient serializers. It is based on the Faraday library, but adapted for Eio. Its core type and related operation gives the user fine-grained control over copying and allocation behavior while serializing user-defined types, and presents the output in a form that makes it possible to use vectorized write operations, such as the
writev
system call, or any other platform or application-specific output APIs.A Buf_write serializer manages an internal buffer and a queue of output buffers. The output bufferes may be a sub range of the serializer's internal buffer or one that is user-provided. Buffered writes such as
string
,char
,cstruct
, etc., copy the source bytes into the serializer's internal buffer. Unbuffered writes are done withschedule_cstruct
, which performs no copying. Instead, it enqueues the source bytes into the serializer's write queue directly.Example:
module Write = Eio.Buf_write let () = Eio_mock.Backend.run @@ fun () -> @@ -10,7 +10,7 @@ Eio.Fiber.yield (); Write.string w "baz"; )
This combines the first two writes, giving:
+stdout: wrote "foobar" -+stdout: wrote "baz"
Raised when waiting for a flush to complete if the buffer is destroyed instead.
Running
with_flow flow fn
runsfn writer
, wherewriter
is a buffer that flushes toflow
.Concurrently with
fn
, it also runs a fiber that copies fromwriter
toflow
. If this fiber runs out of data to copy then it will suspend itself. Writing towriter
will automatically schedule it to be resumed. This means that pending data is flushed automatically before the process sleeps.When
fn
returns,writer
is automatically closed and any remaining data is flushed beforewith_flow
itself returns.Buffered Writes
A serializer manages an internal buffer for coalescing small writes. The size of this buffer is determined when the serializer is created. If the buffer does not contain sufficient space to service a caller's buffered write, the serializer will allocate a new buffer of the sufficient size and use it for the current and subsequent writes. The old buffer will be garbage collected once all of its contents have been
flush
ed.val string : t -> ?off:int -> ?len:int -> string -> unit
string t ?off ?len str
copiesstr
into the serializer's internal buffer.val bytes : t -> ?off:int -> ?len:int -> Stdlib.Bytes.t -> unit
bytes t ?off ?len bytes
copiesbytes
into the serializer's internal buffer. It is safe to modifybytes
after this call returns.val cstruct : t -> Cstruct.t -> unit
cstruct t cs
copiescs
into the serializer's internal buffer. It is safe to modifycs
after this call returns. For large cstructs, it may be more efficient to useschedule_cstruct
.val write_gen : ++stdout: wrote "baz"
\ No newline at end of file diff --git a/eio/Eio/Domain_manager/Pi/index.html b/eio/Eio/Domain_manager/Pi/index.html new file mode 100644 index 000000000..e202b92a9 --- /dev/null +++ b/eio/Eio/Domain_manager/Pi/index.html @@ -0,0 +1,2 @@ + +Raised when waiting for a flush to complete if the buffer is destroyed instead.
Running
with_flow flow fn
runsfn writer
, wherewriter
is a buffer that flushes toflow
.Concurrently with
fn
, it also runs a fiber that copies fromwriter
toflow
. If this fiber runs out of data to copy then it will suspend itself. Writing towriter
will automatically schedule it to be resumed. This means that pending data is flushed automatically before the process sleeps.When
fn
returns,writer
is automatically closed and any remaining data is flushed beforewith_flow
itself returns.Buffered Writes
A serializer manages an internal buffer for coalescing small writes. The size of this buffer is determined when the serializer is created. If the buffer does not contain sufficient space to service a caller's buffered write, the serializer will allocate a new buffer of the sufficient size and use it for the current and subsequent writes. The old buffer will be garbage collected once all of its contents have been
flush
ed.val string : t -> ?off:int -> ?len:int -> string -> unit
string t ?off ?len str
copiesstr
into the serializer's internal buffer.val bytes : t -> ?off:int -> ?len:int -> Stdlib.Bytes.t -> unit
bytes t ?off ?len bytes
copiesbytes
into the serializer's internal buffer. It is safe to modifybytes
after this call returns.val cstruct : t -> Cstruct.t -> unit
cstruct t cs
copiescs
into the serializer's internal buffer. It is safe to modifycs
after this call returns. For large cstructs, it may be more efficient to useschedule_cstruct
.val write_gen : t -> blit:('a -> src_off:int -> Cstruct.buffer -> dst_off:int -> len:int -> unit) -> off:int -> diff --git a/eio/Eio/Cancel/index.html b/eio/Eio/Cancel/index.html index 412003e9b..24486832e 100644 --- a/eio/Eio/Cancel/index.html +++ b/eio/Eio/Cancel/index.html @@ -1,2 +1,2 @@ -
Cancel (eio.Eio.Cancel) Module
Eio.Cancel
Cancelling fibers.
This is the low-level interface to cancellation. Every
Switch
includes a cancellation context and most users will just use that API instead.Each domain has a tree of cancellation contexts, and every fiber is registered with one context. A fiber can switch to a different context (e.g. by calling
sub
). When a context is cancelled, all registered fibers have their current cancellation function (if any) called and removed. Child contexts are cancelled too, recursively, unless marked as protected.Many operations also check that the current context hasn't been cancelled, so if a fiber is performing a non-cancellable operation it will still get cancelled soon afterwards. This check is typically done when starting an operation, not at the end. If an operation is cancelled after succeeding, but while still waiting on the run queue, it will still return the operation's result. A notable exception is
Fiber.yield
, which checks at the end. You can also useFiber.check
to check manually.Whether a fiber is cancelled through a cancellation function or by checking its context, it will receive a
Cancelled
exception. It is possible the exception will get lost (if something catches it and forgets to re-raise). It is also possible to get this exception even when not cancelled, for example by awaiting a promise which another fiber has resolved to a cancelled exception. When in doubt, useFiber.check ()
to find out if your fiber is really cancelled. Ideally this should be done any time you have caught an exception and are planning to ignore it, although if you forget then the next IO operation will typically abort anyway.When handling a
Cancelled
exception, quick clean-up actions (such as releasing a mutex or deleting a temporary file) are OK, but operations that may block should be avoided. For example, a network connection should simply be closed, without attempting to send a goodbye message.The purpose of the cancellation system is to stop fibers quickly, not to report errors. Use
Switch.fail
instead to record an error.\ No newline at end of file +
Cancelled ex
indicates that the context was cancelled with exceptionex
. It is usually not necessary to report aCancelled
exception to the user, as the original problem will be handled elsewhere.The nested exception is only intended for debug-level logging and should generally be ignored.
Raised by
cancel
if any of the cancellation hooks themselves fail.val sub : (t -> 'a) -> 'a
sub fn
installs a new cancellation contextt
, runsfn t
inside it, and then restores the old context.If the old context is cancelled while
fn
is running thent
is cancelled too.t
cannot be used aftersub
returns.
protect fn
runsfn
in a new cancellation context that isn't cancelled when its parent is.This can be used to clean up resources on cancellation. However, it is usually better to use
Switch.on_release
(which calls this for you).Note that
protect
does not check its parent context when it finishes.val check : t -> unit
check t
checks thatt
hasn't been cancelled.val get_error : t -> exn option
get_error t
is likecheck t
except that it returns the exception instead of raising it.If
t
is finished, this returns (rather than raising) theInvalid_argument
exception too.val cancel : t -> exn -> unit
cancel t ex
markst
and its child contexts as cancelled, recursively, and calls all registered fibers' cancellation functions, passingCancelled ex
as the argument.All cancellation functions are run, even if some of them raise exceptions.
If
t
is already cancelled then this does nothing.Note that the caller of this function is still responsible for handling the error somehow (e.g. reporting it to the user); it does not become the responsibility of the cancelled thread(s).
val dump : t Fmt.t
Show the cancellation sub-tree rooted at
t
, for debugging.Cancel (eio.Eio.Cancel) Module
Eio.Cancel
Cancelling fibers.
This is the low-level interface to cancellation. Every
Switch
includes a cancellation context and most users will just use that API instead.Each domain has a tree of cancellation contexts, and every fiber is registered with one context. A fiber can switch to a different context (e.g. by calling
sub
). When a context is cancelled, all registered fibers have their current cancellation function (if any) called and removed. Child contexts are cancelled too, recursively, unless marked as protected.Many operations also check that the current context hasn't been cancelled, so if a fiber is performing a non-cancellable operation it will still get cancelled soon afterwards. This check is typically done when starting an operation, not at the end. If an operation is cancelled after succeeding, but while still waiting on the run queue, it will still return the operation's result. A notable exception is
Fiber.yield
, which checks at the end. You can also useFiber.check
to check manually.Whether a fiber is cancelled through a cancellation function or by checking its context, it will receive a
Cancelled
exception. It is possible the exception will get lost (if something catches it and forgets to re-raise). It is also possible to get this exception even when not cancelled, for example by awaiting a promise which another fiber has resolved to a cancelled exception. When in doubt, useFiber.check ()
to find out if your fiber is really cancelled. Ideally this should be done any time you have caught an exception and are planning to ignore it, although if you forget then the next IO operation will typically abort anyway.When handling a
Cancelled
exception, quick clean-up actions (such as releasing a mutex or deleting a temporary file) are OK, but operations that may block should be avoided. For example, a network connection should simply be closed, without attempting to send a goodbye message.The purpose of the cancellation system is to stop fibers quickly, not to report errors. Use
Switch.fail
instead to record an error.\ No newline at end of file diff --git a/eio/Eio/Condition/index.html b/eio/Eio/Condition/index.html index 3909b49ce..b7641fb4a 100644 --- a/eio/Eio/Condition/index.html +++ b/eio/Eio/Condition/index.html @@ -1,5 +1,5 @@ -
Cancelled ex
indicates that the context was cancelled with exceptionex
. It is usually not necessary to report aCancelled
exception to the user, as the original problem will be handled elsewhere.The nested exception is only intended for debug-level logging and should generally be ignored.
Raised by
cancel
if any of the cancellation hooks themselves fail.val sub : (t -> 'a) -> 'a
sub fn
installs a new cancellation contextt
, runsfn t
inside it, and then restores the old context.If the old context is cancelled while
fn
is running thent
is cancelled too.t
cannot be used aftersub
returns.
protect fn
runsfn
in a new cancellation context that isn't cancelled when its parent is.This can be used to clean up resources on cancellation. However, it is usually better to use
Switch.on_release
(which calls this for you).Note that
protect
does not check its parent context when it finishes.val check : t -> unit
check t
checks thatt
hasn't been cancelled.val get_error : t -> exn option
get_error t
is likecheck t
except that it returns the exception instead of raising it.If
t
is finished, this returns (rather than raising) theInvalid_argument
exception too.val cancel : t -> exn -> unit
cancel t ex
markst
and its child contexts as cancelled, recursively, and calls all registered fibers' cancellation functions, passingCancelled ex
as the argument.All cancellation functions are run, even if some of them raise exceptions.
If
t
is already cancelled then this does nothing.Note that the caller of this function is still responsible for handling the error somehow (e.g. reporting it to the user); it does not become the responsibility of the cancelled thread(s).
val dump : t Fmt.t
Show the cancellation sub-tree rooted at
t
, for debugging.Condition (eio.Eio.Condition) Module
Eio.Condition
Waiting for a condition to become true.
Waiters call
await
in a loop as long as some condition is false. Fibers that modify inputs to the condition must callbroadcast
soon afterwards so that waiters can re-check the condition.Example:
let x = ref 0 +
Condition (eio.Eio.Condition) Module
Eio.Condition
Waiting for a condition to become true.
Waiters call
await
in a loop as long as some condition is false. Fibers that modify inputs to the condition must callbroadcast
soon afterwards so that waiters can re-check the condition.Example:
let x = ref 0 let cond = Eio.Condition.create () let mutex = Eio.Mutex.create () diff --git a/eio/Eio/Debug/index.html b/eio/Eio/Debug/index.html index f7420ca4b..720fbc599 100644 --- a/eio/Eio/Debug/index.html +++ b/eio/Eio/Debug/index.html @@ -1,5 +1,5 @@ -
Debug (eio.Eio.Debug) Module
Eio.Debug
Control over debugging.
Example:
open Eio.Std +
Debug (eio.Eio.Debug) Module
Eio.Debug
Control over debugging.
Example:
open Eio.Std let my_traceln = { Eio.Debug.traceln = fun ?__POS__:_ fmt -> Fmt.epr ("[custom-trace] " ^^ fmt ^^ "@.") @@ -11,4 +11,4 @@ Fiber.with_binding debug#traceln my_traceln @@ fun () -> traceln "Traced with custom function"
This will output:
[custom-trace] Traced with custom function
\ No newline at end of file + 'a;type traceln = Private.Debug.traceln = {
traceln : 'a. ?__POS__:(string * int * int * int) -> ('a, Stdlib.Format.formatter, unit, unit) Stdlib.format4 -> - 'a;
}
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.
Fiber keys used to control debugging. Use
Stdenv.debug
to get this.}
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.
with_trace_prefix fmt fn
runsfn ()
with a traceln that outputsfmt
before each message.Fiber keys used to control debugging. Use
Stdenv.debug
to get this.Pi (eio.Eio.Domain_manager.Pi) \ No newline at end of file diff --git a/eio/Eio/Domain_manager/Pi/module-type-MGR/index.html b/eio/Eio/Domain_manager/Pi/module-type-MGR/index.html new file mode 100644 index 000000000..8d34a3fce --- /dev/null +++ b/eio/Eio/Domain_manager/Pi/module-type-MGR/index.html @@ -0,0 +1,2 @@ + + Module
Domain_manager.Pi
MGR (eio.Eio.Domain_manager.Pi.MGR) Module type
Pi.MGR
\ No newline at end of file diff --git a/eio/Eio/Domain_manager/class-t/index.html b/eio/Eio/Domain_manager/class-t/index.html deleted file mode 100644 index 8f05bf444..000000000 --- a/eio/Eio/Domain_manager/class-t/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -
run t fn
runsfn ~cancelled
in a new domain.If the calling fiber is cancelled,
cancelled
becomes resolved to theCancel.Cancelled
exception.fn
should cancel itself in this case.val run_raw : t -> (unit -> 'a) -> 'a
t (eio.Eio.Domain_manager.t) Class
Domain_manager.t
\ No newline at end of file diff --git a/eio/Eio/Domain_manager/index.html b/eio/Eio/Domain_manager/index.html index b2a61602f..99188dc26 100644 --- a/eio/Eio/Domain_manager/index.html +++ b/eio/Eio/Domain_manager/index.html @@ -1,2 +1,2 @@ -method virtual run : 'a. (cancelled:exn Promise.t -> 'a) -> 'a
t#run fn
runsfn ~cancelled
in a new domain.If the calling fiber is cancelled,
cancelled
becomes resolved to theCancel
.Cancelled exception.fn
should cancel itself in this case.Domain_manager (eio.Eio.Domain_manager) Module
Eio.Domain_manager
Parallel computation across multiple CPU cores.
\ No newline at end of file +class virtual t : object ... end
val run : t -> (unit -> 'a) -> 'a
run t f
runsf ()
in a newly-created domain and returns the result.Other fibers in the calling domain can run in parallel with the new domain.
Warning:
f
must only access thread-safe values from the calling domain, but this is not enforced by the type system.If the calling fiber is cancelled, this is propagated to the spawned domain.
Domain_manager (eio.Eio.Domain_manager) Module
Eio.Domain_manager
Parallel computation across multiple CPU cores.
\ No newline at end of file diff --git a/eio/Eio/Exn/Backend/index.html b/eio/Eio/Exn/Backend/index.html index 68e1404f2..e6cdfdd4e 100644 --- a/eio/Eio/Exn/Backend/index.html +++ b/eio/Eio/Exn/Backend/index.html @@ -1,2 +1,2 @@ -type 'a t = [> ty ] as 'a Resource.t
val run : _ t -> (unit -> 'a) -> 'a
run t f
runsf ()
in a newly-created domain and returns the result.Other fibers in the calling domain can run in parallel with the new domain.
Warning:
f
must only access thread-safe values from the calling domain, but this is not enforced by the type system.If the calling fiber is cancelled, this is propagated to the spawned domain.
val run_raw : _ t -> (unit -> 'a) -> 'a
run_raw t f
is likerun
, but does not run an event loop in the new domain, and so cannot perform IO, fork fibers, etc.Provider Interface
module Pi : sig ... end
Backend (eio.Eio.Exn.Backend) Module
Exn.Backend
Extensible backend-specific exceptions.
\ No newline at end of file +Controls the behaviour of
pp
.val register_pp : (Stdlib.Format.formatter -> t -> bool) -> unit
register_pp pp
addspp
as a pretty-printer of backend errors.
pp f err
should formaterr
usingf
, if possible. It should returntrue
on success, orfalse
if it didn't recogniseerr
.val pp : t Fmt.t
Backend (eio.Eio.Exn.Backend) Module
Exn.Backend
Extensible backend-specific exceptions.
\ No newline at end of file diff --git a/eio/Eio/Exn/index.html b/eio/Eio/Exn/index.html index a89738db2..3041f0578 100644 --- a/eio/Eio/Exn/index.html +++ b/eio/Eio/Exn/index.html @@ -1,5 +1,5 @@ -Controls the behaviour of
pp
.val register_pp : (Stdlib.Format.formatter -> t -> bool) -> unit
register_pp pp
addspp
as a pretty-printer of backend errors.
pp f err
should formaterr
usingf
, if possible. It should returntrue
on success, orfalse
if it didn't recogniseerr
.val pp : t Fmt.t
Exn (eio.Eio.Exn) Module
Eio.Exn
Eio exceptions.
Describes the particular error that occurred.
They are typically nested (e.g.
Fs (Permission_denied (Unix_error ...))
) so that you can match e.g. all IO errors, all file-system errors, all permission denied errors, etc.If you extend this, use
register_pp
to add a printer for the new error.Extra information attached to an IO error. This provides contextual information about what caused the error.
A general purpose IO exception.
This is used for most errors interacting with the outside world, and is similar to
Unix
.Unix_error, but more general. An unknownIo
error should typically be reported to the user, but does not generally indicate a bug in the program.val add_context : +
Exn (eio.Eio.Exn) Module
Eio.Exn
Eio exceptions.
Describes the particular error that occurred.
They are typically nested (e.g.
Fs (Permission_denied (Unix_error ...))
) so that you can match e.g. all IO errors, all file-system errors, all permission denied errors, etc.If you extend this, use
register_pp
to add a printer for the new error.Extra information attached to an IO error. This provides contextual information about what caused the error.
A general purpose IO exception.
This is used for most errors interacting with the outside world, and is similar to
Unix
.Unix_error, but more general. An unknownIo
error should typically be reported to the user, but does not generally indicate a bug in the program.
add_context ex msg
returns a new exception withmsg
added toex
's context, ifex
is anIo
exception.If
ex
is not anIo
exception, this function just returns the original exception.val reraise_with_context : diff --git a/eio/Eio/Fiber/List/index.html b/eio/Eio/Fiber/List/index.html index 3ee0b7563..52e2957b1 100644 --- a/eio/Eio/Fiber/List/index.html +++ b/eio/Eio/Fiber/List/index.html @@ -1,2 +1,2 @@ -
List (eio.Eio.Fiber.List) Module
Fiber.List
Concurrent list operations.
These functions behave like the ones in the standard library's
List
module, except that multiple items can be processed concurrently.They correspond to Lwt's
Lwt_list.*_p
operations. e.g.Lwt_list.iter_p
becomesFiber.List.iter
. For theLwt_list.*_s
operations, just use the standard library function. e.g.Lwt_list.iter_s
can be replaced by a plainList.iter
.\ No newline at end of file +
filter f x
is likeList.filter f x
except that the invocations off
are run concurrently in separate fibers.
map f x
is likeList.map f x
except that the invocations off
are run concurrently in separate fibers.
filter_map f x
is likeList.filter_map f x
except that the invocations off
are run concurrently in separate fibers.List (eio.Eio.Fiber.List) Module
Fiber.List
Concurrent list operations.
These functions behave like the ones in the standard library's
List
module, except that multiple items can be processed concurrently.They correspond to Lwt's
Lwt_list.*_p
operations. e.g.Lwt_list.iter_p
becomesFiber.List.iter
. For theLwt_list.*_s
operations, just use the standard library function. e.g.Lwt_list.iter_s
can be replaced by a plainList.iter
.\ No newline at end of file diff --git a/eio/Eio/Fiber/index.html b/eio/Eio/Fiber/index.html index ec0982057..4707401b9 100644 --- a/eio/Eio/Fiber/index.html +++ b/eio/Eio/Fiber/index.html @@ -1,9 +1,9 @@ -
filter f x
is likeList.filter f x
except that the invocations off
are run concurrently in separate fibers.
map f x
is likeList.map f x
except that the invocations off
are run concurrently in separate fibers.
filter_map f x
is likeList.filter_map f x
except that the invocations off
are run concurrently in separate fibers.Fiber (eio.Eio.Fiber) Module
Eio.Fiber
A fiber is a light-weight thread.
Within a domain, only one fiber can be running at a time. A fiber runs until it performs an IO operation (directly or indirectly). At that point, it may be suspended and the next fiber on the run queue runs.
\ No newline at end of file diff --git a/eio/Eio/File/Pi/index.html b/eio/Eio/File/Pi/index.html new file mode 100644 index 000000000..e5cd87b1d --- /dev/null +++ b/eio/Eio/File/Pi/index.html @@ -0,0 +1,2 @@ + +
both f g
runsf ()
andg ()
concurrently.They run in a new cancellation sub-context, and if either raises an exception, the other is cancelled.
both
waits for both functions to finish even if one raises (it will then re-raise the original exception).
f
runs immediately, without switching to any other thread.g
is inserted at the head of the run-queue, so it runs next even if other threads are already enqueued. You can get other scheduling orders by adding calls toyield
in various places. e.g. to append both fibers to the end of the run-queue, yield immediately before callingboth
.If both fibers fail,
Exn.combine
is used to combine the exceptions.
pair f g
is likeboth
, but returns the two results.
all fs
is likeboth
, but for any number of fibers.all []
returns immediately.
first f g
runsf ()
andg ()
concurrently.They run in a new cancellation sub-context, and when one finishes the other is cancelled. If one raises, the other is cancelled and the exception is reported.
As with
both
,f
runs immediately andg
is scheduled next, ahead of any other queued work.If both fibers fail,
Exn.combine
is used to combine the exceptions.Warning: it is always possible that both operations will succeed (and one result will be thrown away). This is because there is a period of time after the first operation succeeds, but before its fiber finishes, during which the other operation may also succeed.
any fs
is likefirst
, but for any number of fibers.
any []
just waits forever (or until cancelled).val fork : sw:Switch.t -> (unit -> unit) -> unit
fork ~sw fn
runsfn ()
in a new fiber, but does not wait for it to complete.The new fiber is attached to
sw
(which can't finish until the fiber ends).The new fiber inherits
sw
's cancellation context. If the fiber raises an exception,Switch.fail sw
is called. Ifsw
is already off thenfn
fails immediately, but the calling thread continues.
fn
runs immediately, without switching to any other fiber first. The calling fiber is placed at the head of the run queue, ahead of any previous items.val fork_promise : sw:Switch.t -> (unit -> 'a) -> 'a Promise.or_exn
fork_promise ~sw fn
schedulesfn ()
to run in a new fiber and returns a promise for its result.This is just a convenience wrapper around
fork
. Iffn
raises an exception then the promise is resolved to the error, butsw
is not failed.val fork_seq : sw:Switch.t -> (('a -> unit) -> unit) -> 'a Stdlib.Seq.t
fork_seq ~sw fn
creates (but does not start) a new fiber to runfn yield
.Requesting the next item from the returned sequence resumes the fiber until it calls
yield x
, usingx
value as the next item in the sequence. Iffn
returns without producing a value then the result isSeq
.Nil (end-of-sequence).The returned sequence can be consumed safely from another domain.
fn
itself always runs in the domain that calledfork_seq
.Example:
Switch.run @@ fun sw -> +
Fiber (eio.Eio.Fiber) Module
Eio.Fiber
A fiber is a light-weight thread.
Within a domain, only one fiber can be running at a time. A fiber runs until it performs an IO operation (directly or indirectly). At that point, it may be suspended and the next fiber on the run queue runs.
\ No newline at end of file +Seq.iter (traceln "Got: %d") seq
both f g
runsf ()
andg ()
concurrently.They run in a new cancellation sub-context, and if either raises an exception, the other is cancelled.
both
waits for both functions to finish even if one raises (it will then re-raise the original exception).
f
runs immediately, without switching to any other thread.g
is inserted at the head of the run-queue, so it runs next even if other threads are already enqueued. You can get other scheduling orders by adding calls toyield
in various places. e.g. to append both fibers to the end of the run-queue, yield immediately before callingboth
.If both fibers fail,
Exn.combine
is used to combine the exceptions.
pair f g
is likeboth
, but returns the two results.
all fs
is likeboth
, but for any number of fibers.all []
returns immediately.
first f g
runsf ()
andg ()
concurrently.They run in a new cancellation sub-context, and when one finishes the other is cancelled. If one raises, the other is cancelled and the exception is reported.
As with
both
,f
runs immediately andg
is scheduled next, ahead of any other queued work.If both fibers fail,
Exn.combine
is used to combine the exceptions.Warning: it is always possible that both operations will succeed (and one result will be thrown away). This is because there is a period of time after the first operation succeeds, but before its fiber finishes, during which the other operation may also succeed.
any fs
is likefirst
, but for any number of fibers.
any []
just waits forever (or until cancelled).val fork : sw:Switch.t -> (unit -> unit) -> unit
fork ~sw fn
runsfn ()
in a new fiber, but does not wait for it to complete.The new fiber is attached to
sw
(which can't finish until the fiber ends).The new fiber inherits
sw
's cancellation context. If the fiber raises an exception,Switch.fail sw
is called. Ifsw
is already off thenfn
fails immediately, but the calling thread continues.
fn
runs immediately, without switching to any other fiber first. The calling fiber is placed at the head of the run queue, ahead of any previous items.val fork_promise : sw:Switch.t -> (unit -> 'a) -> 'a Promise.or_exn
fork_promise ~sw fn
schedulesfn ()
to run in a new fiber and returns a promise for its result.This is just a convenience wrapper around
fork
. Iffn
raises an exception then the promise is resolved to the error, butsw
is not failed.val fork_seq : sw:Switch.t -> (('a -> unit) -> unit) -> 'a Stdlib.Seq.t
fork_seq ~sw fn
creates (but does not start) a new fiber to runfn yield
.Requesting the next item from the returned sequence resumes the fiber until it calls
yield x
, usingx
value as the next item in the sequence. Iffn
returns without producing a value then the result isSeq
.Nil (end-of-sequence).The returned sequence can be consumed safely from another domain.
fn
itself always runs in the domain that calledfork_seq
.Example:
Switch.run @@ fun sw -> let seq = Fiber.fork_seq ~sw (fun yield -> for i = 1 to 3 do traceln "Yielding %d" i; yield i done ) in -Seq.iter (traceln "Got: %d") seq
If
fn
raises an exception then the consumer receives it. If the consumer cancels while awaiting a value, the producer is cancelled when it next callsyield
. It is an error to request two items at once, or to request items out of sequence.val fork_daemon : sw:Switch.t -> (unit -> [ `Stop_daemon ]) -> unit
fork_daemon
is likefork
except that instead of waiting for the fiber to finish, the switch will cancel it once all non-daemon fibers are done.The switch will still wait for the daemon fiber to finish cancelling.
The return type of
[`Stop_daemon]
instead ofunit
is just to catch mistakes, as daemons normally aren't expected to return.
check ()
checks that the fiber's context hasn't been cancelled. Many operations automatically check this before starting.
yield ()
asks the scheduler to switch to the next runnable task. The current task remains runnable, but goes to the back of the queue. Automatically callscheck
just before resuming.module List : sig ... end
Concurrent list operations.
Fiber-local variables
Each fiber maintains a map of additional variables associated with it, which can be used to store fiber-related state or context. This map is propagated to any forked fibers.
While fiber-local variables can be useful, they can also make code much harder to reason about, as they effectively act as another form of global state. When possible, prefer passing arguments around explicitly.
Fiber-local variables are particularly useful for attaching extra information for debugging, such as a request ID that the log system can include in all logged messages.
'a key
is a fiber-local variable of type'a
.Since the key is required to get or set a variable, a library can keep its key private to control how the variable can be accessed.
val create_key : unit -> 'a key
create_key ()
creates a new fiber-local variable.val get : 'a key -> 'a option
get key
readskey
from the map of fiber local variables, returning its value orNone
if it has not been bound.val with_binding : 'a key -> 'a -> (unit -> 'b) -> 'b
with_binding key value fn
runsfn
withkey
bound to the providedvalue
.Whilst this binding only exists for the duration of this function on this fiber, it will be propagated to any forked fibers. If
fn
creates fibers using an external switch, the bound value may be continue to be used after this function returns.val without_binding : 'a key -> (unit -> 'b) -> 'b
with_binding key value fn
runsfn
with any binding forkey
removed.If
fn
raises an exception then the consumer receives it. If the consumer cancels while awaiting a value, the producer is cancelled when it next callsyield
. It is an error to request two items at once, or to request items out of sequence.val fork_daemon : sw:Switch.t -> (unit -> [ `Stop_daemon ]) -> unit
fork_daemon
is likefork
except that instead of waiting for the fiber to finish, the switch will cancel it once all non-daemon fibers are done.The switch will still wait for the daemon fiber to finish cancelling.
The return type of
[`Stop_daemon]
instead ofunit
is just to catch mistakes, as daemons normally aren't expected to return.
check ()
checks that the fiber's context hasn't been cancelled. Many operations automatically check this before starting.
is_cancelled ()
istrue
iffcheck
would raise an exception.
yield ()
asks the scheduler to switch to the next runnable task. The current task remains runnable, but goes to the back of the queue. Automatically callscheck
just before resuming.module List : sig ... end
Concurrent list operations.
Fiber-local variables
Each fiber maintains a map of additional variables associated with it, which can be used to store fiber-related state or context. This map is propagated to any forked fibers.
While fiber-local variables can be useful, they can also make code much harder to reason about, as they effectively act as another form of global state. When possible, prefer passing arguments around explicitly.
Fiber-local variables are particularly useful for attaching extra information for debugging, such as a request ID that the log system can include in all logged messages.
'a key
is a fiber-local variable of type'a
.Since the key is required to get or set a variable, a library can keep its key private to control how the variable can be accessed.
val create_key : unit -> 'a key
create_key ()
creates a new fiber-local variable.val get : 'a key -> 'a option
get key
readskey
from the map of fiber local variables, returning its value orNone
if it has not been bound.val with_binding : 'a key -> 'a -> (unit -> 'b) -> 'b
with_binding key value fn
runsfn
withkey
bound to the providedvalue
.Whilst this binding only exists for the duration of this function on this fiber, it will be propagated to any forked fibers. If
fn
creates fibers using an external switch, the bound value may be continue to be used after this function returns.val without_binding : 'a key -> (unit -> 'b) -> 'b
with_binding key value fn
runsfn
with any binding forkey
removed.Pi (eio.Eio.File.Pi) Module
File.Pi
\ No newline at end of file diff --git a/eio/Eio/File/Pi/module-type-READ/index.html b/eio/Eio/File/Pi/module-type-READ/index.html new file mode 100644 index 000000000..34c6445d5 --- /dev/null +++ b/eio/Eio/File/Pi/module-type-READ/index.html @@ -0,0 +1,2 @@ + +module type READ = sig ... end
module type WRITE = sig ... end
type Resource.pi +=
| Read : ('t, (module READ with type t = 't), [> ro_ty ]) Resource.pi
| Write : ('t, (module WRITE with type t = 't), [> rw_ty ]) Resource.pi
val ro : (module READ with type t = 't) -> ('t, ro_ty) Resource.handler
val rw : (module WRITE with type t = 't) -> ('t, rw_ty) Resource.handler
READ (eio.Eio.File.Pi.READ) Module type
Pi.READ
\ No newline at end of file diff --git a/eio/Eio/File/Pi/module-type-WRITE/index.html b/eio/Eio/File/Pi/module-type-WRITE/index.html new file mode 100644 index 000000000..406d6fa00 --- /dev/null +++ b/eio/Eio/File/Pi/module-type-WRITE/index.html @@ -0,0 +1,2 @@ + +
include Flow.Pi.SOURCE
val read_methods : t Flow.read_method list
val single_read : t -> Cstruct.t -> int
val pread : t -> file_offset:Optint.Int63.t -> Cstruct.t list -> int
val close : t -> unit
WRITE (eio.Eio.File.Pi.WRITE) Module type
Pi.WRITE
\ No newline at end of file diff --git a/eio/Eio/File/Stat/index.html b/eio/Eio/File/Stat/index.html index 979c93ffc..9b20e7f26 100644 --- a/eio/Eio/File/Stat/index.html +++ b/eio/Eio/File/Stat/index.html @@ -1,2 +1,2 @@ -
include Flow.Pi.SINK
val single_write : t -> Cstruct.t list -> int
val copy : t -> src:_ Flow.source -> unit
copy t ~src
allows for optimising copy operations.If you have no optimisations, you can use
simple_copy
to implement this usingsingle_write
.val pwrite : t -> file_offset:Optint.Int63.t -> Cstruct.t list -> int
Stat (eio.Eio.File.Stat) Module
File.Stat
Portable file stats.
\ No newline at end of file +type kind = [
|
`Unknown
|
`Fifo
|
`Character_special
|
`Directory
|
`Block_device
|
`Regular_file
|
`Symbolic_link
|
`Socket
]
Kind of file from st_mode. *
type t = {
dev : Stdlib.Int64.t;
ino : Stdlib.Int64.t;
kind : kind;
perm : Unix_perm.t;
nlink : Stdlib.Int64.t;
uid : Stdlib.Int64.t;
gid : Stdlib.Int64.t;
rdev : Stdlib.Int64.t;
size : Optint.Int63.t;
atime : float;
mtime : float;
ctime : float;
}
Like stat(2).
Stat (eio.Eio.File.Stat) Module
File.Stat
Portable file stats.
\ No newline at end of file diff --git a/eio/Eio/File/Unix_perm/index.html b/eio/Eio/File/Unix_perm/index.html index 555204145..f0bf01615 100644 --- a/eio/Eio/File/Unix_perm/index.html +++ b/eio/Eio/File/Unix_perm/index.html @@ -1,2 +1,2 @@ -type kind = [
|
`Unknown
|
`Fifo
|
`Character_special
|
`Directory
|
`Block_device
|
`Regular_file
|
`Symbolic_link
|
`Socket
]
Kind of file from st_mode. *
type t = {
dev : Stdlib.Int64.t;
ino : Stdlib.Int64.t;
kind : kind;
perm : Unix_perm.t;
nlink : Stdlib.Int64.t;
uid : Stdlib.Int64.t;
gid : Stdlib.Int64.t;
rdev : Stdlib.Int64.t;
size : Optint.Int63.t;
atime : float;
mtime : float;
ctime : float;
}
Like stat(2).
Unix_perm (eio.Eio.File.Unix_perm) \ No newline at end of file + Module
File.Unix_perm
Tranditional Unix permissions.
Unix_perm (eio.Eio.File.Unix_perm) \ No newline at end of file diff --git a/eio/Eio/File/class-ro/index.html b/eio/Eio/File/class-ro/index.html deleted file mode 100644 index 39f150b14..000000000 --- a/eio/Eio/File/class-ro/index.html +++ /dev/null @@ -1,2 +0,0 @@ - - Module
File.Unix_perm
Tranditional Unix permissions.
ro (eio.Eio.File.ro) \ No newline at end of file diff --git a/eio/Eio/File/class-rw/index.html b/eio/Eio/File/class-rw/index.html deleted file mode 100644 index 8b377d9f4..000000000 --- a/eio/Eio/File/class-rw/index.html +++ /dev/null @@ -1,2 +0,0 @@ - - Class
File.ro
A file opened for reading.
rw (eio.Eio.File.rw) Class
File.rw
A file opened for reading and writing.
\ No newline at end of file diff --git a/eio/Eio/File/index.html b/eio/Eio/File/index.html index c8274a9dd..c6961b86c 100644 --- a/eio/Eio/File/index.html +++ b/eio/Eio/File/index.html @@ -1,2 +1,2 @@ -inherit ro
File (eio.Eio.File) Module
Eio.File
Operations on open files.
\ No newline at end of file +module Unix_perm : sig ... end
Tranditional Unix permissions.
module Stat : sig ... end
Portable file stats.
class virtual ro : object ... end
A file opened for reading.
class virtual rw : object ... end
A file opened for reading and writing.
val size : ro -> Optint.Int63.t
size t
returns the size oft
.val pread : ro -> file_offset:Optint.Int63.t -> Cstruct.t list -> int
pread t ~file_offset bufs
performs a single read oft
atfile_offset
intobufs
.It returns the number of bytes read, which may be less than the space in
bufs
, even if more bytes are available. Usepread_exact
instead if you require the buffer to be filled.To read at the current offset, use
Flow.single_read
instead.val pread_exact : ro -> file_offset:Optint.Int63.t -> Cstruct.t list -> unit
pread_exact t ~file_offset bufs
reads fromt
intobufs
untilbufs
is full.val pwrite_single : rw -> file_offset:Optint.Int63.t -> Cstruct.t list -> int
pwrite_single t ~file_offset bufs
performs a single write operation, writing data frombufs
to locationfile_offset
int
.It returns the number of bytes written, which may be less than the length of
bufs
. In most cases, you will want to usepwrite_all
instead.val pwrite_all : rw -> file_offset:Optint.Int63.t -> Cstruct.t list -> unit
pwrite_all t ~file_offset bufs
writes all the data inbufs
to locationfile_offset
int
.File (eio.Eio.File) Module
Eio.File
Operations on open files.
\ No newline at end of file diff --git a/eio/Eio/Flow/Pi/index.html b/eio/Eio/Flow/Pi/index.html new file mode 100644 index 000000000..164003273 --- /dev/null +++ b/eio/Eio/Flow/Pi/index.html @@ -0,0 +1,13 @@ + +module Unix_perm : sig ... end
Tranditional Unix permissions.
module Stat : sig ... end
Portable file stats.
module Pi : sig ... end
val size : _ ro -> Optint.Int63.t
size t
returns the size oft
.val pread : _ ro -> file_offset:Optint.Int63.t -> Cstruct.t list -> int
pread t ~file_offset bufs
performs a single read oft
atfile_offset
intobufs
.It returns the number of bytes read, which may be less than the space in
bufs
, even if more bytes are available. Usepread_exact
instead if you require the buffer to be filled.To read at the current offset, use
Flow.single_read
instead.val pread_exact : _ ro -> file_offset:Optint.Int63.t -> Cstruct.t list -> unit
pread_exact t ~file_offset bufs
reads fromt
intobufs
untilbufs
is full.val pwrite_single : _ rw -> file_offset:Optint.Int63.t -> Cstruct.t list -> int
pwrite_single t ~file_offset bufs
performs a single write operation, writing data frombufs
to locationfile_offset
int
.It returns the number of bytes written, which may be less than the length of
bufs
. In most cases, you will want to usepwrite_all
instead.val pwrite_all : _ rw -> file_offset:Optint.Int63.t -> Cstruct.t list -> unit
pwrite_all t ~file_offset bufs
writes all the data inbufs
to locationfile_offset
int
.Pi (eio.Eio.Flow.Pi) Module
Flow.Pi
\ No newline at end of file diff --git a/eio/Eio/Flow/Pi/module-type-SHUTDOWN/index.html b/eio/Eio/Flow/Pi/module-type-SHUTDOWN/index.html new file mode 100644 index 000000000..811fd8e42 --- /dev/null +++ b/eio/Eio/Flow/Pi/module-type-SHUTDOWN/index.html @@ -0,0 +1,2 @@ + +module type SOURCE = sig ... end
module type SINK = sig ... end
module type SHUTDOWN = sig ... end
val source : + (module SOURCE with type t = 't) -> + ('t, source_ty) Resource.handler
val sink : (module SINK with type t = 't) -> ('t, sink_ty) Resource.handler
val shutdown : + (module SHUTDOWN with type t = 't) -> + ('t, shutdown_ty) Resource.handler
module type TWO_WAY = sig ... end
val two_way : + (module TWO_WAY with type t = 't) -> + ('t, two_way_ty) Resource.handler
type Resource.pi +=
| Source : ('t, (module SOURCE with type t = 't), [> source_ty ]) Resource.pi
| Sink : ('t, (module SINK with type t = 't), [> sink_ty ]) Resource.pi
| Shutdown : ('t, (module SHUTDOWN with type t = 't), [> shutdown_ty ]) + Resource.pi
SHUTDOWN (eio.Eio.Flow.Pi.SHUTDOWN) Module type
Pi.SHUTDOWN
\ No newline at end of file diff --git a/eio/Eio/Flow/Pi/module-type-SINK/index.html b/eio/Eio/Flow/Pi/module-type-SINK/index.html new file mode 100644 index 000000000..b548430e7 --- /dev/null +++ b/eio/Eio/Flow/Pi/module-type-SINK/index.html @@ -0,0 +1,2 @@ + +val shutdown : t -> shutdown_command -> unit
SINK (eio.Eio.Flow.Pi.SINK) Module type
Pi.SINK
\ No newline at end of file diff --git a/eio/Eio/Flow/Pi/module-type-SOURCE/index.html b/eio/Eio/Flow/Pi/module-type-SOURCE/index.html new file mode 100644 index 000000000..ede0f4024 --- /dev/null +++ b/eio/Eio/Flow/Pi/module-type-SOURCE/index.html @@ -0,0 +1,2 @@ + +val single_write : t -> Cstruct.t list -> int
copy t ~src
allows for optimising copy operations.If you have no optimisations, you can use
simple_copy
to implement this usingsingle_write
.SOURCE (eio.Eio.Flow.Pi.SOURCE) \ No newline at end of file diff --git a/eio/Eio/Flow/Pi/module-type-TWO_WAY/index.html b/eio/Eio/Flow/Pi/module-type-TWO_WAY/index.html new file mode 100644 index 000000000..947198161 --- /dev/null +++ b/eio/Eio/Flow/Pi/module-type-TWO_WAY/index.html @@ -0,0 +1,2 @@ + + Module type
Pi.SOURCE
TWO_WAY (eio.Eio.Flow.Pi.TWO_WAY) Module type
Pi.TWO_WAY
\ No newline at end of file diff --git a/eio/Eio/Flow/class-sink/index.html b/eio/Eio/Flow/class-sink/index.html deleted file mode 100644 index c06f8a73c..000000000 --- a/eio/Eio/Flow/class-sink/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -
include SINK with type t := t
val single_write : t -> Cstruct.t list -> int
copy t ~src
allows for optimising copy operations.If you have no optimisations, you can use
simple_copy
to implement this usingsingle_write
.sink (eio.Eio.Flow.sink) Class
Flow.sink
Consumer base class.
\ No newline at end of file diff --git a/eio/Eio/Flow/class-source/index.html b/eio/Eio/Flow/class-source/index.html deleted file mode 100644 index 21f82202b..000000000 --- a/eio/Eio/Flow/class-source/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -inherit Eio__.Generic.t
method virtual copy : 'a. source as 'a -> unit
source (eio.Eio.Flow.source) Class
Flow.source
\ No newline at end of file diff --git a/eio/Eio/Flow/class-two_way/index.html b/eio/Eio/Flow/class-two_way/index.html deleted file mode 100644 index 3ac2b314b..000000000 --- a/eio/Eio/Flow/class-two_way/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -inherit Eio__.Generic.t
method read_methods : read_method list
two_way (eio.Eio.Flow.two_way) \ No newline at end of file diff --git a/eio/Eio/Flow/class-type-close/index.html b/eio/Eio/Flow/class-type-close/index.html deleted file mode 100644 index 7cd719a97..000000000 --- a/eio/Eio/Flow/class-type-close/index.html +++ /dev/null @@ -1,2 +0,0 @@ - - Class
Flow.two_way
close (eio.Eio.Flow.close) \ No newline at end of file diff --git a/eio/Eio/Flow/index.html b/eio/Eio/Flow/index.html index 3f32f8657..eb32d1e81 100644 --- a/eio/Eio/Flow/index.html +++ b/eio/Eio/Flow/index.html @@ -1,2 +1,2 @@ - Class type
Flow.close
Flow (eio.Eio.Flow) Module
Eio.Flow
Byte streams.
Flows are used to represent byte streams, such as open files and network sockets. A
source
provides a stream of bytes. Asink
consumes a stream. Atwo_way
can do both.To read structured data (e.g. a line at a time), wrap a source using
Buf_read
.\ No newline at end of file +Reading
class virtual source : object ... end
val single_read : source -> Cstruct.t -> int
single_read src buf
reads one or more bytes intobuf
.It returns the number of bytes read (which may be less than the buffer size even if there is more data to be read).
single_read src
just makes a single call tosrc#read_into
(and asserts that the result is in range).
- Use
read_exact
instead if you want to fillbuf
completely.- Use
Buf_read.line
to read complete lines.- Use
copy
to stream data directly from a source to a sink.
buf
must not be zero-length.val read_exact : source -> Cstruct.t -> unit
read_exact src dst
keeps reading intodst
until it is full.val read_methods : source -> read_method list
read_methods flow
is a list of extra ways of reading fromflow
, with the preferred (most efficient) methods first.If no method is suitable,
read
should be used as the fallback.val string_source : string -> source
string_source s
is a source that gives the bytes ofs
.val cstruct_source : Cstruct.t list -> source
cstruct_source cs
is a source that gives the bytes ofcs
.type read_method +=
| Read_source_buffer of (Cstruct.t list -> int) -> unit
(*If a source offers
Read_source_buffer rsb
then the user can callrsb fn
to borrow a view of the source's buffers.fn
returns the number of bytes it consumed.
rsb
will raiseEnd_of_file
if no more data will be produced. If no data is currently available,rsb
will wait for some to become available before callingfn
.*)
fn
must not continue to use the buffers after it returns.Writing
class virtual sink : object ... end
Consumer base class.
val write : sink -> Cstruct.t list -> unit
val copy_string : string -> sink -> unit
copy_string s = copy (string_source s)
val buffer_sink : Stdlib.Buffer.t -> sink
buffer_sink b
is a sink that adds anything sent to it tob
.To collect data as a cstruct, use
Buf_read
instead.Bidirectional streams
class virtual two_way : object ... end
val shutdown : two_way -> shutdown_command -> unit
shutdown t cmd
indicates that the caller has finished reading or writingt
(depending oncmd
).This is useful in some protocols to indicate that you have finished sending the request, and that the remote peer should now send the response.
Closing
Flows are usually attached to switches and closed automatically when the switch finishes. However, it can be useful to close them sooner manually in some cases.
class type close = Eio__.Generic.close
val close : close -> unit
Alias of
Generic.close
.Flow (eio.Eio.Flow) Module
Eio.Flow
Byte streams.
Flows are used to represent byte streams, such as open files and network sockets. A
source
provides a stream of bytes. Asink
consumes a stream. Atwo_way
can do both.To read structured data (e.g. a line at a time), wrap a source using
Buf_read
.\ No newline at end of file diff --git a/eio/Eio/Fs/Pi/index.html b/eio/Eio/Fs/Pi/index.html new file mode 100644 index 000000000..5ec9c02f4 --- /dev/null +++ b/eio/Eio/Fs/Pi/index.html @@ -0,0 +1,2 @@ + +Types
type 'a shutdown = [> shutdown_ty ] as 'a Std.r
Reading
val single_read : _ source -> Cstruct.t -> int
single_read src buf
reads one or more bytes intobuf
.It returns the number of bytes read (which may be less than the buffer size even if there is more data to be read).
- Use
read_exact
instead if you want to fillbuf
completely.- Use
Buf_read.line
to read complete lines.- Use
copy
to stream data directly from a source to a sink.
buf
must not be zero-length.val read_exact : _ source -> Cstruct.t -> unit
read_exact src dst
keeps reading intodst
until it is full.
cstruct_source cs
is a source that gives the bytes ofcs
.type read_method +=
| Read_source_buffer of 't -> (Cstruct.t list -> int) -> unit
(*If a source offers
Read_source_buffer rsb
then the user can callrsb t fn
to borrow a view of the source's buffers.fn
returns the number of bytes it consumed.
rsb
will raiseEnd_of_file
if no more data will be produced. If no data is currently available,rsb
will wait for some to become available before callingfn
.*)
fn
must not continue to use the buffers after it returns.Writing
val write : _ sink -> Cstruct.t list -> unit
val single_write : _ sink -> Cstruct.t list -> int
single_write dst bufs
writes at least one byte frombufs
and returns the number of bytes written.val copy_string : string -> _ sink -> unit
copy_string s = copy (string_source s)
buffer_sink b
is a sink that adds anything sent to it tob
.To collect data as a cstruct, use
Buf_read
instead.Bidirectional streams
type 'a two_way = [> two_way_ty ] as 'a Std.r
val shutdown : _ two_way -> shutdown_command -> unit
shutdown t cmd
indicates that the caller has finished reading or writingt
(depending oncmd
).This is useful in some protocols to indicate that you have finished sending the request, and that the remote peer should now send the response.
Closing
Flows are usually attached to switches and closed automatically when the switch finishes. However, it can be useful to close them sooner manually in some cases.
val close : [> `Close ] Std.r -> unit
Alias of
Resource.close
.Provider Interface
module Pi : sig ... end
Pi (eio.Eio.Fs.Pi) Module
Fs.Pi
Note: use the functions in
Path
to access directories.\ No newline at end of file diff --git a/eio/Eio/Fs/Pi/module-type-DIR/index.html b/eio/Eio/Fs/Pi/module-type-DIR/index.html new file mode 100644 index 000000000..d43b9ffed --- /dev/null +++ b/eio/Eio/Fs/Pi/module-type-DIR/index.html @@ -0,0 +1,8 @@ + +module type DIR = sig ... end
DIR (eio.Eio.Fs.Pi.DIR) Module type
Pi.DIR
\ No newline at end of file diff --git a/eio/Eio/Fs/class-dir/index.html b/eio/Eio/Fs/class-dir/index.html deleted file mode 100644 index 596f4e2bc..000000000 --- a/eio/Eio/Fs/class-dir/index.html +++ /dev/null @@ -1,21 +0,0 @@ - -val open_in : t -> sw:Switch.t -> path -> File.ro_ty Std.r
val mkdir : t -> perm:File.Unix_perm.t -> path -> unit
val pp : t Fmt.t
val native : t -> string -> string option
dir (eio.Eio.Fs.dir) Class
Fs.dir
Note: use the functions in
Path
to access directories.\ No newline at end of file diff --git a/eio/Eio/Fs/class-dir_with_close/index.html b/eio/Eio/Fs/class-dir_with_close/index.html deleted file mode 100644 index 917867a92..000000000 --- a/eio/Eio/Fs/class-dir_with_close/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -method probe : dir -> 'a. 'a Eio__.Generic.ty -> 'a option
method virtual open_in : sw:Eio__core.Switch.t -> - path -> - < close : unit - ; pread : file_offset:Optint.Int63.t -> Cstruct.t list -> int - ; probe : 'a. 'a Eio__.Generic.ty -> 'a option - ; read_into : Cstruct.t -> int - ; read_methods : Eio__.Flow.read_method list - ; stat : Eio__.File.Stat.t >
method virtual open_out : sw:Eio__core.Switch.t -> - append:bool -> - create:create -> - path -> - < close : unit - ; copy : 'b. Eio__.Flow.source as 'c -> unit - ; pread : file_offset:Optint.Int63.t -> Cstruct.t list -> int - ; probe : 'a. 'a Eio__.Generic.ty -> 'a option - ; pwrite : file_offset:Optint.Int63.t -> Cstruct.t list -> int - ; read_into : Cstruct.t -> int - ; read_methods : Eio__.Flow.read_method list - ; stat : Eio__.File.Stat.t - ; write : Cstruct.t list -> unit >
method virtual mkdir : perm:Eio__.File.Unix_perm.t -> path -> unit
method virtual open_dir : sw:Eio__core.Switch.t -> path -> dir_with_close
method virtual read_dir : path -> string list
method virtual unlink : path -> unit
method virtual rmdir : path -> unit
dir_with_close (eio.Eio.Fs.dir_with_close) Class
Fs.dir_with_close
\ No newline at end of file diff --git a/eio/Eio/Fs/index.html b/eio/Eio/Fs/index.html index 40b6c2617..bfe905908 100644 --- a/eio/Eio/Fs/index.html +++ b/eio/Eio/Fs/index.html @@ -1,2 +1,2 @@ -inherit dir
Fs (eio.Eio.Fs) Module
Eio.Fs
File-system types.
Defines types used by file-systems.
\ No newline at end of file +type error =
| Already_exists of Exn.Backend.t
| Not_found of Exn.Backend.t
| Permission_denied of Exn.Backend.t
| File_too_large
val err : error -> exn
type create = [
|
`Never
(*fail if the named file doesn't exist
*)|
`If_missing of File.Unix_perm.t
(*create if file doesn't already exist
*)|
`Or_truncate of File.Unix_perm.t
(*any existing file is truncated to zero length
*)|
`Exclusive of File.Unix_perm.t
(*always create; fail if the file already exists
*)]
When to create a new file.
If a new file is created, the given permissions are used for it.
class virtual dir_with_close : object ... end
Fs (eio.Eio.Fs) Module
Eio.Fs
File-system types.
Defines types used by file-systems.
\ No newline at end of file diff --git a/eio/Eio/Generic/class-type-close/index.html b/eio/Eio/Generic/class-type-close/index.html deleted file mode 100644 index 4a9ccf02f..000000000 --- a/eio/Eio/Generic/class-type-close/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -type error =
| Already_exists of Exn.Backend.t
| Not_found of Exn.Backend.t
| Permission_denied of Exn.Backend.t
| File_too_large
| Not_native of string
val err : error -> exn
type create = [
|
`Never
(*fail if the named file doesn't exist
*)|
`If_missing of File.Unix_perm.t
(*create if file doesn't already exist
*)|
`Or_truncate of File.Unix_perm.t
(*any existing file is truncated to zero length
*)|
`Exclusive of File.Unix_perm.t
(*always create; fail if the file already exists
*)]
When to create a new file.
If a new file is created, the given permissions are used for it.
close (eio.Eio.Generic.close) \ No newline at end of file diff --git a/eio/Eio/Generic/class-type-t/index.html b/eio/Eio/Generic/class-type-t/index.html deleted file mode 100644 index aab0fe6f9..000000000 --- a/eio/Eio/Generic/class-type-t/index.html +++ /dev/null @@ -1,2 +0,0 @@ - - Class type
Generic.close
t (eio.Eio.Generic.t) Class type
Generic.t
\ No newline at end of file diff --git a/eio/Eio/Generic/index.html b/eio/Eio/Generic/index.html deleted file mode 100644 index cb8ebd917..000000000 --- a/eio/Eio/Generic/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -method probe : 'a. 'a ty -> 'a option
Generic (eio.Eio.Generic) Module
Eio.Generic
A base class for objects that can be queried at runtime for extra features.
\ No newline at end of file diff --git a/eio/Eio/Lazy/index.html b/eio/Eio/Lazy/index.html new file mode 100644 index 000000000..6ad4f54b2 --- /dev/null +++ b/eio/Eio/Lazy/index.html @@ -0,0 +1,2 @@ + +class type t = object ... end
probe t feature
checks whethert
supportsfeature
. This is mostly for internal use. For example,Eio_unix
.FD.peek_opt uses this to get the underlying Unix file descriptor from a flow.Closing
Resources are usually attached to switches and closed automatically when the switch finishes. However, it can be useful to close them sooner in some cases.
class type close = object ... end
val close : close -> unit
close t
marks the resource as closed. It can no longer be used after this.If
t
is already closed then this does nothing (it does not raise an exception).Note: if an operation is currently in progress when this is called then it is not necessarily cancelled, and any underlying OS resource (such as a file descriptor) might not be closed immediately if other operations are using it. Closing a resource only prevents new operations from starting.
Lazy (eio.Eio.Lazy) Module
Eio.Lazy
Delayed evaluation.
This is like
Stdlib.Lazy
, but multiple fibers or domains can force at once.\ No newline at end of file diff --git a/eio/Eio/Mutex/index.html b/eio/Eio/Mutex/index.html index 17f52235b..266c375e7 100644 --- a/eio/Eio/Mutex/index.html +++ b/eio/Eio/Mutex/index.html @@ -1,2 +1,2 @@ -val from_fun : cancel:[ `Restart | `Record | `Protect ] -> (unit -> 'a) -> 'a t
from_fun ~cancel fn
is a lazy value that runsfn ()
the first time it is forced.
cancel
determines how cancellation is handled while forcing:
`Restart
: if the forcing fiber is cancelled, the next waiting fiber runsfn
again.`Record
: the failure is recorded and the lazy value will always report cancelled if used.`Protect
: the forcing fiber is protected from cancellation while running.val from_val : 'a -> 'a t
from_val v
is a lazy value that is already forced.It is equivalent to
from_fun (fun () -> v)
.val force : 'a t -> 'a
force t
returns the result of running the function passed tofrom_fun
.If the function is currently running, this waits for it to finish and then retries. If the function has already completed then it returns the saved result. If the function returned an exception then
force
re-raises it.Mutex (eio.Eio.Mutex) Module
Eio.Mutex
Mutual exclusion.
A mutex can be used to ensure that only one piece of code can access a shared resource at one time.
Unlike
Stdlib
.Mutex, which blocks the whole domain while waiting to take the mutex, this module allows other Eio fibers to run while waiting. You should use this module if your critical section may perform blocking operations, whileStdlib.Mutex
may be more efficient if the lock is held only briefly and the critial section does not switch fibers.Note that mutexes are often unnecessary for code running in a single domain, as the scheduler will only switch to another fiber if you perform an operation that can block.
\ No newline at end of file +type t = Mutex.t
The type for a concurrency-friendly mutex.
val create : unit -> t
create ()
creates an initially unlocked mutex.val use_rw : protect:bool -> t -> (unit -> 'a) -> 'a
use_rw ~protect t fn
waits for the mutex to be free and then executesfn ()
while holding the mutex locked.fn
may mutate the resource protected by the mutex, but must ensure the resource is in a consistent state before returning. Iffn
raises an exception, the mutex is disabled and cannot be used again.val use_ro : t -> (unit -> 'a) -> 'a
use_ro t fn
is likeuse_rw ~protect:false
, but iffn
raises an exception it unlocks the mutex instead of disabling it. Use this if you only need read-only access to the mutex's resource and so know that it will be in a consistent state even if an exception is raised.Note: a mutex still only allows one fiber to have the mutex locked at a time, even if all operations are "read-only".
Low-level API
Care must be taken when locking a mutex manually. It is easy to forget to unlock it in some cases, which will result in deadlock the next time a fiber tries to use it. In particular, you need to consider:
- What happens if your critical section raises an exception.
- What happens if your fiber is cancelled while in its critical section.
val lock : t -> unit
Lock the given mutex. Only one fiber can have the mutex locked at any time. A fiber that attempts to lock a mutex already locked by another fiber will suspend until the other fiber unlocks the mutex. If no other fiber has the lock, this returns immediately without switching fibers.
val unlock : t -> unit
unlock t
unlocks the mutex.Mutex (eio.Eio.Mutex) Module
Eio.Mutex
Mutual exclusion.
A mutex can be used to ensure that only one piece of code can access a shared resource at one time.
Unlike
Stdlib
.Mutex, which blocks the whole domain while waiting to take the mutex, this module allows other Eio fibers to run while waiting. You should use this module if your critical section may perform blocking operations, whileStdlib.Mutex
may be more efficient if the lock is held only briefly and the critial section does not switch fibers.Note that mutexes are often unnecessary for code running in a single domain, as the scheduler will only switch to another fiber if you perform an operation that can block.
\ No newline at end of file diff --git a/eio/Eio/Net/Ipaddr/V4/index.html b/eio/Eio/Net/Ipaddr/V4/index.html index c1cc9b064..495e95025 100644 --- a/eio/Eio/Net/Ipaddr/V4/index.html +++ b/eio/Eio/Net/Ipaddr/V4/index.html @@ -1,2 +1,2 @@ -type t = Mutex.t
The type for a concurrency-friendly mutex.
val create : unit -> t
create ()
creates an initially unlocked mutex.val use_rw : protect:bool -> t -> (unit -> 'a) -> 'a
use_rw ~protect t fn
waits for the mutex to be free and then executesfn ()
while holding the mutex locked.fn
may mutate the resource protected by the mutex, but must ensure the resource is in a consistent state before returning. Iffn
raises an exception, the mutex is disabled and cannot be used again.val use_ro : t -> (unit -> 'a) -> 'a
use_ro t fn
is likeuse_rw ~protect:false
, but iffn
raises an exception it unlocks the mutex instead of disabling it. Use this if you only need read-only access to the mutex's resource and so know that it will be in a consistent state even if an exception is raised.Note: a mutex still only allows one fiber to have the mutex locked at a time, even if all operations are "read-only".
Low-level API
Care must be taken when locking a mutex manually. It is easy to forget to unlock it in some cases, which will result in deadlock the next time a fiber tries to use it. In particular, you need to consider:
- What happens if your critical section raises an exception.
- What happens if your fiber is cancelled while in its critical section.
val lock : t -> unit
Lock the given mutex. Only one fiber can have the mutex locked at any time. A fiber that attempts to lock a mutex already locked by another fiber will suspend until the other fiber unlocks the mutex. If no other fiber has the lock, this returns immediately without switching fibers.
val unlock : t -> unit
unlock t
unlocks the mutex.V4 (eio.Eio.Net.Ipaddr.V4) Module
Ipaddr.V4
IPv4 addresses.
\ No newline at end of file +val any : [> `V4 ] t
A special IPv4 address, for use only with
listen
, representing all the Internet addresses that the host machine possesses.val loopback : [> `V4 ] t
A special IPv4 address representing the host machine (
127.0.0.1
).V4 (eio.Eio.Net.Ipaddr.V4) Module
Ipaddr.V4
IPv4 addresses.
\ No newline at end of file diff --git a/eio/Eio/Net/Ipaddr/V6/index.html b/eio/Eio/Net/Ipaddr/V6/index.html index 64536766e..6651770ef 100644 --- a/eio/Eio/Net/Ipaddr/V6/index.html +++ b/eio/Eio/Net/Ipaddr/V6/index.html @@ -1,2 +1,2 @@ -val any : [> `V4 ] t
A special IPv4 address, for use only with
listen
, representing all the Internet addresses that the host machine possesses.val loopback : [> `V4 ] t
A special IPv4 address representing the host machine (
127.0.0.1
).V6 (eio.Eio.Net.Ipaddr.V6) Module
Ipaddr.V6
IPv6 addresses.
\ No newline at end of file +val any : [> `V6 ] t
A special IPv6 address, for use only with
listen
, representing all the Internet addresses that the host machine possesses.val loopback : [> `V6 ] t
A special IPv6 address representing the host machine (
::1
).V6 (eio.Eio.Net.Ipaddr.V6) Module
Ipaddr.V6
IPv6 addresses.
\ No newline at end of file diff --git a/eio/Eio/Net/Ipaddr/index.html b/eio/Eio/Net/Ipaddr/index.html index e1fc44b47..ffddb4f06 100644 --- a/eio/Eio/Net/Ipaddr/index.html +++ b/eio/Eio/Net/Ipaddr/index.html @@ -1,5 +1,5 @@ -val any : [> `V6 ] t
A special IPv6 address, for use only with
listen
, representing all the Internet addresses that the host machine possesses.val loopback : [> `V6 ] t
A special IPv6 address representing the host machine (
::1
).Ipaddr (eio.Eio.Net.Ipaddr) Module
Net.Ipaddr
IP addresses.
The raw bytes of the IP address. It is either 4 bytes long (for an IPv4 address) or 16 bytes long (for IPv6).
module V4 : sig ... end
IPv4 addresses.
module V6 : sig ... end
IPv6 addresses.
val pp : [< `V4 | `V6 ] t Fmt.t
pp
formats IP addresses. For IPv6 addresses, it follows http://tools.ietf.org/html/rfc5952.type v4v6 = [ `V4 | `V6 ] t
val fold : +
Ipaddr (eio.Eio.Net.Ipaddr) Module
Net.Ipaddr
IP addresses.
The raw bytes of the IP address. It is either 4 bytes long (for an IPv4 address) or 16 bytes long (for IPv6).
module V4 : sig ... end
IPv4 addresses.
module V6 : sig ... end
IPv6 addresses.
val pp : [< `V4 | `V6 ] t Fmt.t
pp
formats IP addresses. For IPv6 addresses, it follows http://tools.ietf.org/html/rfc5952.type v4v6 = [ `V4 | `V6 ] t
val fold : v4:([> `V4 ] t -> 'a) -> v6:([> `V6 ] t -> 'a) -> [< `V4 | `V6 ] t -> diff --git a/eio/Eio/Net/Pi/index.html b/eio/Eio/Net/Pi/index.html new file mode 100644 index 000000000..37ff962a9 --- /dev/null +++ b/eio/Eio/Net/Pi/index.html @@ -0,0 +1,10 @@ + +
Pi (eio.Eio.Net.Pi) Module
Net.Pi
\ No newline at end of file diff --git a/eio/Eio/Net/Pi/module-type-DATAGRAM_SOCKET/index.html b/eio/Eio/Net/Pi/module-type-DATAGRAM_SOCKET/index.html new file mode 100644 index 000000000..2c1f62ccd --- /dev/null +++ b/eio/Eio/Net/Pi/module-type-DATAGRAM_SOCKET/index.html @@ -0,0 +1,2 @@ + +module type STREAM_SOCKET = sig ... end
val stream_socket : + (module STREAM_SOCKET with type t = 't and type tag = 'tag) -> + ('t, 'tag stream_socket_ty) Resource.handler
module type DATAGRAM_SOCKET = sig ... end
val datagram_socket : + (module DATAGRAM_SOCKET with type t = 't and type tag = 'tag) -> + ('t, 'tag datagram_socket_ty) Resource.handler
module type LISTENING_SOCKET = sig ... end
val listening_socket : + (module LISTENING_SOCKET with type t = 't and type tag = 'tag) -> + ('t, 'tag listening_socket_ty) Resource.handler
module type NETWORK = sig ... end
val network : + (module NETWORK with type t = 't and type tag = 'tag) -> + ('t, 'tag ty) Resource.handler
DATAGRAM_SOCKET (eio.Eio.Net.Pi.DATAGRAM_SOCKET) Module type
Pi.DATAGRAM_SOCKET
\ No newline at end of file diff --git a/eio/Eio/Net/Pi/module-type-LISTENING_SOCKET/index.html b/eio/Eio/Net/Pi/module-type-LISTENING_SOCKET/index.html new file mode 100644 index 000000000..c0d576003 --- /dev/null +++ b/eio/Eio/Net/Pi/module-type-LISTENING_SOCKET/index.html @@ -0,0 +1,2 @@ + +val send : t -> ?dst:Sockaddr.datagram -> Cstruct.t list -> unit
val recv : t -> Cstruct.t -> Sockaddr.datagram * int
val close : t -> unit
LISTENING_SOCKET (eio.Eio.Net.Pi.LISTENING_SOCKET) Module type
Pi.LISTENING_SOCKET
\ No newline at end of file diff --git a/eio/Eio/Net/Pi/module-type-NETWORK/index.html b/eio/Eio/Net/Pi/module-type-NETWORK/index.html new file mode 100644 index 000000000..59eece4c9 --- /dev/null +++ b/eio/Eio/Net/Pi/module-type-NETWORK/index.html @@ -0,0 +1,15 @@ + +val accept : t -> sw:Switch.t -> tag stream_socket_ty Std.r * Sockaddr.stream
val close : t -> unit
NETWORK (eio.Eio.Net.Pi.NETWORK) Module type
Pi.NETWORK
\ No newline at end of file diff --git a/eio/Eio/Net/Pi/module-type-STREAM_SOCKET/index.html b/eio/Eio/Net/Pi/module-type-STREAM_SOCKET/index.html new file mode 100644 index 000000000..5cffcd9bf --- /dev/null +++ b/eio/Eio/Net/Pi/module-type-STREAM_SOCKET/index.html @@ -0,0 +1,2 @@ + +val listen : + t -> + reuse_addr:bool -> + reuse_port:bool -> + backlog:int -> + sw:Switch.t -> + Sockaddr.stream -> + tag listening_socket_ty Std.r
val connect : t -> sw:Switch.t -> Sockaddr.stream -> tag stream_socket_ty Std.r
val datagram_socket : + t -> + reuse_addr:bool -> + reuse_port:bool -> + sw:Switch.t -> + [ Sockaddr.datagram | `UdpV4 | `UdpV6 ] -> + tag datagram_socket_ty Std.r
val getaddrinfo : t -> service:string -> string -> Sockaddr.t list
val getnameinfo : t -> Sockaddr.t -> string * string
STREAM_SOCKET (eio.Eio.Net.Pi.STREAM_SOCKET) Module type
Pi.STREAM_SOCKET
\ No newline at end of file diff --git a/eio/Eio/Net/Sockaddr/index.html b/eio/Eio/Net/Sockaddr/index.html index a7ab33bff..080336e94 100644 --- a/eio/Eio/Net/Sockaddr/index.html +++ b/eio/Eio/Net/Sockaddr/index.html @@ -1,2 +1,2 @@ -
include Flow.Pi.SOURCE with type t := t
val read_methods : t Flow.read_method list
val single_read : t -> Cstruct.t -> int
include Flow.Pi.SINK with type t := t
val single_write : t -> Cstruct.t list -> int
val copy : t -> src:_ Flow.source -> unit
copy t ~src
allows for optimising copy operations.If you have no optimisations, you can use
simple_copy
to implement this usingsingle_write
.val close : t -> unit
Sockaddr (eio.Eio.Net.Sockaddr) Module
Net.Sockaddr
Network addresses.
\ No newline at end of file +Socket addresses that we can build a
Flow.two_way
for i.e. stream-oriented protocols.Socket addresses that are message-oriented.
val pp : Stdlib.Format.formatter -> [< t ] -> unit
Sockaddr (eio.Eio.Net.Sockaddr) Module
Net.Sockaddr
Network addresses.
\ No newline at end of file diff --git a/eio/Eio/Net/class-datagram_socket/index.html b/eio/Eio/Net/class-datagram_socket/index.html deleted file mode 100644 index b12c7b002..000000000 --- a/eio/Eio/Net/class-datagram_socket/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -Socket addresses that we can build a
Flow.two_way
for i.e. stream-oriented protocols.Socket addresses that are message-oriented.
val pp : Stdlib.Format.formatter -> [< t ] -> unit
datagram_socket (eio.Eio.Net.datagram_socket) Class
Net.datagram_socket
\ No newline at end of file diff --git a/eio/Eio/Net/class-listening_socket/index.html b/eio/Eio/Net/class-listening_socket/index.html deleted file mode 100644 index 336e05ec8..000000000 --- a/eio/Eio/Net/class-listening_socket/index.html +++ /dev/null @@ -1,3 +0,0 @@ - -inherit socket
method virtual send : ?dst:Sockaddr.datagram -> Cstruct.t list -> unit
method virtual recv : Cstruct.t -> Sockaddr.datagram * int
listening_socket (eio.Eio.Net.listening_socket) Class
Net.listening_socket
\ No newline at end of file diff --git a/eio/Eio/Net/class-socket/index.html b/eio/Eio/Net/class-socket/index.html deleted file mode 100644 index 68cc92b05..000000000 --- a/eio/Eio/Net/class-socket/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -inherit socket
method virtual accept : sw:Eio__core.Switch.t -> - stream_socket * Sockaddr.stream
socket (eio.Eio.Net.socket) Class
Net.socket
\ No newline at end of file diff --git a/eio/Eio/Net/class-stream_socket/index.html b/eio/Eio/Net/class-stream_socket/index.html deleted file mode 100644 index fc57b9e30..000000000 --- a/eio/Eio/Net/class-stream_socket/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -inherit Eio__.Generic.t
stream_socket (eio.Eio.Net.stream_socket) Class
Net.stream_socket
\ No newline at end of file diff --git a/eio/Eio/Net/class-t/index.html b/eio/Eio/Net/class-t/index.html deleted file mode 100644 index 4c3fb4a84..000000000 --- a/eio/Eio/Net/class-t/index.html +++ /dev/null @@ -1,13 +0,0 @@ - -inherit socket
inherit Eio__.Flow.two_way
t (eio.Eio.Net.t) Class
Net.t
\ No newline at end of file diff --git a/eio/Eio/Net/index.html b/eio/Eio/Net/index.html index 5edc2f2c6..5c027cb8c 100644 --- a/eio/Eio/Net/index.html +++ b/eio/Eio/Net/index.html @@ -1,44 +1,59 @@ -method virtual listen : reuse_addr:bool -> - reuse_port:bool -> - backlog:int -> - sw:Eio__core.Switch.t -> - Sockaddr.stream -> - listening_socket
method virtual connect : sw:Eio__core.Switch.t -> - Sockaddr.stream -> - stream_socket
method virtual datagram_socket : reuse_addr:bool -> - reuse_port:bool -> - sw:Eio__core.Switch.t -> - [ Sockaddr.datagram | `UdpV4 | `UdpV6 ] -> - datagram_socket
method virtual getaddrinfo : service:string -> string -> Sockaddr.t list
method virtual getnameinfo : Sockaddr.t -> string * string
Net (eio.Eio.Net) Module
Eio.Net
Networking.
Example:
let addr = `Tcp (Ipaddr.V4.loopback, 8080) +
Net (eio.Eio.Net) Module
Eio.Net
Networking.
Example:
let addr = `Tcp (Ipaddr.V4.loopback, 8080) let http_get ~net ~stdout addr = Switch.run @@ fun sw -> let flow = Net.connect ~sw net addr in Flow.copy_string "GET / HTTP/1.0\r\n\r\n" flow; Flow.shutdown flow `Send; - Flow.copy flow stdout
\ No newline at end of file diff --git a/eio/Eio/Path/index.html b/eio/Eio/Path/index.html index e12e3a7a4..7dbc908b0 100644 --- a/eio/Eio/Path/index.html +++ b/eio/Eio/Path/index.html @@ -1,5 +1,5 @@ -type error =
| Connection_reset of Exn.Backend.t
(*This is a wrapper for epipe, econnreset and similar errors. It indicates that the flow has failed, and data may have been lost.
*)| Connection_failure of connection_failure
val err : error -> exn
err e
isEio.Exn.create (Net e)
module Ipaddr : sig ... end
IP addresses.
module Sockaddr : sig ... end
Network addresses.
Provider Interfaces
class virtual socket : object ... end
class virtual stream_socket : object ... end
class virtual datagram_socket : object ... end
class virtual listening_socket : object ... end
class virtual t : object ... end
Out-bound Connections
val connect : sw:Switch.t -> t -> Sockaddr.stream -> stream_socket
connect ~sw t addr
is a new socket connected to remote addressaddr
.The new socket will be closed when
sw
finishes, unless closed manually first.val with_tcp_connect : + Flow.copy flow stdout
\ No newline at end of file + Sockaddr.datagram listtype error =
| Connection_reset of Exn.Backend.t
(*This is a wrapper for epipe, econnreset and similar errors. It indicates that the flow has failed, and data may have been lost.
*)| Connection_failure of connection_failure
val err : error -> exn
err e
isEio.Exn.create (Net e)
module Ipaddr : sig ... end
IP addresses.
module Sockaddr : sig ... end
Network addresses.
Types
type 'tag stream_socket_ty = [
|
`Stream
|
`Platform of 'tag
|
`Shutdown
|
socket_ty
|
Flow.source_ty
|
Flow.sink_ty
]
type 'a stream_socket = 'a Std.r constraint 'a = [> [> `Generic ] stream_socket_ty ]
type 'a listening_socket = 'a Std.r constraint 'a = [> [> `Generic ] listening_socket_ty ]
type 'a connection_handler = 'a stream_socket -> Sockaddr.stream -> unit
A
_ connection_handler
handles incoming connections from a listening socket.type 'a datagram_socket = 'a Std.r constraint 'a = [> [> `Generic ] datagram_socket_ty ]
Out-bound Connections
val connect : + sw:Switch.t -> + [> 'tag ty ] t -> + Sockaddr.stream -> + 'tag stream_socket_ty Std.r
connect ~sw t addr
is a new socket connected to remote addressaddr
.The new socket will be closed when
sw
finishes, unless closed manually first.val with_tcp_connect : ?timeout:Time.Timeout.t -> host:string -> service:string -> - t -> - (stream_socket -> 'b) -> + [> 'tag ty ] Std.r -> + ('tag stream_socket_ty Std.r -> 'b) -> 'b
with_tcp_connect ~host ~service t f
creates a tcp connectionconn
tohost
andservice
and executesf conn
.
conn
is closed afterf
returns (if it isn't already closed by then).
host
is either an IP address or a domain name, eg. "www.example.org", "www.ocaml.org" or "127.0.0.1".
service
is an IANA recognized service name or port number, eg. "http", "ftp", "8080" etc. See https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml.Addresses are tried in the order they are returned by
getaddrinfo
, until one succeeds.Incoming Connections
val listen : ?reuse_addr:bool -> ?reuse_port:bool -> backlog:int -> sw:Switch.t -> - t -> + [> 'tag ty ] Std.r -> Sockaddr.stream -> - listening_socket
listen ~sw ~backlog t addr
is a new listening socket bound to local addressaddr
.The new socket will be closed when
sw
finishes, unless closed manually first.For (non-abstract) Unix domain sockets, the path will be removed afterwards.
val accept : sw:Switch.t -> listening_socket -> stream_socket * Sockaddr.stream
accept ~sw socket
waits until a new connection is ready onsocket
and returns it.The new socket will be closed automatically when
sw
finishes, if not closed earlier. If you want to handle multiple connections, consider usingaccept_fork
instead.type connection_handler = stream_socket -> Sockaddr.stream -> unit
connection_handler
handles incoming connections from a listening socket.val accept_fork : + 'tag listening_socket_ty Std.r
listen ~sw ~backlog t addr
is a new listening socket bound to local addressaddr
.The new socket will be closed when
sw
finishes, unless closed manually first.For (non-abstract) Unix domain sockets, the path will be removed afterwards.
val accept : + sw:Switch.t -> + [> 'tag listening_socket_ty ] Std.r -> + 'tag stream_socket_ty Std.r * Sockaddr.stream
accept ~sw socket
waits until a new connection is ready onsocket
and returns it.The new socket will be closed automatically when
sw
finishes, if not closed earlier. If you want to handle multiple connections, consider usingaccept_fork
instead.val accept_fork : sw:Switch.t -> - listening_socket -> + [> 'tag listening_socket_ty ] Std.r -> on_error:(exn -> unit) -> - connection_handler -> + [< 'tag stream_socket_ty ] connection_handler -> unit
accept_fork ~sw ~on_error socket fn
accepts a connection and handles it in a new fiber.After accepting a connection to
socket
, it runsfn flow client_addr
in a new fiber.
flow
will be closed whenfn
returns. The new fiber is attached tosw
.Running Servers
val run_server : ?max_connections:int -> - ?additional_domains:(Domain_manager.t * int) -> + ?additional_domains:(_ Domain_manager.t * int) -> ?stop:'a Promise.t -> on_error:(exn -> unit) -> - listening_socket -> - connection_handler -> + [> 'tag listening_socket_ty ] Std.r -> + [< 'tag stream_socket_ty ] connection_handler -> 'a
run_server ~on_error sock connection_handler
establishes a concurrent socket servers
.It accepts incoming client connections on socket
sock
and handles them withaccept_fork
(see that for the description ofon_error
andconnection_handler
).Running a Parallel Server
By default
s
runs on a single OCamlDomain
. However, ifadditional_domains:(domain_mgr, domains)
parameter is given, thens
will spawndomains
additional domains and run accept loops in those too. In such cases you must ensure thatconnection_handler
only accesses thread-safe values. Note that having more thanDomain
.recommended_domain_count domains in total is likely to result in bad performance.Datagram Sockets
val datagram_socket : ?reuse_addr:bool -> ?reuse_port:bool -> sw:Switch.t -> - t -> + [> 'tag ty ] Std.r -> [< Sockaddr.datagram | `UdpV4 | `UdpV6 ] -> - datagram_socket
datagram_socket ~sw t addr
creates a new datagram socket bound toaddr
. The new socket will be closed whensw
finishes.
`UdpV4
and`UdpV6
represents IPv4 and IPv6 datagram client sockets where the OS assigns the next available socket address and port automatically.`Udp ..
can be used to create both listening server socket and client socket.val send : datagram_socket -> ?dst:Sockaddr.datagram -> Cstruct.t list -> unit
send sock buf
sends the data inbuf
using the the datagram socketsock
.val recv : datagram_socket -> Cstruct.t -> Sockaddr.datagram * int
recv sock buf
receives data from the socketsock
putting it inbuf
. The number of bytes received is returned along with the sender address and port. If thebuf
is too small then excess bytes may be discarded depending on the type of the socket the message is received from.DNS queries
val getaddrinfo : ?service:string -> t -> string -> Sockaddr.t list
getaddrinfo ?service t node
returns a list of IP addresses fornode
.node
is either a domain name or an IP address.val getaddrinfo_stream : ?service:string -> t -> string -> Sockaddr.stream list
getaddrinfo_stream
is likegetaddrinfo
, but filters out non-stream protocols.val getaddrinfo_datagram : + 'tag datagram_socket_ty Std.r
datagram_socket ~sw t addr
creates a new datagram socket bound toaddr
. The new socket will be closed whensw
finishes.
`UdpV4
and`UdpV6
represents IPv4 and IPv6 datagram client sockets where the OS assigns the next available socket address and port automatically.`Udp ..
can be used to create both listening server socket and client socket.val send : + _ datagram_socket -> + ?dst:Sockaddr.datagram -> + Cstruct.t list -> + unit
send sock buf
sends the data inbuf
using the the datagram socketsock
.val recv : _ datagram_socket -> Cstruct.t -> Sockaddr.datagram * int
recv sock buf
receives data from the socketsock
putting it inbuf
. The number of bytes received is returned along with the sender address and port. If thebuf
is too small then excess bytes may be discarded depending on the type of the socket the message is received from.DNS queries
val getaddrinfo : ?service:string -> _ t -> string -> Sockaddr.t list
getaddrinfo ?service t node
returns a list of IP addresses fornode
.node
is either a domain name or an IP address.val getaddrinfo_stream : + ?service:string -> + _ t -> + string -> + Sockaddr.stream list
getaddrinfo_stream
is likegetaddrinfo
, but filters out non-stream protocols.val getaddrinfo_datagram : ?service:string -> - t -> + _ t -> string -> - Sockaddr.datagram list
getaddrinfo_datagram
is likegetaddrinfo
, but filters out non-datagram protocols.val getnameinfo : t -> Sockaddr.t -> string * string
getnameinfo t sockaddr
is(hostname, service)
corresponding tosockaddr
.hostname
is the registered domain name represented bysockaddr
.service
is the IANA specified textual name of the port specified insockaddr
, e.g. 'ftp', 'http', 'https', etc.Closing
val close : Generic.close -> unit
Alias of
Generic.close
.
getaddrinfo_datagram
is likegetaddrinfo
, but filters out non-datagram protocols.val getnameinfo : _ t -> Sockaddr.t -> string * string
getnameinfo t sockaddr
is(hostname, service)
corresponding tosockaddr
.hostname
is the registered domain name represented bysockaddr
.service
is the IANA specified textual name of the port specified insockaddr
, e.g. 'ftp', 'http', 'https', etc.Closing
val close : [> `Close ] Std.r -> unit
Alias of
Resource.close
.Provider Interface
module Pi : sig ... end
Path (eio.Eio.Path) Module
Eio.Path
Accessing paths on a file-system.
A
_ Path.t
represents a particular location in some filesystem. It is a pair of a base directory and a relative path from there.
Eio.Stdenv.cwd
provides access to the current working directory. For example:let ( / ) = Eio.Path.( / ) +
Path (eio.Eio.Path) Module
Eio.Path
Accessing paths on a file-system.
A
_ Path.t
represents a particular location in some filesystem. It is a pair of a base directory and a relative path from there.
Eio.Stdenv.cwd
provides access to the current working directory. For example:let ( / ) = Eio.Path.( / ) let run dir = Eio.Path.save ~create:(`Exclusive 0o600) @@ -7,15 +7,14 @@ let () = Eio_main.run @@ fun env -> - run (Eio.Stdenv.cwd env)
It is normally not permitted to access anything above the base directory, even by following a symlink. The exception is
Stdenv.fs
, which provides access to the whole file-system:Eio.Path.load (fs / "/etc/passwd")
\ No newline at end of file diff --git a/eio/Eio/Pool/index.html b/eio/Eio/Pool/index.html new file mode 100644 index 000000000..2c3a9d991 --- /dev/null +++ b/eio/Eio/Pool/index.html @@ -0,0 +1,8 @@ + +An OS directory FD and a path relative to it, for use with e.g.
openat(2)
.
t / step
ist
withstep
appended tot
's path, or replacingt
's path ifstep
is absolute:
(fd, "foo") / "bar" = (fd, "foo/bar")
(fd, "foo") / "/bar" = (fd, "/bar")
val pp : _ t Fmt.t
pp
formats a_ t
as "<label:path>", suitable for logging.Reading files
val load : _ t -> string
load t
returns the contents of the given file.This is a convenience wrapper around
with_open_in
.val open_in : sw:Switch.t -> _ t -> < File.ro ; Flow.close >
open_in ~sw t
openst
for reading.Note: files are always opened in binary mode.
val with_open_in : _ t -> (< File.ro ; Flow.close > -> 'a) -> 'a
with_open_in
is likeopen_in
, but callsfn flow
with the new flow and closes it automatically whenfn
returns (if it hasn't already been closed by then).val with_lines : _ t -> (string Stdlib.Seq.t -> 'a) -> 'a
with_lines t fn
is a convenience function for streaming the lines of the file.It uses
Buf_read.lines
.Writing files
save t data ~create
writesdata
tot
.This is a convenience wrapper around
with_open_out
.val open_out : + run (Eio.Stdenv.cwd env)
It is normally not permitted to access anything above the base directory, even by following a symlink. The exception is
Stdenv.fs
, which provides access to the whole file-system:Eio.Path.load (fs / "/etc/passwd")
In Eio, the directory separator is always "/", even on Windows. Use
native
to convert to a native path.\ No newline at end of file + (File.rw_ty Std.r -> 'a) -> + 'aAn OS directory FD and a path relative to it, for use with e.g.
openat(2)
.
t / step
ist
withstep
appended tot
's path, or replacingt
's path ifstep
is absolute:
(fd, "foo") / "bar" = (fd, "foo/bar")
(fd, "foo") / "/bar" = (fd, "/bar")
val pp : _ t Fmt.t
pp
formats a_ t
as "<label:path>", suitable for logging.val native : _ t -> string option
native t
returns a path that can be used to refer tot
with the host platform's native string-based file-system APIs, if available. This is intended for interoperability with non-Eio libraries.This does not check for confinement (the resulting path might not be accessible via
t
itself). Also, if a directory was opened withopen_dir
and later renamed, this might use the old name.Using strings as paths is not secure if components in the path can be replaced by symlinks while the path is being used. For example, if you try to write to "/home/mal/output.txt" just as mal replaces "output.txt" with a symlink to "/etc/passwd".
val native_exn : _ t -> string
Like
native
, but raise a suitable exception if the path is not a native path.Reading files
val load : _ t -> string
load t
returns the contents of the given file.This is a convenience wrapper around
with_open_in
.val open_in : sw:Switch.t -> _ t -> File.ro_ty Std.r
open_in ~sw t
openst
for reading.Note: files are always opened in binary mode.
val with_open_in : _ t -> (File.ro_ty Std.r -> 'a) -> 'a
with_open_in
is likeopen_in
, but callsfn flow
with the new flow and closes it automatically whenfn
returns (if it hasn't already been closed by then).val with_lines : _ t -> (string Stdlib.Seq.t -> 'a) -> 'a
with_lines t fn
is a convenience function for streaming the lines of the file.It uses
Buf_read.lines
.Writing files
save t data ~create
writesdata
tot
.This is a convenience wrapper around
with_open_out
.val open_out : sw:Switch.t -> ?append:bool -> create:Fs.create -> _ t -> - < File.rw - ; Flow.close >
open_out ~sw t
openst
for reading and writing.Note: files are always opened in binary mode.
val with_open_out : + File.rw_ty Resource.t
open_out ~sw t
openst
for reading and writing.Note: files are always opened in binary mode.
val with_open_out : ?append:bool -> create:Fs.create -> _ t -> - (< File.rw ; Flow.close > -> 'a) -> - 'a
with_open_out
is likeopen_out
, but callsfn flow
with the new flow and closes it automatically whenfn
returns (if it hasn't already been closed by then).Directories
val mkdir : perm:File.Unix_perm.t -> _ t -> unit
mkdir ~perm t
creates a new directoryt
with permissionsperm
.val open_dir : sw:Switch.t -> _ t -> < Fs.dir ; Flow.close > t
open_dir ~sw t
openst
.This can be passed to functions to grant access only to the subtree
t
.val with_open_dir : _ t -> (< Fs.dir ; Flow.close > t -> 'a) -> 'a
with_open_dir
is likeopen_dir
, but callsfn dir
with the new directory and closes it automatically whenfn
returns (if it hasn't already been closed by then).val read_dir : _ t -> string list
read_dir t
reads directory entries fort
.The entries are sorted using
String
.compare.Note: The special Unix entries "." and ".." are not included in the results.
Other
val unlink : _ t -> unit
unlink t
removes directory entryt
.Note: this cannot be used to unlink directories. Use
rmdir
for directories.val rmdir : _ t -> unit
rmdir t
removes directory entryt
. This only works when the entry is itself a directory.Note: this usually requires the directory to be empty.
with_open_out
is likeopen_out
, but callsfn flow
with the new flow and closes it automatically whenfn
returns (if it hasn't already been closed by then).Directories
val mkdir : perm:File.Unix_perm.t -> _ t -> unit
mkdir ~perm t
creates a new directoryt
with permissionsperm
.
open_dir ~sw t
openst
.This can be passed to functions to grant access only to the subtree
t
.
with_open_dir
is likeopen_dir
, but callsfn dir
with the new directory and closes it automatically whenfn
returns (if it hasn't already been closed by then).val read_dir : _ t -> string list
read_dir t
reads directory entries fort
.The entries are sorted using
String
.compare.Note: The special Unix entries "." and ".." are not included in the results.
Other
val unlink : _ t -> unit
unlink t
removes directory entryt
.Note: this cannot be used to unlink directories. Use
rmdir
for directories.val rmdir : _ t -> unit
rmdir t
removes directory entryt
. This only works when the entry is itself a directory.Note: this usually requires the directory to be empty.
Pool (eio.Eio.Pool) Module
Eio.Pool
A pool of resources.
This is useful to manage a collection of resources where creating new ones is expensive and so you want to reuse them where possible.
Example:
let buffer_pool = Eio.Pool.create 10 (fun () -> Bytes.create 1024) in +Eio.Pool.use buffer_pool (fun buf -> ...)
Note: If you just need to limit how many resources are in use, it is simpler to use
Eio.Semaphore
instead.\ No newline at end of file diff --git a/eio/Eio/Private/Broadcast/index.html b/eio/Eio/Private/Broadcast/index.html index 15569d827..f16f312ef 100644 --- a/eio/Eio/Private/Broadcast/index.html +++ b/eio/Eio/Private/Broadcast/index.html @@ -1,2 +1,2 @@ -val create : + ?validate:('a -> bool) -> + ?dispose:('a -> unit) -> + int -> + (unit -> 'a) -> + 'a t
create n alloc
is a fresh pool which allows up ton
resources to be live at a time. It usesalloc
to create new resources as needed. Ifalloc
raises an exception then that use fails, but future calls touse
will retry.The
alloc
function is called in the context of the fiber trying to use the pool. If the pool is shared between domains and the resources are attached to a switch, this might cause trouble (since switches can't be shared between domains). You might therefore want to makealloc
request a resource from the main domain rather than creating one itself.You should also take care about handling cancellation in
alloc
, since resources are typically attached to a switch with the lifetime of the pool, meaning that ifalloc
fails then they won't be freed automatically until the pool itself is finished.val use : 'a t -> ('a -> 'b) -> 'b
use t fn
waits for some resourcex
to be available and then runsf x
. Afterwards (on success or error),x
is returned to the pool.Broadcast (eio.Eio.Private.Broadcast) Module
Private.Broadcast
A lock-free queue of waiters that should all be resumed at once.
This uses
Cells
internally.\ No newline at end of file +val create : unit -> t
create ()
is a fresh broadcast queue.
suspend t fn
arranges forfn ()
to be called onresume_all
.
fn ()
may be called from the caller's context, or byresume_all
, so it needs to be able to cope with running in any context where that can run. For example,fn
must be safe to call from a signal handler ifresume_all
can be called from one.fn
must not raise.The returned request can be used to cancel. It can be
None
in the (unlikely) event thatt
got resumed before the function returned.val resume_all : t -> unit
resume_all t
calls all non-cancelled callbacks attached tot
, in the order in which they were suspended.This function is lock-free and can be used safely even from a signal handler or GC finalizer.
val cancel : request -> bool
cancel request
attempts to remove a pending request.It returns
true
if the request was cancelled, orfalse
if it got resumed before that could happen.val dump : Stdlib.Format.formatter -> t -> unit
Display the internal state of a queue, for debugging.
Broadcast (eio.Eio.Private.Broadcast) Module
Private.Broadcast
A lock-free queue of waiters that should all be resumed at once.
This uses
Cells
internally.\ No newline at end of file diff --git a/eio/Eio/Private/Cells/Make/argument-1-Cell/index.html b/eio/Eio/Private/Cells/Make/argument-1-Cell/index.html index 1c7aa0590..9195deb3e 100644 --- a/eio/Eio/Private/Cells/Make/argument-1-Cell/index.html +++ b/eio/Eio/Private/Cells/Make/argument-1-Cell/index.html @@ -1,2 +1,2 @@ -val create : unit -> t
create ()
is a fresh broadcast queue.
suspend t fn
arranges forfn ()
to be called onresume_all
.
fn ()
may be called from the caller's context, or byresume_all
, so it needs to be able to cope with running in any context where that can run. For example,fn
must be safe to call from a signal handler ifresume_all
can be called from one.fn
must not raise.The returned request can be used to cancel. It can be
None
in the (unlikely) event thatt
got resumed before the function returned.val resume_all : t -> unit
resume_all t
calls all non-cancelled callbacks attached tot
, in the order in which they were suspended.This function is lock-free and can be used safely even from a signal handler or GC finalizer.
val cancel : request -> bool
cancel request
attempts to remove a pending request.It returns
true
if the request was cancelled, orfalse
if it got resumed before that could happen.val dump : Stdlib.Format.formatter -> t -> unit
Display the internal state of a queue, for debugging.
Cell (eio.Eio.Private.Cells.Make.Cell) Parameter
Make.Cell
\ No newline at end of file +val init : 'a t
The value to give newly-allocated cells.
The number of bits to use for the offset into the segment.
The number of cells per segment is
2 ** segment_order
.val dump : _ t Fmt.t
Display the cell state for debugging.
Cell (eio.Eio.Private.Cells.Make.Cell) Parameter
Make.Cell
\ No newline at end of file diff --git a/eio/Eio/Private/Cells/Make/index.html b/eio/Eio/Private/Cells/Make/index.html index fc3c382c0..a2f3c0537 100644 --- a/eio/Eio/Private/Cells/Make/index.html +++ b/eio/Eio/Private/Cells/Make/index.html @@ -1,2 +1,2 @@ -val init : 'a t
The value to give newly-allocated cells.
The number of bits to use for the offset into the segment.
The number of cells per segment is
2 ** segment_order
.val dump : _ t Fmt.t
Display the cell state for debugging.
Make (eio.Eio.Private.Cells.Make) Module
Cells.Make
\ No newline at end of file +Parameters
Signature
val make : unit -> 'a t
make ()
is a fresh sequence of cells.
next_suspend t
atomically returns the next suspend cell and its segment.If multiple domains call this at the same time, they will each get a different location.
The cell might or might not have already been filled in by a resumer. You need to handle both cases (typically by using
Atomic
.compare_and_set).The segment can be used with
cancel_cell
.This function is lock-free and is safe to call even from a signal handler or GC finalizer.
next_resume t
atomically returns the next resume cell.If multiple domains call this at the same time, they will each get a different cell.
The cell might or might not contain a request from a suspender that got there first. You need to handle both cases (typically by using
Atomic
.compare_and_set).Note: cancelled cells may or may not be skipped (you need to handle the case of the cell you get being cancelled before you can write to it, but you also can't rely on seeing every cancelled cell, as cancelled segments may be deleted).
This function is lock-free and is safe to call even from a signal handler or GC finalizer.
resume_all t f
advances the resume position to the current suspend position, then callsf cell
on each cell advanced over.Note: as with
next_resume
,f
may be called for some cancelled cells but not others.
f
must not raise an exception (if it does, it will not be called on the remaining cells).If the resume position is ahead of the suspend position, then calling this function does nothing.
This function is lock-free and is safe to call even from a signal handler or GC finalizer.
val cancel_cell : 'a segment -> unit
cancel_cell segment
increments the segment's count of the number of cancelled cells.Once all cells are cancelled it may be possible to discard the whole segment. This avoids leaking memory if a user keeps suspending and then cancelling.
You must not call this more than once per cell.
This function is lock-free and is safe to call even from a signal handler or GC finalizer.
val validate : _ t -> unit
validate t
checks thatt
is in a valid state, assuming there are no operations currently in progress.val dump : _ t Fmt.t
dump
outputs the internal state of a_ t
, for debugging.Make (eio.Eio.Private.Cells.Make) Module
Cells.Make
\ No newline at end of file diff --git a/eio/Eio/Private/Cells/index.html b/eio/Eio/Private/Cells/index.html index 1fab5852b..dd6908690 100644 --- a/eio/Eio/Private/Cells/index.html +++ b/eio/Eio/Private/Cells/index.html @@ -1,2 +1,2 @@ -Parameters
Signature
val make : unit -> 'a t
make ()
is a fresh sequence of cells.
next_suspend t
atomically returns the next suspend cell and its segment.If multiple domains call this at the same time, they will each get a different location.
The cell might or might not have already been filled in by a resumer. You need to handle both cases (typically by using
Atomic
.compare_and_set).The segment can be used with
cancel_cell
.This function is lock-free and is safe to call even from a signal handler or GC finalizer.
next_resume t
atomically returns the next resume cell.If multiple domains call this at the same time, they will each get a different cell.
The cell might or might not contain a request from a suspender that got there first. You need to handle both cases (typically by using
Atomic
.compare_and_set).Note: cancelled cells may or may not be skipped (you need to handle the case of the cell you get being cancelled before you can write to it, but you also can't rely on seeing every cancelled cell, as cancelled segments may be deleted).
This function is lock-free and is safe to call even from a signal handler or GC finalizer.
resume_all t f
advances the resume position to the current suspend position, then callsf cell
on each cell advanced over.Note: as with
next_resume
,f
may be called for some cancelled cells but not others.
f
must not raise an exception (if it does, it will not be called on the remaining cells).If the resume position is ahead of the suspend position, then calling this function does nothing.
This function is lock-free and is safe to call even from a signal handler or GC finalizer.
val cancel_cell : 'a segment -> unit
cancel_cell segment
increments the segment's count of the number of cancelled cells.Once all cells are cancelled it may be possible to discard the whole segment. This avoids leaking memory if a user keeps suspending and then cancelling.
You must not call this more than once per cell.
This function is lock-free and is safe to call even from a signal handler or GC finalizer.
val validate : _ t -> unit
validate t
checks thatt
is in a valid state, assuming there are no operations currently in progress.val dump : _ t Fmt.t
dump
outputs the internal state of a_ t
, for debugging.Cells (eio.Eio.Private.Cells) Module
Private.Cells
A lock-free queue-like structure with suspension and cancellation.
This module provides an infinite sequence of atomic cells, which can be used for whatever you like. There are two pointers into this sequence: a suspend (consumer) pointer and a resume (producer) pointer. These are similar to the head and tail pointers in a traditional queue, except that the consumer is also permitted to get ahead of the producer.
To use this as a plain queue, each producer calls
Make.next_resume
to get the cell at the resume (tail) pointer (and advance it atomically), then stores its value in the cell. Each consumer callsMake.next_suspend
to get the next cell at the head of the queue (and advance the suspend pointer).The consumer/suspender is permitted to get ahead of the producer. In this case, the consumer will CAS the cell from its initial state to a Request state containing a callback to receive the value when it arrives. When a producer later tries to CAS the cell from the initial state to holding a value, it will fail and find the Request with the callback function instead. It can then provide the value directly to the callback.
A suspender can be cancelled by CASing the Request to a Cancelled state. It should also call
Make.cancel_cell
(if the CAS succeeds), to allow the cell to be freed. If a resumer's CAS fails because the cell is cancelled, it can retry with a fresh cell.For efficiency, cells are grouped into segments, which are stored in a linked list. Once all the cells in a segment are cancelled, the whole segment may be freed.
This is based on A formally-verified framework for fair synchronization in kotlin coroutines, Appendix C, which contains more details and examples of use.
This module also adds the
Make.resume_all
function, which is useful for broadcasting.\ No newline at end of file +module type CELL = sig ... end
The signature for user-defined cell contents.
Cells (eio.Eio.Private.Cells) Module
Private.Cells
A lock-free queue-like structure with suspension and cancellation.
This module provides an infinite sequence of atomic cells, which can be used for whatever you like. There are two pointers into this sequence: a suspend (consumer) pointer and a resume (producer) pointer. These are similar to the head and tail pointers in a traditional queue, except that the consumer is also permitted to get ahead of the producer.
To use this as a plain queue, each producer calls
Make.next_resume
to get the cell at the resume (tail) pointer (and advance it atomically), then stores its value in the cell. Each consumer callsMake.next_suspend
to get the next cell at the head of the queue (and advance the suspend pointer).The consumer/suspender is permitted to get ahead of the producer. In this case, the consumer will CAS the cell from its initial state to a Request state containing a callback to receive the value when it arrives. When a producer later tries to CAS the cell from the initial state to holding a value, it will fail and find the Request with the callback function instead. It can then provide the value directly to the callback.
A suspender can be cancelled by CASing the Request to a Cancelled state. It should also call
Make.cancel_cell
(if the CAS succeeds), to allow the cell to be freed. If a resumer's CAS fails because the cell is cancelled, it can retry with a fresh cell.For efficiency, cells are grouped into segments, which are stored in a linked list. Once all the cells in a segment are cancelled, the whole segment may be freed.
This is based on A formally-verified framework for fair synchronization in kotlin coroutines, Appendix C, which contains more details and examples of use.
This module also adds the
Make.resume_all
function, which is useful for broadcasting.\ No newline at end of file diff --git a/eio/Eio/Private/Cells/module-type-CELL/index.html b/eio/Eio/Private/Cells/module-type-CELL/index.html index 0ec1be57a..d896db1f5 100644 --- a/eio/Eio/Private/Cells/module-type-CELL/index.html +++ b/eio/Eio/Private/Cells/module-type-CELL/index.html @@ -1,2 +1,2 @@ -module type CELL = sig ... end
The signature for user-defined cell contents.
CELL (eio.Eio.Private.Cells.CELL) Module type
Cells.CELL
The signature for user-defined cell contents.
\ No newline at end of file +val init : 'a t
The value to give newly-allocated cells.
The number of bits to use for the offset into the segment.
The number of cells per segment is
2 ** segment_order
.val dump : _ t Fmt.t
Display the cell state for debugging.
CELL (eio.Eio.Private.Cells.CELL) Module type
Cells.CELL
The signature for user-defined cell contents.
\ No newline at end of file diff --git a/eio/Eio/Private/Ctf/Control/index.html b/eio/Eio/Private/Ctf/Control/index.html index f52df0ff7..47bd54a0a 100644 --- a/eio/Eio/Private/Ctf/Control/index.html +++ b/eio/Eio/Private/Ctf/Control/index.html @@ -1,2 +1,2 @@ -val init : 'a t
The value to give newly-allocated cells.
The number of bits to use for the offset into the segment.
The number of cells per segment is
2 ** segment_order
.val dump : _ t Fmt.t
Display the cell state for debugging.
Control (eio.Eio.Private.Ctf.Control) Module
Ctf.Control
\ No newline at end of file +val make : timestamper:(log_buffer -> int -> unit) -> log_buffer -> t
make ~timestamper b
is a trace buffer that record events inb
. In most cases, theCtf_unix
module provides a simpler interface.val start : t -> unit
start t
begins recording events int
.val stop : t -> unit
stop t
stops recording tot
(which must be the current trace buffer).Control (eio.Eio.Private.Ctf.Control) Module
Ctf.Control
\ No newline at end of file diff --git a/eio/Eio/Private/Ctf/index.html b/eio/Eio/Private/Ctf/index.html index 2a4ac9b67..ca02333c5 100644 --- a/eio/Eio/Private/Ctf/index.html +++ b/eio/Eio/Private/Ctf/index.html @@ -1,4 +1,4 @@ -val make : timestamper:(log_buffer -> int -> unit) -> log_buffer -> t
make ~timestamper b
is a trace buffer that record events inb
. In most cases, theCtf_unix
module provides a simpler interface.val start : t -> unit
start t
begins recording events int
.val stop : t -> unit
stop t
stops recording tot
(which must be the current trace buffer).Ctf (eio.Eio.Private.Ctf) Module
Private.Ctf
This library is used to write event traces in mirage-profile's CTF format.
Recording events
Libraries and applications can use these functions to make the traces more useful.
note_increase counter delta
records thatcounter
increased bydelta
. Ifdelta
is negative, this records a decrease.
note_counter_value counter value
records thatcounter
is nowvalue
.val should_resolve : id -> unit
should_resolve id
records thatid
is expected to resolve, and should be highlighted if it doesn't.Recording system events
These are normally only called by the scheduler.
val mint_id : unit -> id
mint_id ()
is a fresh uniqueid
.
note_created t id ty
records the creation ofid
.val note_try_read : id -> unit
note_try_read src
records that the current thread wants to read fromsrc
(which is not currently ready).val note_switch : id -> unit
note_switch id
records thatid
is now the current thread.val note_hiatus : hiatus_reason -> unit
note_hiatus r
records that the system will sleep for reasonr
.val note_resume : id -> unit
note_resume id
records that the system has resumed (used afternote_hiatus
), and is now runningid
.val note_fork : unit -> id
note_fork ()
records that a new thread has been forked and returns a fresh ID for it.val note_resolved : id -> ex:exn option -> unit
note_resolved id ~ex
records thatid
is now resolved. Ifex = None
thenid
was successful, otherwise it failed with exceptionex
.Controlling tracing
type log_buffer = +
Ctf (eio.Eio.Private.Ctf) Module
Private.Ctf
This library is used to write event traces in mirage-profile's CTF format.
\ No newline at end of file diff --git a/eio/Eio/Private/Debug/index.html b/eio/Eio/Private/Debug/index.html index 97396b6db..7fcf9ff6a 100644 --- a/eio/Eio/Private/Debug/index.html +++ b/eio/Eio/Private/Debug/index.html @@ -1,8 +1,8 @@ -Recording events
Libraries and applications can use these functions to make the traces more useful.
note_increase counter delta
records thatcounter
increased bydelta
. Ifdelta
is negative, this records a decrease.
note_counter_value counter value
records thatcounter
is nowvalue
.val should_resolve : id -> unit
should_resolve id
records thatid
is expected to resolve, and should be highlighted if it doesn't.Recording system events
These are normally only called by the scheduler.
val mint_id : unit -> id
mint_id ()
is a fresh uniqueid
.
note_created t id ty
records the creation ofid
.val note_try_read : id -> unit
note_try_read src
records that the current thread wants to read fromsrc
(which is not currently ready).val note_switch : id -> unit
note_switch id
records thatid
is now the current thread.val note_hiatus : hiatus_reason -> unit
note_hiatus r
records that the system will sleep for reasonr
.val note_resume : id -> unit
note_resume id
records that the system has resumed (used afternote_hiatus
), and is now runningid
.val note_fork : unit -> id
note_fork ()
records that a new thread has been forked and returns a fresh ID for it.val note_resolved : id -> ex:exn option -> unit
note_resolved id ~ex
records thatid
is now resolved. Ifex = None
thenid
was successful, otherwise it failed with exceptionex
.Controlling tracing
module Control : sig ... end
Debug (eio.Eio.Private.Debug) Module
Private.Debug
val traceln : +
Debug (eio.Eio.Private.Debug) Module
Private.Debug
val traceln : ?__POS__:(string * int * int * int) -> ('a, Stdlib.Format.formatter, unit, unit) Stdlib.format4 -> - 'a
Writes trace logging using the current fiber's configured traceln function.
The mutex used to prevent two domains writing to stderr at once.
This might be useful if you want to write to it directly yourself, e.g. for a log reporter.
Writes trace logging using the current fiber's configured traceln function.
with_trace_prefix fmt fn
runsfn ()
with a traceln that outputsfmt
before each message.The mutex used to prevent two domains writing to stderr at once.
This might be useful if you want to write to it directly yourself, e.g. for a log reporter.
val default_traceln : ?__POS__:(string * int * int * int) -> ('a, Stdlib.Format.formatter, unit, unit) Stdlib.format4 -> 'a
default_traceln
is a suitable default implementation forEio.Std.traceln
.It writes output to stderr, prefixing each line with a "+". If
__POS__
is given, it also displays the file and line number from that. It usestraceln_mutex
so that only one domain's output is written at a time.type traceln = {
traceln : 'a. ?__POS__:(string * int * int * int) -> diff --git a/eio/Eio/Private/Dla/index.html b/eio/Eio/Private/Dla/index.html index 0bd6a25e8..34f80ffb0 100644 --- a/eio/Eio/Private/Dla/index.html +++ b/eio/Eio/Private/Dla/index.html @@ -1,2 +1,2 @@ -
Dla (eio.Eio.Private.Dla) \ No newline at end of file + Module
Private.Dla
Dla (eio.Eio.Private.Dla) \ No newline at end of file diff --git a/eio/Eio/Private/Effects/index.html b/eio/Eio/Private/Effects/index.html index 90b004b3b..87ff67f86 100644 --- a/eio/Eio/Private/Effects/index.html +++ b/eio/Eio/Private/Effects/index.html @@ -1,2 +1,2 @@ - Module
Private.Dla
Effects (eio.Eio.Private.Effects) Module
Private.Effects
\ No newline at end of file +A function provided by the scheduler to reschedule a previously-suspended thread.
type Stdlib.Effect.t +=
| Suspend : (Fiber_context.t -> 'a enqueue -> unit) -> 'a Stdlib.Effect.t
(**)
Suspend fn
is performed when a fiber must be suspended (e.g. because it calledPromise.await
on an unresolved promise). The effect handler runsfn fiber enqueue
in the scheduler context, passing it the suspended fiber's context and a function to resume it.fn
should arrange forenqueue
to be called once the thread is ready to run again.| Fork : Fiber_context.t * (unit -> unit) -> unit Stdlib.Effect.t
(**)
perform (Fork new_context f)
creates a new fiber and runsf
in it, with contextnew_context
.f
must not raise an exception. SeeFiber.fork
.| Get_context : Fiber_context.t Stdlib.Effect.t
(**)
perform Get_context
immediately returns the current fiber's context (without switching fibers).Effects (eio.Eio.Private.Effects) Module
Private.Effects
\ No newline at end of file diff --git a/eio/Eio/Private/Fiber_context/index.html b/eio/Eio/Private/Fiber_context/index.html index 8ca5b252f..d5e256fc6 100644 --- a/eio/Eio/Private/Fiber_context/index.html +++ b/eio/Eio/Private/Fiber_context/index.html @@ -1,2 +1,2 @@ -A function provided by the scheduler to reschedule a previously-suspended thread.
type Stdlib.Effect.t +=
| Suspend : (Fiber_context.t -> 'a enqueue -> unit) -> 'a Stdlib.Effect.t
(**)
Suspend fn
is performed when a fiber must be suspended (e.g. because it calledPromise.await
on an unresolved promise). The effect handler runsfn fiber enqueue
in the scheduler context, passing it the suspended fiber's context and a function to resume it.fn
should arrange forenqueue
to be called once the thread is ready to run again.| Fork : Fiber_context.t * (unit -> unit) -> unit Stdlib.Effect.t
(**)
perform (Fork new_context f)
creates a new fiber and runsf
in it, with contextnew_context
.f
must not raise an exception. SeeFiber.fork
.| Get_context : Fiber_context.t Stdlib.Effect.t
(**)
perform Get_context
immediately returns the current fiber's context (without switching fibers).Fiber_context (eio.Eio.Private.Fiber_context) Module
Private.Fiber_context
Every fiber has an associated context.
\ No newline at end of file +val make_root : unit -> t
Make a new root context for a new domain.
val destroy : t -> unit
destroy t
removest
from its cancellation context.Cancellation
The
Cancel
module describes the user's view of cancellation.Internally, when the user calls a primitive operation that needs to block the fiber, the
Suspend callback
effect is performed. This suspends the fiber and callscallback
from the scheduler's context, passing it the suspended fiber's context. If the operation can be cancelled, the callback should useset_cancel_fn
to register a cancellation function.There are two possible outcomes for the operation: it may complete normally, or it may be cancelled. If it is cancelled then the registered cancellation function is called. This function will always be called from the fiber's own domain, but care must be taken if the operation could be completed by another domain at the same time.
Consider the case of
Stream.take
, which can be fulfilled by aStream.add
from another domain. We want to ensure that either the item is removed from the stream and returned to the waiting fiber, or that the operation is cancelled and the item is not removed from the stream.Therefore, cancelling and completing both need to update an atomic value (with
Atomic
.compare_and_set) so that only one can succeed. The case whereStream.take
succeeds before cancellation:
- A fiber calls
Suspend
and is suspended. The callback sets a cancel function and registers a waiter on the stream.- When another domain has an item, it marks the atomic as finished (making the
take
uncancellable) and begins resuming the fiber with the new item.- If the taking fiber is cancelled after this, the cancellation must be ignored and the operation will complete successfully. Future operations will fail immediately, however.
The case of cancellation winning the race:
- A fiber calls
Suspend
and is suspended. The callback sets a cancel function and registers a waiter on the stream.- The taking fiber is cancelled. Its cancellation function is called, which updates the atomic and starts removing the waiter.
- If another domain tries to provide an item to the waiter as this is happening, it will try to update the atomic too and fail. The item will be given to the next waiter instead.
Note: A fiber will only have a cancel function set while it is suspended.
val set_cancel_fn : t -> (exn -> unit) -> unit
set_cancel_fn t fn
setsfn
as the fiber's cancel function.If
t
's cancellation context is cancelled, the function is called. It should attempt to make the current operation finish quickly, either with a successful result or by raising the given exception.Just before being called, the fiber's cancel function is replaced with
ignore
so thatfn
cannot be called twice.On success, the cancel function is cleared automatically when
Suspend.enter
returns, but for single-domain operations you may like to callclear_cancel_fn
manually to remove it earlier.
fn
will be called fromt
's domain (from the fiber that calledcancel
).
fn
must not switch fibers. If it did, this could happen:
- Another suspended fiber in the same cancellation context resumes before its cancel function is called.
- It enters a protected block and starts a new operation.
fn
returns.- We cancel the protected operation.
val clear_cancel_fn : t -> unit
clear_cancel_fn t
isset_cancel_fn t ignore
.This must only be called from the fiber's own domain.
For single-domain operations, it can be useful to call this manually as soon as the operation succeeds (i.e. when the fiber is added to the run-queue) to prevent the cancel function from being called.
For operations where another domain may resume the fiber, your cancel function will need to cope with being called after the operation has succeeded. In that case you should not call
clear_cancel_fn
. The backend will do it automatically just before resuming your fiber.val get_error : t -> exn option
get_error t
isCancel.get_error (cancellation_context t)
Fiber_context (eio.Eio.Private.Fiber_context) Module
Private.Fiber_context
Every fiber has an associated context.
\ No newline at end of file diff --git a/eio/Eio/Private/Suspend/index.html b/eio/Eio/Private/Suspend/index.html index 807dbd40b..b87f87f24 100644 --- a/eio/Eio/Private/Suspend/index.html +++ b/eio/Eio/Private/Suspend/index.html @@ -1,2 +1,2 @@ -val make_root : unit -> t
Make a new root context for a new domain.
val destroy : t -> unit
destroy t
removest
from its cancellation context.Cancellation
The
Cancel
module describes the user's view of cancellation.Internally, when the user calls a primitive operation that needs to block the fiber, the
Suspend callback
effect is performed. This suspends the fiber and callscallback
from the scheduler's context, passing it the suspended fiber's context. If the operation can be cancelled, the callback should useset_cancel_fn
to register a cancellation function.There are two possible outcomes for the operation: it may complete normally, or it may be cancelled. If it is cancelled then the registered cancellation function is called. This function will always be called from the fiber's own domain, but care must be taken if the operation could be completed by another domain at the same time.
Consider the case of
Stream.take
, which can be fulfilled by aStream.add
from another domain. We want to ensure that either the item is removed from the stream and returned to the waiting fiber, or that the operation is cancelled and the item is not removed from the stream.Therefore, cancelling and completing both need to update an atomic value (with
Atomic
.compare_and_set) so that only one can succeed. The case whereStream.take
succeeds before cancellation:
- A fiber calls
Suspend
and is suspended. The callback sets a cancel function and registers a waiter on the stream.- When another domain has an item, it marks the atomic as finished (making the
take
uncancellable) and begins resuming the fiber with the new item.- If the taking fiber is cancelled after this, the cancellation must be ignored and the operation will complete successfully. Future operations will fail immediately, however.
The case of cancellation winning the race:
- A fiber calls
Suspend
and is suspended. The callback sets a cancel function and registers a waiter on the stream.- The taking fiber is cancelled. Its cancellation function is called, which updates the atomic and starts removing the waiter.
- If another domain tries to provide an item to the waiter as this is happening, it will try to update the atomic too and fail. The item will be given to the next waiter instead.
Note: A fiber will only have a cancel function set while it is suspended.
val set_cancel_fn : t -> (exn -> unit) -> unit
set_cancel_fn t fn
setsfn
as the fiber's cancel function.If
t
's cancellation context is cancelled, the function is called. It should attempt to make the current operation finish quickly, either with a successful result or by raising the given exception.Just before being called, the fiber's cancel function is replaced with
ignore
so thatfn
cannot be called twice.On success, the cancel function is cleared automatically when
Suspend.enter
returns, but for single-domain operations you may like to callclear_cancel_fn
manually to remove it earlier.
fn
will be called fromt
's domain (from the fiber that calledcancel
).
fn
must not switch fibers. If it did, this could happen:
- Another suspended fiber in the same cancellation context resumes before its cancel function is called.
- It enters a protected block and starts a new operation.
fn
returns.- We cancel the protected operation.
val clear_cancel_fn : t -> unit
clear_cancel_fn t
isset_cancel_fn t ignore
.This must only be called from the fiber's own domain.
For single-domain operations, it can be useful to call this manually as soon as the operation succeeds (i.e. when the fiber is added to the run-queue) to prevent the cancel function from being called.
For operations where another domain may resume the fiber, your cancel function will need to cope with being called after the operation has succeeded. In that case you should not call
clear_cancel_fn
. The backend will do it automatically just before resuming your fiber.val get_error : t -> exn option
get_error t
isCancel.get_error (cancellation_context t)
Suspend (eio.Eio.Private.Suspend) Module
Private.Suspend
Suspend a fiber and enter the scheduler.
\ No newline at end of file +val enter : (Fiber_context.t -> 'a Effects.enqueue -> unit) -> 'a
enter fn
suspends the calling fiber and callsfn ctx enqueue
in the scheduler's context. This should arrange forenqueue
to be called when the fiber should be resumed.enqueue
is thread-safe and so can be called from another domain or systhread.
ctx
should be used to set a cancellation function. Otherwise, the operation is non-interruptable. If the caller's cancellation context is already cancelled,enter
immediately aborts.val enter_unchecked : (Fiber_context.t -> 'a Effects.enqueue -> unit) -> 'a
enter_unchecked
is likeenter
except that it does not perform the initial check that the fiber isn't cancelled (this is useful if you want to do the check yourself, e.g. because you need to unlock a mutex if cancelled).Suspend (eio.Eio.Private.Suspend) Module
Private.Suspend
Suspend a fiber and enter the scheduler.
\ No newline at end of file diff --git a/eio/Eio/Private/index.html b/eio/Eio/Private/index.html index 9287fbbc2..fd7780a37 100644 --- a/eio/Eio/Private/index.html +++ b/eio/Eio/Private/index.html @@ -1,2 +1,2 @@ -val enter : (Fiber_context.t -> 'a Effects.enqueue -> unit) -> 'a
enter fn
suspends the calling fiber and callsfn ctx enqueue
in the scheduler's context. This should arrange forenqueue
to be called when the fiber should be resumed.enqueue
is thread-safe and so can be called from another domain or systhread.
ctx
should be used to set a cancellation function. Otherwise, the operation is non-interruptable. If the caller's cancellation context is already cancelled,enter
immediately aborts.val enter_unchecked : (Fiber_context.t -> 'a Effects.enqueue -> unit) -> 'a
enter_unchecked
is likeenter
except that it does not perform the initial check that the fiber isn't cancelled (this is useful if you want to do the check yourself, e.g. because you need to unlock a mutex if cancelled).Private (eio.Eio.Private) Module
Eio.Private
API for use by the scheduler implementation.
\ No newline at end of file +module Ctf : sig ... end
This library is used to write event traces in mirage-profile's CTF format.
module Cells : sig ... end
A lock-free queue-like structure with suspension and cancellation.
module Broadcast : sig ... end
A lock-free queue of waiters that should all be resumed at once.
module Fiber_context : sig ... end
Every fiber has an associated context.
module Effects : sig ... end
module Suspend : sig ... end
Suspend a fiber and enter the scheduler.
module Debug : sig ... end
module Dla : sig ... end
Private (eio.Eio.Private) Module
Eio.Private
API for use by the scheduler implementation.
\ No newline at end of file diff --git a/eio/Eio/Process/Pi/index.html b/eio/Eio/Process/Pi/index.html new file mode 100644 index 000000000..df1f6dc76 --- /dev/null +++ b/eio/Eio/Process/Pi/index.html @@ -0,0 +1,12 @@ + +module Ctf : sig ... end
This library is used to write event traces in mirage-profile's CTF format.
module Cells : sig ... end
A lock-free queue-like structure with suspension and cancellation.
module Broadcast : sig ... end
A lock-free queue of waiters that should all be resumed at once.
module Fiber_context : sig ... end
Every fiber has an associated context.
module Effects : sig ... end
module Suspend : sig ... end
Suspend a fiber and enter the scheduler.
module Debug : sig ... end
module Dla : sig ... end
Pi (eio.Eio.Process.Pi) Module
Process.Pi
\ No newline at end of file diff --git a/eio/Eio/Process/Pi/module-type-MGR/index.html b/eio/Eio/Process/Pi/module-type-MGR/index.html new file mode 100644 index 000000000..f7f3a1bac --- /dev/null +++ b/eio/Eio/Process/Pi/module-type-MGR/index.html @@ -0,0 +1,16 @@ + +Provider Interface
module type PROCESS = sig ... end
type Resource.pi +=
| Process : ('t, + (module PROCESS + with type t = 't + and type tag = 'tag), + [> 'tag ty ]) + Resource.pi
val process : + (module PROCESS with type t = 't and type tag = 'tag) -> + ('t, 'tag ty) Resource.handler
module type MGR = sig ... end
type Resource.pi +=
| Mgr : ('t, (module MGR with type t = 't and type tag = 'tag), [> 'tag mgr_ty ]) + Resource.pi
val mgr : + (module MGR with type t = 't and type tag = 'tag) -> + ('t, 'tag mgr_ty) Resource.handler
MGR (eio.Eio.Process.Pi.MGR) Module type
Pi.MGR
\ No newline at end of file diff --git a/eio/Eio/Process/Pi/module-type-PROCESS/index.html b/eio/Eio/Process/Pi/module-type-PROCESS/index.html new file mode 100644 index 000000000..fda21ed49 --- /dev/null +++ b/eio/Eio/Process/Pi/module-type-PROCESS/index.html @@ -0,0 +1,2 @@ + +val pipe : + t -> + sw:Switch.t -> + [ Flow.source_ty | Resource.close_ty ] Std.r + * [ Flow.sink_ty | Resource.close_ty ] Std.r
val spawn : + t -> + sw:Switch.t -> + ?cwd:Fs.dir_ty Path.t -> + ?stdin:Flow.source_ty Std.r -> + ?stdout:Flow.sink_ty Std.r -> + ?stderr:Flow.sink_ty Std.r -> + ?env:string array -> + ?executable:string -> + string list -> + tag ty Std.r
PROCESS (eio.Eio.Process.Pi.PROCESS) \ No newline at end of file diff --git a/eio/Eio/Process/class-mgr/index.html b/eio/Eio/Process/class-mgr/index.html deleted file mode 100644 index 32692e310..000000000 --- a/eio/Eio/Process/class-mgr/index.html +++ /dev/null @@ -1,14 +0,0 @@ - - Module type
Pi.PROCESS
mgr (eio.Eio.Process.mgr) Class
Process.mgr
A process manager capable of spawning new processes.
\ No newline at end of file diff --git a/eio/Eio/Process/class-t/index.html b/eio/Eio/Process/class-t/index.html deleted file mode 100644 index 70121db98..000000000 --- a/eio/Eio/Process/class-t/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -method virtual spawn : sw:Eio__core.Switch.t -> - ?cwd:Eio__.Fs.dir Eio__.Path.t -> - ?stdin:Eio__.Flow.source -> - ?stdout:Eio__.Flow.sink -> - ?stderr:Eio__.Flow.sink -> - ?env:string array -> - ?executable:string -> - string list -> - t
t (eio.Eio.Process.t) \ No newline at end of file diff --git a/eio/Eio/Process/index.html b/eio/Eio/Process/index.html index e6b3bcfb3..ad5c57fd6 100644 --- a/eio/Eio/Process/index.html +++ b/eio/Eio/Process/index.html @@ -1,35 +1,38 @@ - Class
Process.t
A process.
Process (eio.Eio.Process) Module
Eio.Process
Managing child processes.
Example:
# Eio_main.run @@ fun env -> +
Process (eio.Eio.Process) Module
Eio.Process
Managing child processes.
Example:
# Eio_main.run @@ fun env -> let proc_mgr = Eio.Stdenv.process_mgr env in - Eio.Process.parse_out proc_mgr Eio.Buf_read.line ["echo"; "hello"]
\ No newline at end of file diff --git a/eio/Eio/Promise/index.html b/eio/Eio/Promise/index.html index 305d8bc9e..54828f0fd 100644 --- a/eio/Eio/Promise/index.html +++ b/eio/Eio/Promise/index.html @@ -1,5 +1,5 @@ -Status and error types
type status = [
|
exit_status
|
`Stopped of int
(*Process was stopped (paused) by the given signal.
*)]
val pp_status : [< status ] Fmt.t
type error =
| Executable_not_found of string
(*The requested executable does not exist.
*)| Child_error of exit_status
(*The process exited with an error status.
*)val err : error -> exn
err e
isEio.Exn.create (E e)
Formats a list of arguments, quoting any that might cause confusion to the reader.
This is intended for use in error messages and logging.
Processes
class virtual t : object ... end
A process.
val pid : t -> int
pid t
is the process ID oft
.val await : t -> exit_status
await t
waits for processt
to exit and then reports the status.val signal : t -> int -> unit
signal t i
sends the signali
to processt
.If the process has already exited then this does nothing (it will not signal a different process, even if the PID has been reused).
See
Sys
for the signal numbers.Spawning processes
class virtual mgr : object ... end
A process manager capable of spawning new processes.
val spawn : + Eio.Process.parse_out proc_mgr Eio.Buf_read.line ["echo"; "hello"]
\ No newline at end of file + _ mgr -> + [ Flow.source_ty | Resource.close_ty ] Std.r + * [ Flow.sink_ty | Resource.close_ty ] Std.rStatus and error types
type status = [
|
exit_status
|
`Stopped of int
(*Process was stopped (paused) by the given signal.
*)]
val pp_status : [< status ] Fmt.t
type error =
| Executable_not_found of string
(*The requested executable does not exist.
*)| Child_error of exit_status
(*The process exited with an error status.
*)val err : error -> exn
err e
isEio.Exn.create (E e)
Formats a list of arguments, quoting any that might cause confusion to the reader.
This is intended for use in error messages and logging.
Types
A process manager capable of spawning new processes.
Processes
val pid : _ t -> int
pid t
is the process ID oft
.val await : _ t -> exit_status
await t
waits for processt
to exit and then reports the status.val await_exn : ?is_success:(int -> bool) -> _ t -> unit
Like
await
except an exception is raised if does not return a successful exit status.val signal : _ t -> int -> unit
signal t i
sends the signali
to processt
.If the process has already exited then this does nothing (it will not signal a different process, even if the PID has been reused).
See
Sys
for the signal numbers.val spawn : sw:Switch.t -> - mgr -> - ?cwd:Fs.dir Path.t -> - ?stdin:Flow.source -> - ?stdout:Flow.sink -> - ?stderr:Flow.sink -> + [> 'tag mgr_ty ] Std.r -> + ?cwd:Fs.dir_ty Path.t -> + ?stdin:_ Flow.source -> + ?stdout:_ Flow.sink -> + ?stderr:_ Flow.sink -> ?env:string array -> ?executable:string -> string list -> - t
spawn ~sw mgr args
creates a new child process that is connected to the switchsw
.The child process will be sent
Sys
.sigkill when the switch is released.If the flows
stdin
,stdout
andstderr
are not backed by file descriptors then this also creates pipes and spawns fibers to copy the data as necessary. If you need more control over file descriptors, seeEio_unix.Process
.val run : - mgr -> - ?cwd:Fs.dir Path.t -> - ?stdin:Flow.source -> - ?stdout:Flow.sink -> - ?stderr:Flow.sink -> + 'tag ty Std.r
spawn ~sw mgr args
creates a new child process that is connected to the switchsw
.The child process will be sent
Sys
.sigkill when the switch is released.If the flows
stdin
,stdout
andstderr
are not backed by file descriptors then this also creates pipes and spawns fibers to copy the data as necessary. If you need more control over file descriptors, seeEio_unix.Process
.val run : + _ mgr -> + ?cwd:_ Path.t -> + ?stdin:_ Flow.source -> + ?stdout:_ Flow.sink -> + ?stderr:_ Flow.sink -> + ?is_success:(int -> bool) -> ?env:string array -> ?executable:string -> string list -> - unit
val parse_out : - mgr -> + unit
run
doesspawn
followed byawait_exn
, with the advantage that if the process fails then the error message includes the command that failed.When
is_success
is provided, it is called with the exit code to determine whether it indicates success or failure. Withoutis_success
, success requires the process to return an exit code of 0.Note: If
spawn
needed to create extra fibers to copystdin
, etc, then it also waits for those to finish.val parse_out : + _ mgr -> 'a Buf_read.parser -> - ?cwd:Fs.dir Path.t -> - ?stdin:Flow.source -> - ?stderr:Flow.sink -> + ?cwd:_ Path.t -> + ?stdin:_ Flow.source -> + ?stderr:_ Flow.sink -> + ?is_success:(int -> bool) -> ?env:string array -> ?executable:string -> string list -> 'a
parse_out mgr parser args
runsargs
and parses the child's stdout withparser
.It also waits for the process to finish and checks its exit status is zero.
Note that
parser
must consume the entire output of the process (likeBuf_read.parse
).To return all the output as a string, use
Buf_read.take_all
as the parser.This is a convenience wrapper around
run
, and the optional arguments have the same meanings.Pipes
val pipe : sw:Switch.t -> - mgr -> - < Flow.source ; Flow.close > * < Flow.sink ; Flow.close >
pipe ~sw mgr
creates a pipe backed by the OS.The flows can be used by
spawn
without the need for extra fibers to copy the data. This can be used to connect multiple processes together.
pipe ~sw mgr
creates a pipe backed by the OS.The flows can be used by
spawn
without the need for extra fibers to copy the data. This can be used to connect multiple processes together.module Pi : sig ... end
Promise (eio.Eio.Promise) Module
Eio.Promise
A promise is a placeholder for result that will arrive in the future.
Unlike lazy values, you cannot "force" promises; a promise is resolved when the maker of the promise is ready.
Promises are thread-safe and so can be shared between domains and used to communicate between them.
Example:
let promise, resolver = Promise.create () in +
Promise (eio.Eio.Promise) Module
Eio.Promise
A promise is a placeholder for result that will arrive in the future.
Unlike lazy values, you cannot "force" promises; a promise is resolved when the maker of the promise is ready.
Promises are thread-safe and so can be shared between domains and used to communicate between them.
Example:
let promise, resolver = Promise.create () in Fiber.both (fun () -> traceln "Got %d" (Promise.await promise)) (fun () -> Promise.resolve resolver 42)
\ No newline at end of file diff --git a/eio/Eio/Resource/index.html b/eio/Eio/Resource/index.html new file mode 100644 index 000000000..d6e30b60c --- /dev/null +++ b/eio/Eio/Resource/index.html @@ -0,0 +1,8 @@ + +
create ()
is a fresh promise/resolver pair. The promise is initially unresolved.val create_resolved : 'a -> 'a t
create_resolved x
is a promise that is already resolved with resultx
.val await : 'a t -> 'a
await t
blocks untilt
is resolved. Ift
is already resolved then this returns immediately.val resolve : 'a u -> 'a -> unit
resolve u v
resolvesu
's promise with the valuev
. Any threads waiting for the result will be added to the run queue.val peek : 'a t -> 'a option
peek t
isSome v
if the promise has been resolved tov
, orNone
otherwise. If the result isNone
then it may change in future, otherwise it won't. If another domain has access to the resolver then the state may have already changed by the time this call returns.val is_resolved : 'a t -> bool
is_resolved t
isOption.is_some (peek t)
.Result promises
type 'a or_exn = ('a, exn) Stdlib.result t
val resolve_ok : ('a, 'b) Stdlib.result u -> 'a -> unit
resolve_ok u x
isresolve u (Ok x)
.val resolve_error : ('a, 'b) Stdlib.result u -> 'b -> unit
resolve_error u x
isresolve u (Error x)
.val await_exn : 'a or_exn -> 'a
await_exn t
is likeawait t
, but if the result isError ex
then it raisesex
.Resource (eio.Eio.Resource) Module
Eio.Resource
Defines the base resource type.
Resources are typically operating-system provided resources such as open files and network sockets. However, they can also be pure OCaml resources (such as mocks) or wrappers (such as an encrypted flow that wraps an unencrypted OS flow).
A resource's type shows which interfaces it supports. For example, a
[source | sink] t
is a resource that can be used as a source or a sink.If you are familiar with object types, this is roughly equivalent to the type
<source; sink>
. We avoid using object types here as some OCaml programmers find them confusing.\ No newline at end of file diff --git a/eio/Eio/Semaphore/index.html b/eio/Eio/Semaphore/index.html index 1a90b09c5..d55e65342 100644 --- a/eio/Eio/Semaphore/index.html +++ b/eio/Eio/Semaphore/index.html @@ -1,2 +1,2 @@ -Types
A
('t, 'tags) handler
can be used to look up the implementation for a type't
.
'tags
is a phantom type to record which interfaces are supported.Internally, a handler is a set of
binding
s.A resource is a pair of a value and a handler for it.
Normally there will be convenience functions provided for using resources and you will not need to match on
T
yourself except when defining a new interface.Defining new interfaces
These types and functions can be used to define new interfaces that others can implement.
When defining a new interface, you will typically provide:
- The tags that indicate that the interface is supported (e.g.
Flow.source_ty
).- A convenience type to match all sub-types easily (e.g.
Flow.source
).- Functions allowing users to call the interface (e.g.
Flow.single_read
).- A module to let providers implement the interface (e.g.
Flow.Pi
).A provider interface describes an interface that a resource can implement.
't
is the type of the resource itself.'iface
is the API that can be requested.'tag
is the tag (or tags) indicating that the interface is supported.For example, the value
Close
(of type(fd, fd -> unit, [> `Close]) pi
) can be used with a resource backed by anfd
, and which offers at least the`Close
tag, to request its close function. Often, the API requested will be a module type, but it can be a single function as in this example.A binding
H (pi, impl)
says to useimpl
to implementpi
.For example:
H (Close, M.close)
.
handler ops
is a handler that looks up interfaces using the assoc listops
.For example
shutdown (module Foo)
is a handler that handles theClose
andShutdown
interfaces for resources of typeFoo.t
by using theFoo
module:let shutdown (type t) (module X : SHUTDOWN with type t = t) : (t, shutdown_ty) handler = + handler [ + H (Close, X.close); + H (Shutdown, (module X)); + ]
Be sure to give the return type explicitly, as this cannot be inferred.
bindings (handler ops) = ops
.This is useful if you want to extend an interface and you already have a handler for that interface.
get handler iface
useshandler
to get the implementation ofiface
.For example:
let write (Resource.T (t, ops)) bufs = + let module X = (val (Resource.get ops Sink)) in + X.write t bufs
get_opt
is likeget
, but the handler need not have a compatible type. Instead, this performs a check at runtime and returnsNone
if the interface is not supported.Closing
Resources are usually attached to switches and closed automatically when the switch finishes. However, it can be useful to close them sooner in some cases.
close t
marks the resource as closed. It can no longer be used after this.If
t
is already closed then this does nothing (it does not raise an exception).Note: if an operation is currently in progress when this is called then it is not necessarily cancelled, and any underlying OS resource (such as a file descriptor) might not be closed immediately if other operations are using it. Closing a resource only prevents new operations from starting.
Semaphore (eio.Eio.Semaphore) Module
Eio.Semaphore
A counting semaphore.
The API is based on OCaml's
Semaphore.Counting
.The difference is that when waiting for the semaphore this will switch to the next runnable fiber, whereas the stdlib one will block the whole domain.
Semaphores are thread-safe and so can be shared between domains and used to synchronise between them.
\ No newline at end of file +val make : int -> t
make n
returns a new counting semaphore, with initial valuen
. The initial valuen
must be nonnegative.val release : t -> unit
release t
increments the value of semaphoret
. If other fibers are waiting ont
, the one that has been waiting the longest is resumed.val acquire : t -> unit
acquire t
blocks the calling fiber until the value of semaphoret
is not zero, then atomically decrements the value oft
and returns.val get_value : t -> int
get_value t
returns the current value of semaphoret
.Semaphore (eio.Eio.Semaphore) Module
Eio.Semaphore
A counting semaphore.
The API is based on OCaml's
Semaphore.Counting
.The difference is that when waiting for the semaphore this will switch to the next runnable fiber, whereas the stdlib one will block the whole domain.
Semaphores are thread-safe and so can be shared between domains and used to synchronise between them.
\ No newline at end of file diff --git a/eio/Eio/Std/index.html b/eio/Eio/Std/index.html index 47c3a4228..9e07dbd2f 100644 --- a/eio/Eio/Std/index.html +++ b/eio/Eio/Std/index.html @@ -1,5 +1,5 @@ -val make : int -> t
make n
returns a new counting semaphore, with initial valuen
. The initial valuen
must be nonnegative.val release : t -> unit
release t
increments the value of semaphoret
. If other fibers are waiting ont
, the one that has been waiting the longest is resumed.val acquire : t -> unit
acquire t
blocks the calling fiber until the value of semaphoret
is not zero, then atomically decrements the value oft
and returns.val get_value : t -> int
get_value t
returns the current value of semaphoret
.Std (eio.Eio.Std) Module
Eio.Std
Commonly used standard features. This module is intended to be
open
ed.module Promise = Promise
module Fiber = Fiber
module Switch = Switch
val traceln : +
Std (eio.Eio.Std) Module
Eio.Std
Commonly used standard features. This module is intended to be
open
ed.\ No newline at end of file diff --git a/eio/Eio/Stdenv/index.html b/eio/Eio/Stdenv/index.html index ca7cd420f..56a3a3df5 100644 --- a/eio/Eio/Stdenv/index.html +++ b/eio/Eio/Stdenv/index.html @@ -1,6 +1,6 @@ -module Promise = Promise
module Fiber = Fiber
module Switch = Switch
type 'a r = 'a Resource.t
val traceln : ?__POS__:(string * int * int * int) -> ('a, Stdlib.Format.formatter, unit, unit) Stdlib.format4 -> 'a
Same as
Eio.traceln
.Stdenv (eio.Eio.Stdenv) Module
Eio.Stdenv
The standard environment of a process.
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 () = +
Stdenv (eio.Eio.Stdenv) Module
Eio.Stdenv
The standard environment of a process.
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
\ No newline at end of file + ~net:env#netStandard 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
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.Network
To use this, see
Net
.val net : < net : Net.t as 'a.. > -> 'a
net t
gives access to the process's network namespace.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.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.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).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.Debugging
val debug : < debug : < Debug.t.. > as 'a.. > -> 'a
debug t
provides privileged controls for debugging.\ No newline at end of file diff --git a/eio/Eio/Stream/index.html b/eio/Eio/Stream/index.html index 26965e624..bfcb6c8ef 100644 --- a/eio/Eio/Stream/index.html +++ b/eio/Eio/Stream/index.html @@ -1,5 +1,5 @@ -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
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.Network
To use this, see
Net
.val net : < net : _ Net.t as 'a.. > -> 'a
net t
gives access to the process's network namespace.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.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.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).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.Debugging
val debug : < debug : < Debug.t.. > as 'a.. > -> 'a
debug t
provides privileged controls for debugging.Stream (eio.Eio.Stream) Module
Eio.Stream
A stream/queue.
Reading from an empty queue will wait until an item is available. Writing to a full queue will wait until there is space.
Example:
let t = Stream.create 100 in +
Stream (eio.Eio.Stream) Module
Eio.Stream
A stream/queue.
Reading from an empty queue will wait until an item is available. Writing to a full queue will wait until there is space.
Example:
let t = Stream.create 100 in Stream.add t 1; Stream.add t 2; assert (Stream.take t = 1); diff --git a/eio/Eio/Switch/index.html b/eio/Eio/Switch/index.html index fa776274e..e75470369 100644 --- a/eio/Eio/Switch/index.html +++ b/eio/Eio/Switch/index.html @@ -1,5 +1,5 @@ -
Switch (eio.Eio.Switch) Module
Eio.Switch
Grouping fibers and other resources so they can be turned off together.
Many resources in Eio (such as fibers and file handles) require a switch to be provided when they are created. The resource cannot outlive its switch.
If a function wants to create such resources, and was not passed a switch as an argument, it will need to create a switch using
run
. This doesn't return until all resources attached to it have been freed, preventing the function from leaking resources.Any function creating resources that outlive it needs to be given a switch by its caller.
Each switch includes its own
Cancel.t
context. Callingfail
cancels all fibers attached to the switch and, once they have exited, reports the error.Note: this concept is known as a "nursery" or "bundle" in some other systems.
Example:
Switch.run (fun sw -> +
Switch (eio.Eio.Switch) Module
Eio.Switch
Grouping fibers and other resources so they can be turned off together.
Many resources in Eio (such as fibers and file handles) require a switch to be provided when they are created. The resource cannot outlive its switch.
If a function wants to create such resources, and was not passed a switch as an argument, it will need to create a switch using
run
. This doesn't return until all resources attached to it have been freed, preventing the function from leaking resources.Any function creating resources that outlive it needs to be given a switch by its caller.
Each switch includes its own
Cancel.t
context. Callingfail
cancels all fibers attached to the switch and, once they have exited, reports the error.Note: this concept is known as a "nursery" or "bundle" in some other systems.
Example:
Switch.run (fun sw -> let flow = Dir.open_in ~sw dir "myfile.txt" in ... ); diff --git a/eio/Eio/Time/Mono/class-t/index.html b/eio/Eio/Time/Mono/class-t/index.html deleted file mode 100644 index f41df0c58..000000000 --- a/eio/Eio/Time/Mono/class-t/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -
t (eio.Eio.Time.Mono.t) Class
Mono.t
\ No newline at end of file diff --git a/eio/Eio/Time/Mono/index.html b/eio/Eio/Time/Mono/index.html index 1fec46554..8dc715418 100644 --- a/eio/Eio/Time/Mono/index.html +++ b/eio/Eio/Time/Mono/index.html @@ -1,2 +1,2 @@ -inherit Mtime.t clock_base
Mono (eio.Eio.Time.Mono) Module
Time.Mono
Monotonic clocks.
Monotonic clocks are unaffected by corrections to the real-time clock, and so are a better choice for timeouts or measuring intervals, where the absolute time doesn't matter.
A monotonic clock may or may not include time while the computer is suspended.
\ No newline at end of file +class virtual t : object ... end
val now : t -> Mtime.t
now t
is the current time according tot
.val sleep_until : t -> Mtime.t -> unit
sleep_until t time
waits untiltime
before returning.val sleep : t -> float -> unit
sleep t d
waits ford
seconds.val sleep_span : t -> Mtime.span -> unit
sleep_span t d
waits for durationd
.Mono (eio.Eio.Time.Mono) Module
Time.Mono
Monotonic clocks.
Monotonic clocks are unaffected by corrections to the real-time clock, and so are a better choice for timeouts or measuring intervals, where the absolute time doesn't matter.
A monotonic clock may or may not include time while the computer is suspended.
\ No newline at end of file diff --git a/eio/Eio/Time/Pi/index.html b/eio/Eio/Time/Pi/index.html new file mode 100644 index 000000000..8ce74fda2 --- /dev/null +++ b/eio/Eio/Time/Pi/index.html @@ -0,0 +1,9 @@ + +type ty = Mtime.t clock_ty
val now : _ t -> Mtime.t
now t
is the current time according tot
.val sleep_until : _ t -> Mtime.t -> unit
sleep_until t time
waits untiltime
before returning.val sleep : _ t -> float -> unit
sleep t d
waits ford
seconds.val sleep_span : _ t -> Mtime.span -> unit
sleep_span t d
waits for durationd
.Pi (eio.Eio.Time.Pi) Module
Time.Pi
\ No newline at end of file diff --git a/eio/Eio/Time/Pi/module-type-CLOCK/index.html b/eio/Eio/Time/Pi/module-type-CLOCK/index.html new file mode 100644 index 000000000..d69ec7d28 --- /dev/null +++ b/eio/Eio/Time/Pi/module-type-CLOCK/index.html @@ -0,0 +1,2 @@ + +module type CLOCK = sig ... end
type Resource.pi +=
| Clock : ('t, + (module CLOCK + with type t = 't + and type time = 'time), + [> 'time clock_ty ]) + Resource.pi
val clock : + (module CLOCK with type t = 't and type time = 'time) -> + ('t, [> 'time clock_ty ]) Resource.handler
CLOCK (eio.Eio.Time.Pi.CLOCK) \ No newline at end of file diff --git a/eio/Eio/Time/Timeout/index.html b/eio/Eio/Time/Timeout/index.html index 52138fc0e..3efe617f1 100644 --- a/eio/Eio/Time/Timeout/index.html +++ b/eio/Eio/Time/Timeout/index.html @@ -1,5 +1,5 @@ - Module type
Pi.CLOCK
Timeout (eio.Eio.Time.Timeout) Module
Time.Timeout
Timeout values.
v clock duration
is a timeout ofduration
, as measured byclock
. Internally, this is just the tuple(clock, duration)
.
seconds clock duration
is a timeout ofduration
seconds, as measured byclock
.val none : t
none
is an infinite timeout.val run : +
Timeout (eio.Eio.Time.Timeout) Module
Time.Timeout
Timeout values.
\ No newline at end of file diff --git a/eio/Eio/Time/class-clock/index.html b/eio/Eio/Time/class-clock/index.html deleted file mode 100644 index 545898d0a..000000000 --- a/eio/Eio/Time/class-clock/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -
v clock duration
is a timeout ofduration
, as measured byclock
. Internally, this is just the tuple(clock, duration)
.
seconds clock duration
is a timeout ofduration
seconds, as measured byclock
.val none : t
none
is an infinite timeout.val run : t -> (unit -> ('a, 'e) Stdlib.result) -> ('a, [> `Timeout ] as 'e) Stdlib.result
run t fn
runsfn ()
but cancels it if it takes longer than allowed by timeoutt
.val run_exn : t -> (unit -> 'a) -> 'a
run_exn t fn
runsfn ()
but cancels it if it takes longer than allowed by timeoutt
, raising exceptionTimeout
.val pp : t Fmt.t
pp
formats a timeout as a duration (e.g. "5s"). This is intended for use in error messages and logging and is rounded.clock (eio.Eio.Time.clock) Class
Time.clock
\ No newline at end of file diff --git a/eio/Eio/Time/class-clock_base/index.html b/eio/Eio/Time/class-clock_base/index.html deleted file mode 100644 index e67320031..000000000 --- a/eio/Eio/Time/class-clock_base/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -inherit float clock_base
clock_base (eio.Eio.Time.clock_base) \ No newline at end of file diff --git a/eio/Eio/Time/index.html b/eio/Eio/Time/index.html index b775d47aa..8c9096a35 100644 --- a/eio/Eio/Time/index.html +++ b/eio/Eio/Time/index.html @@ -1,6 +1,6 @@ - Class
Time.clock_base
Time (eio.Eio.Time) Module
Eio.Time
Clocks, time, sleeping and timeouts.
\ No newline at end of file diff --git a/eio/Eio/index.html b/eio/Eio/index.html index 669a958eb..a69f4f28f 100644 --- a/eio/Eio/index.html +++ b/eio/Eio/index.html @@ -1,5 +1,5 @@ -class virtual 'a clock_base : object ... end
class virtual clock : object ... end
val now : clock -> float
now t
is the current time since 00:00:00 GMT, Jan. 1, 1970 - in seconds - according tot
.val sleep_until : clock -> float -> unit
sleep_until t time
waits until the given time is reached.val sleep : clock -> float -> unit
sleep t d
waits ford
seconds.module Mono : sig ... end
Monotonic clocks.
Timeouts
val with_timeout : - clock -> +
Time (eio.Eio.Time) Module
Eio.Time
Clocks, time, sleeping and timeouts.
\ No newline at end of file + ('a, [> `Timeout ] as 'e) Stdlib.resultval now : _ clock -> float
now t
is the current time since 00:00:00 GMT, Jan. 1, 1970 - in seconds - according tot
.val sleep_until : _ clock -> float -> unit
sleep_until t time
waits until the given time is reached.val sleep : _ clock -> float -> unit
sleep t d
waits ford
seconds.module Mono : sig ... end
Monotonic clocks.
Timeouts
val with_timeout : + _ clock -> float -> (unit -> ('a, 'e) Stdlib.result) -> - ('a, [> `Timeout ] as 'e) Stdlib.result
with_timeout clock d fn
runsfn ()
but cancels it afterd
seconds.val with_timeout_exn : clock -> float -> (unit -> 'a) -> 'a
with_timeout_exn clock d fn
runsfn ()
but cancels it afterd
seconds, raising exceptionTimeout
.module Timeout : sig ... end
Timeout values.
with_timeout clock d fn
runsfn ()
but cancels it afterd
seconds.val with_timeout_exn : _ clock -> float -> (unit -> 'a) -> 'a
with_timeout_exn clock d fn
runsfn ()
but cancels it afterd
seconds, raising exceptionTimeout
.module Timeout : sig ... end
Timeout values.
module Pi : sig ... end
Eio (eio.Eio) Module
Eio
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 event loop, provided by an Eio backend. Applications can use
Eio_main
.run to run a suitable loop.See https://github.com/ocaml-multicore/eio for a tutorial.
Concurrency primitives
module Switch : sig ... end
Grouping fibers and other resources so they can be turned off together.
module Promise : sig ... end
A promise is a placeholder for result that will arrive in the future.
module Fiber : sig ... end
A fiber is a light-weight thread.
module Semaphore : sig ... end
A counting semaphore.
module Mutex : sig ... end
Mutual exclusion.
module Condition : sig ... end
Waiting for a condition to become true.
module Stream : sig ... end
A stream/queue.
module Cancel : sig ... end
Cancelling fibers.
module Std : sig ... end
Commonly used standard features. This module is intended to be
open
ed.Cross-platform OS API
The general pattern here is that each type of resource has a set of functions for using it, plus an object type to allow defining your own implementations. To use the resources, it is recommended that you use the functions rather than calling methods directly. Using the functions results in better error messages from the compiler, and may provide extra features or sanity checks.
The system resources are available from the environment argument provided by your event loop (e.g.
Eio_main
.run).module Generic : sig ... end
A base class for objects that can be queried at runtime for extra features.
module Flow : sig ... end
Byte streams.
module Buf_read : sig ... end
Buffered input and parsing
module Buf_write : sig ... end
Buffered output
module Net : sig ... end
Networking.
module Process : sig ... end
Managing child processes.
module Domain_manager : sig ... end
Parallel computation across multiple CPU cores.
module Time : sig ... end
Clocks, time, sleeping and timeouts.
module File : sig ... end
Operations on open files.
module Fs : sig ... end
File-system types.
module Path : sig ... end
Accessing paths on a file-system.
module Debug : sig ... end
Control over debugging.
module Stdenv : sig ... end
The standard environment of a process.
Errors and Debugging
exception Io of Exn.err * Exn.context
val traceln : +
Eio (eio.Eio) Module
Eio
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 event loop, provided by an Eio backend. Applications can use
Eio_main
.run to run a suitable loop.See https://github.com/ocaml-multicore/eio for a tutorial.
Concurrency primitives
module Switch : sig ... end
Grouping fibers and other resources so they can be turned off together.
module Promise : sig ... end
A promise is a placeholder for result that will arrive in the future.
module Fiber : sig ... end
A fiber is a light-weight thread.
module Semaphore : sig ... end
A counting semaphore.
module Mutex : sig ... end
Mutual exclusion.
module Condition : sig ... end
Waiting for a condition to become true.
module Stream : sig ... end
A stream/queue.
module Lazy : sig ... end
Delayed evaluation.
module Pool : sig ... end
A pool of resources.
module Cancel : sig ... end
Cancelling fibers.
module Std : sig ... end
Commonly used standard features. This module is intended to be
open
ed.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).module Resource : sig ... end
Defines the base resource type.
module Flow : sig ... end
Byte streams.
module Buf_read : sig ... end
Buffered input and parsing
module Buf_write : sig ... end
Buffered output
module Net : sig ... end
Networking.
module Process : sig ... end
Managing child processes.
module Domain_manager : sig ... end
Parallel computation across multiple CPU cores.
module Time : sig ... end
Clocks, time, sleeping and timeouts.
module File : sig ... end
Operations on open files.
module Fs : sig ... end
File-system types.
module Path : sig ... end
Accessing paths on a file-system.
module Debug : sig ... end
Control over debugging.
module Stdenv : sig ... end
The standard environment of a process.
Errors and Debugging
exception Io of Exn.err * Exn.context
val traceln : ?__POS__:(string * int * int * int) -> ('a, Stdlib.Format.formatter, unit, unit) Stdlib.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; diff --git a/eio/Eio__core/.dummy b/eio/Eio__core/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/eio/Eio__core/index.html b/eio/Eio__core/index.html index 859a888c1..5c00bc83f 100644 --- a/eio/Eio__core/index.html +++ b/eio/Eio__core/index.html @@ -1,2 +1,2 @@ -
Eio__core (eio.Eio__core) \ No newline at end of file + Module
Eio__core
Eio__core (eio.Eio__core) \ No newline at end of file diff --git a/eio/Eio_mock/.dummy b/eio/Eio_mock/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/eio/Eio_mock/Action/index.html b/eio/Eio_mock/Action/index.html index 86d15fff1..5d2775cd2 100644 --- a/eio/Eio_mock/Action/index.html +++ b/eio/Eio_mock/Action/index.html @@ -1,2 +1,2 @@ - Module
Eio__core
Action (eio.Eio_mock.Action) Module
Eio_mock.Action
Actions that can be performed by mock handlers.
\ No newline at end of file +type 'a t = [
|
`Return of 'a
(*Immediately return a value
*)|
`Raise of exn
(*Raise an exception
*)|
`Await of 'a Eio.Promise.or_exn
(*Wait for a promise to resolve
*)|
`Yield_then of 'a t
|
`Run of unit -> 'a
(*Run any code you like.
*)]
val run : 'a t -> 'a
run t
performs actiont
and returns the result.Action (eio.Eio_mock.Action) Module
Eio_mock.Action
Actions that can be performed by mock handlers.
\ No newline at end of file diff --git a/eio/Eio_mock/Backend/index.html b/eio/Eio_mock/Backend/index.html index 2148112bd..61a86c35e 100644 --- a/eio/Eio_mock/Backend/index.html +++ b/eio/Eio_mock/Backend/index.html @@ -1,2 +1,2 @@ -type 'a t = [
|
`Return of 'a
(*Immediately return a value
*)|
`Raise of exn
(*Raise an exception
*)|
`Await of 'a Eio.Promise.or_exn
(*Wait for a promise to resolve
*)|
`Yield_then of 'a t
|
`Run of unit -> 'a
(*Run any code you like.
*)]
val run : 'a t -> 'a
run t
performs actiont
and returns the result.Backend (eio.Eio_mock.Backend) Module
Eio_mock.Backend
A dummy Eio backend with no actual IO.
This backend does not support the use of multiple domains or systhreads, but the tradeoff is that it can reliably detect deadlock, because if the run queue is empty then it knows that no wake up event can be coming from elsewhere.
\ No newline at end of file +Backend (eio.Eio_mock.Backend) Module
Eio_mock.Backend
A dummy Eio backend with no actual IO.
This backend does not support the use of multiple domains or systhreads, but the tradeoff is that it can reliably detect deadlock, because if the run queue is empty then it knows that no wake up event can be coming from elsewhere.
\ No newline at end of file diff --git a/eio/Eio_mock/Clock/Mono/index.html b/eio/Eio_mock/Clock/Mono/index.html index 64034f52c..e2fe0ba33 100644 --- a/eio/Eio_mock/Clock/Mono/index.html +++ b/eio/Eio_mock/Clock/Mono/index.html @@ -1,5 +1,2 @@ -Mono (eio.Eio_mock.Clock.Mono) Module
Clock.Mono
\ No newline at end of file +type t = - < Mtime.t Eio.Time.clock_base - ; advance : unit - ; set_time : Mtime.t -> unit >
val make : unit -> t
val advance : t -> unit
advance t
sets the time to the next scheduled event (adding any due fibers to the run queue).val set_time : t -> Mtime.t -> unit
set_time t time
sets the time totime
(adding any due fibers to the run queue).Mono (eio.Eio_mock.Clock.Mono) Module
Clock.Mono
\ No newline at end of file diff --git a/eio/Eio_mock/Clock/index.html b/eio/Eio_mock/Clock/index.html index 7e8b62cdc..82e6bd1da 100644 --- a/eio/Eio_mock/Clock/index.html +++ b/eio/Eio_mock/Clock/index.html @@ -1,5 +1,2 @@ -val make : unit -> t
val advance : t -> unit
advance t
sets the time to the next scheduled event (adding any due fibers to the run queue).val set_time : t -> Mtime.t -> unit
set_time t time
sets the time totime
(adding any due fibers to the run queue).Clock (eio.Eio_mock.Clock) Module
Eio_mock.Clock
A mock
Eio.Time
clock for testing timeouts.\ No newline at end of file +module type S = sig ... end
include S with type time := float
type t = - < float Eio.Time.clock_base - ; advance : unit - ; set_time : float -> unit >
val make : unit -> t
val advance : t -> unit
advance t
sets the time to the next scheduled event (adding any due fibers to the run queue).val set_time : t -> float -> unit
set_time t time
sets the time totime
(adding any due fibers to the run queue).Clock (eio.Eio_mock.Clock) Module
Eio_mock.Clock
A mock
Eio.Time
clock for testing timeouts.\ No newline at end of file diff --git a/eio/Eio_mock/Clock/module-type-S/index.html b/eio/Eio_mock/Clock/module-type-S/index.html index 59cd5d8df..c60e94e62 100644 --- a/eio/Eio_mock/Clock/module-type-S/index.html +++ b/eio/Eio_mock/Clock/module-type-S/index.html @@ -1,5 +1,2 @@ -module type S = sig ... end
S (eio.Eio_mock.Clock.S) Module type
Clock.S
\ No newline at end of file +type t = - < time Eio.Time.clock_base - ; advance : unit - ; set_time : time -> unit >
val make : unit -> t
val advance : t -> unit
advance t
sets the time to the next scheduled event (adding any due fibers to the run queue).S (eio.Eio_mock.Clock.S) Module type
Clock.S
\ No newline at end of file diff --git a/eio/Eio_mock/Domain_manager/index.html b/eio/Eio_mock/Domain_manager/index.html new file mode 100644 index 000000000..2d942e885 --- /dev/null +++ b/eio/Eio_mock/Domain_manager/index.html @@ -0,0 +1,2 @@ + +val make : unit -> t
val advance : t -> unit
advance t
sets the time to the next scheduled event (adding any due fibers to the run queue).Domain_manager (eio.Eio_mock.Domain_manager) Module
Eio_mock.Domain_manager
A mock
Eio.Domain_manager
that runs everything in a single domain.\ No newline at end of file diff --git a/eio/Eio_mock/Flow/index.html b/eio/Eio_mock/Flow/index.html index cd4d23535..e07ab140b 100644 --- a/eio/Eio_mock/Flow/index.html +++ b/eio/Eio_mock/Flow/index.html @@ -1,8 +1,2 @@ -val create : unit -> Eio.Domain_manager.ty Eio.Std.r
create ()
is a mock domain manager.When asked to run a new Eio domain, it just runs it in the parent domain. It runs the function in a context where
id
is a fresh domain ID (assigned sequentially starting from 1).val run : (Eio.Domain_manager.ty Eio.Std.r -> 'a) -> 'a
run fn
runsfn dm
, wheredm
is a new fake domain manager. It also runswith_domain_tracing
to display domain IDs in trace output.
fn
itself runs withid
set to "0".val id : string Eio.Std.Fiber.key
id
is used to get or set the current fake domain's ID.This is used in traceln output.
with_domain_tracing fn
runsfn ()
with a modifiedtraceln
function that prefixes the currentid
(if any) to each trace message.Flow (eio.Eio_mock.Flow) Module
Eio_mock.Flow
Mock
Eio.Flow
sources and sinks.\ No newline at end of file +type t = - < Eio.Flow.two_way - ; Eio.Flow.close - ; on_read : string Handler.t - ; on_copy_bytes : int Handler.t - ; set_copy_method : copy_method -> unit - ; attach_to_switch : Eio.Switch.t -> unit >
val make : ?pp:string Fmt.t -> string -> t
make label
is a mock Eio flow. It can be used as a source, sink, or two-way flow.val on_read : t -> string Handler.actions -> unit
on_read t actions
configures the values to return from the mock'sread
function.val on_copy_bytes : t -> int Handler.actions -> unit
on_copy_bytes t actions
configures the number of bytes to copy in each iteration.val set_copy_method : t -> copy_method -> unit
set_copy_method t m
configurest
to use the given method to read from a source during a copy operation.Flow (eio.Eio_mock.Flow) Module
Eio_mock.Flow
Mock
Eio.Flow
sources and sinks.\ No newline at end of file diff --git a/eio/Eio_mock/Handler/index.html b/eio/Eio_mock/Handler/index.html index 7b736ebf6..a6b088b21 100644 --- a/eio/Eio_mock/Handler/index.html +++ b/eio/Eio_mock/Handler/index.html @@ -1,2 +1,2 @@ -type ty = [ `Generic | `Mock ] Eio.Net.stream_socket_ty
val make : ?pp:string Fmt.t -> string -> t
make label
is a mock Eio flow. It can be used as a source, sink, or two-way flow.val on_read : t -> string Handler.actions -> unit
on_read t actions
configures the values to return from the mock'sread
function.val on_copy_bytes : t -> int Handler.actions -> unit
on_copy_bytes t actions
configures the number of bytes to copy in each iteration.val set_copy_method : t -> copy_method -> unit
set_copy_method t m
configurest
to use the given method to read from a source during a copy operation.Handler (eio.Eio_mock.Handler) Module
Eio_mock.Handler
Control how a mock responds.
This module is mostly useful when writing custom mocks. Individual mocks usually provide convenience wrappers around this.
\ No newline at end of file +type 'a actions = 'a Action.t list
make default_action
is a new handler that initially always runsdefault_action
.val set_handler : 'a t -> (unit -> 'a) -> unit
set_handler t fn
sets (replaces) the function to be called whenever the handler is run.
seq t actions
sets a handler function that performs the next action inactions
on each call. When there are no more actions, it runs the default handler.val run : 'a t -> 'a
run t
is used by mocks to run their handlers.Handler (eio.Eio_mock.Handler) Module
Eio_mock.Handler
Control how a mock responds.
This module is mostly useful when writing custom mocks. Individual mocks usually provide convenience wrappers around this.
\ No newline at end of file diff --git a/eio/Eio_mock/Net/index.html b/eio/Eio_mock/Net/index.html index 0e00b0255..0a3b90f66 100644 --- a/eio/Eio_mock/Net/index.html +++ b/eio/Eio_mock/Net/index.html @@ -1,16 +1,6 @@ -type 'a actions = 'a Action.t list
make default_action
is a new handler that initially always runsdefault_action
.val set_handler : 'a t -> (unit -> 'a) -> unit
set_handler t fn
sets (replaces) the function to be called whenever the handler is run.
seq t actions
sets a handler function that performs the next action inactions
on each call. When there are no more actions, it runs the default handler.val run : 'a t -> 'a
run t
is used by mocks to run their handlers.Net (eio.Eio_mock.Net) Module
Eio_mock.Net
Mock
Eio.Net
networks and sockets.type t = - < Eio.Net.t - ; on_listen : Eio.Net.listening_socket Handler.t - ; on_connect : Eio.Net.stream_socket Handler.t - ; on_datagram_socket : Eio.Net.datagram_socket Handler.t - ; on_getaddrinfo : Eio.Net.Sockaddr.t list Handler.t - ; on_getnameinfo : (string * string) Handler.t >
type listening_socket = - < Eio.Net.listening_socket - ; on_accept : (Flow.t * Eio.Net.Sockaddr.stream) Handler.t >
val make : string -> t
make label
is a new mock network.val on_connect : t -> < Eio.Net.stream_socket.. > Handler.actions -> unit
on_connect t actions
configures what to do when a client tries to connect somewhere.val on_listen : t -> Eio.Net.listening_socket Handler.actions -> unit
on_listen t actions
configures what to do when a server starts listening for incoming connections.val on_datagram_socket : - t -> - < Eio.Net.datagram_socket.. > Handler.actions -> - unit
on_datagram_socket t actions
configures how to create datagram sockets.val on_getaddrinfo : t -> Eio.Net.Sockaddr.t list Handler.actions -> unit
val on_getnameinfo : t -> (string * string) Handler.actions -> unit
val listening_socket : string -> listening_socket
listening_socket label
can be configured to provide mock connections.val on_accept : +
Net (eio.Eio_mock.Net) Module
Eio_mock.Net
Mock
Eio.Net
networks and sockets.\ No newline at end of file diff --git a/eio/Eio_mock/index.html b/eio/Eio_mock/index.html index 5ff89acbc..4827edba5 100644 --- a/eio/Eio_mock/index.html +++ b/eio/Eio_mock/index.html @@ -1,5 +1,5 @@ -type t = [ `Generic | `Mock ] Eio.Net.ty Eio.Std.r
type listening_socket = + [ `Generic | `Mock ] Eio.Net.listening_socket_ty Eio.Std.r
val make : string -> t
make label
is a new mock network.val on_connect : t -> _ Eio.Net.stream_socket Handler.actions -> unit
on_connect t actions
configures what to do when a client tries to connect somewhere.val on_listen : t -> _ Eio.Net.listening_socket Handler.actions -> unit
on_listen t actions
configures what to do when a server starts listening for incoming connections.val on_datagram_socket : t -> _ Eio.Net.datagram_socket Handler.actions -> unit
on_datagram_socket t actions
configures how to create datagram sockets.val on_getaddrinfo : t -> Eio.Net.Sockaddr.t list Handler.actions -> unit
val on_getnameinfo : t -> (string * string) Handler.actions -> unit
val listening_socket : string -> listening_socket
listening_socket label
can be configured to provide mock connections.val on_accept : listening_socket -> (Flow.t * Eio.Net.Sockaddr.stream) Handler.actions -> unit
on_accept socket actions
configures how to respond when the server calls "accept".Eio_mock (eio.Eio_mock) Module
Eio_mock
Mocks for testing.
When testing an Eio program it is often convenient to use mock resources rather than real OS-provided ones. This allows precise control over the test, such as adding delays or simulated faults. You can always just implement the various Eio types directly, but this module provides some convenient pre-built mocks, and some helpers for creating your own mocks.
Mocks typically use
Eio.traceln
to record how they were used. This output can be recorded and compared against a known-good copy using e.g. ocaml-mdx.Mocks may require configuration. For example, a source flow needs to know what data to return when the application reads from it. This can be done using the various
on_*
functions. For example:let stdin = Eio_mock.Flow.make "stdin" in +
Eio_mock (eio.Eio_mock) Module
Eio_mock
Mocks for testing.
When testing an Eio program it is often convenient to use mock resources rather than real OS-provided ones. This allows precise control over the test, such as adding delays or simulated faults. You can always just implement the various Eio types directly, but this module provides some convenient pre-built mocks, and some helpers for creating your own mocks.
Mocks typically use
Eio.traceln
to record how they were used. This output can be recorded and compared against a known-good copy using e.g. ocaml-mdx.Mocks may require configuration. For example, a source flow needs to know what data to return when the application reads from it. This can be done using the various
on_*
functions. For example:let stdin = Eio_mock.Flow.make "stdin" in let stdout = Eio_mock.Flow.make "stdout" in Eio_mock.Flow.on_read stdin [ `Return "chunk1"; @@ -9,4 +9,4 @@ Eio.Flow.copy stdin stdout
This will produce:
+stdin: read "chunk1" +stdout: wrote "chunk1" +stdin: read "chunk2" -+stdout: wrote "chunk2"
\ No newline at end of file ++stdout: wrote "chunk2"Configuration
module Action : sig ... end
Actions that can be performed by mock handlers.
module Handler : sig ... end
Control how a mock responds.
Pre-defined mocks
Backend for mocks
The mocks can be used with any backend, but if you don't need any IO then you can use this one to avoid a dependency on eio_main.
module Backend : sig ... end
A dummy Eio backend with no actual IO.
Mock errors
type Eio.Exn.Backend.t +=
\ No newline at end of file diff --git a/eio/Eio_unix/.dummy b/eio/Eio_unix/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/eio/Eio_unix/Ctf/index.html b/eio/Eio_unix/Ctf/index.html index 4d86db698..e08f21c43 100644 --- a/eio/Eio_unix/Ctf/index.html +++ b/eio/Eio_unix/Ctf/index.html @@ -1,2 +1,2 @@ -Configuration
module Action : sig ... end
Actions that can be performed by mock handlers.
module Handler : sig ... end
Control how a mock responds.
Pre-defined mocks
module Domain_manager : sig ... end
A mock
Eio.Domain_manager
that runs everything in a single domain.Backend for mocks
The mocks can be used with any backend, but if you don't need any IO then you can use this one to avoid a dependency on eio_main.
module Backend : sig ... end
A dummy Eio backend with no actual IO.
Mock errors
type Eio.Exn.Backend.t +=
Ctf (eio.Eio_unix.Ctf) Module
Eio_unix.Ctf
\ No newline at end of file +val timestamper : Eio.Private.Ctf.log_buffer -> int -> unit
Uses
Mtime_clock
to write timestamps.val mmap_buffer : size:int -> string -> Eio.Private.Ctf.log_buffer
mmap_buffer ~size path
initialises filepath
as an empty buffer for tracing.
with_tracing path fn
is a convenience function that usesmmap_buffer
to create a log buffer, callsCtf
.Control.start to start recording, runsfn
, and then stops recording.Ctf (eio.Eio_unix.Ctf) Module
Eio_unix.Ctf
\ No newline at end of file diff --git a/eio/Eio_unix/Fd/index.html b/eio/Eio_unix/Fd/index.html index b42cd66b2..d5e89b0cf 100644 --- a/eio/Eio_unix/Fd/index.html +++ b/eio/Eio_unix/Fd/index.html @@ -1,8 +1,8 @@ -val timestamper : Eio.Private.Ctf.log_buffer -> int -> unit
Uses
Mtime_clock
to write timestamps.val mmap_buffer : size:int -> string -> Eio.Private.Ctf.log_buffer
mmap_buffer ~size path
initialises filepath
as an empty buffer for tracing.
with_tracing path fn
is a convenience function that usesmmap_buffer
to create a log buffer, callsCtf
.Control.start to start recording, runsfn
, and then stops recording.Fd (eio.Eio_unix.Fd) Module
Eio_unix.Fd
A safe wrapper for
Unix
.file_descr.\ No newline at end of file diff --git a/eio/Eio_unix/Net/Ipaddr/index.html b/eio/Eio_unix/Net/Ipaddr/index.html index f4fc58cf7..4af0d62be 100644 --- a/eio/Eio_unix/Net/Ipaddr/index.html +++ b/eio/Eio_unix/Net/Ipaddr/index.html @@ -1,2 +1,2 @@ -Creation
val of_unix : +
Fd (eio.Eio_unix.Fd) Module
Eio_unix.Fd
A safe wrapper for
Unix
.file_descr.\ No newline at end of file + tCreation
val of_unix : sw:Eio.Std.Switch.t -> ?blocking:bool -> ?seekable:bool -> close_unix:bool -> Unix.file_descr -> - t
of_unix ~sw ~close_unix fd
wrapsfd
.Using FDs
val use : t -> (Unix.file_descr -> 'a) -> if_closed:(unit -> 'a) -> 'a
use t fn ~if_closed
callsfn wrapped_fd
, ensuring thatwrapped_fd
will not be closed beforefn
returns.If
t
is already closed, it returnsif_closed ()
instead.val use_exn : string -> t -> (Unix.file_descr -> 'a) -> 'a
use_exn op t fn
callsfn wrapped_fd
, ensuring thatwrapped_fd
will not be closed beforefn
returns.If
t
is already closed, it raises an exception, usingop
as the name of the failing operation.val use_exn_list : string -> t list -> (Unix.file_descr list -> 'a) -> 'a
use_exn_list op fds fn
callsuse_exn
on each FD infds
, callingfn wrapped_fds
on the results.Closing
val close : t -> unit
close t
markst
as closed, so thatuse
can no longer be used to start new operations.The wrapped FD will be closed once all current users of the FD have finished (unless
close_unix = false
).Has no effect if
t
is already closed.val remove : t -> Unix.file_descr option
remove t
markst
as closed, so thatuse
can no longer be used to start new operations.It then waits for all current users of the wrapped FD to finish using it, and then returns the FD.
This operation suspends the calling fiber and so must run from an Eio fiber. It does not allow itself to be cancelled, since it takes ownership of the FD and that would be leaked if it aborted.
Returns
None
ift
is closed by another fiber first.Flags
val is_blocking : t -> bool
is_blocking t
returns the value ofblocking
passed toof_unix
.If not known, it first probes for it (and if the FD is already closed, returns
false
).val is_seekable : t -> bool
is_seekable t
returns the value ofseekable
passed toof_unix
.If not known, it first probes for it (and if the FD is already closed, returns
false
).Standard FDs
val stdin : t
val stdout : t
val stderr : t
Printing
val pp : t Fmt.t
Displays the FD number.
of_unix ~sw ~close_unix fd
wrapsfd
.val of_unix_list : sw:Eio.Std.Switch.t -> Unix.file_descr list -> t list
of_unix_list ~sw fds
is likeList.map (of_unix ~sw ~close_unix:true) fds
, except that ifsw
is off then it closes all the FDs.Using FDs
val use : t -> (Unix.file_descr -> 'a) -> if_closed:(unit -> 'a) -> 'a
use t fn ~if_closed
callsfn wrapped_fd
, ensuring thatwrapped_fd
will not be closed beforefn
returns.If
t
is already closed, it returnsif_closed ()
instead.val use_exn : string -> t -> (Unix.file_descr -> 'a) -> 'a
use_exn op t fn
callsfn wrapped_fd
, ensuring thatwrapped_fd
will not be closed beforefn
returns.If
t
is already closed, it raises an exception, usingop
as the name of the failing operation.val use_exn_list : string -> t list -> (Unix.file_descr list -> 'a) -> 'a
use_exn_list op fds fn
callsuse_exn
on each FD infds
, callingfn wrapped_fds
on the results.Closing
val close : t -> unit
close t
markst
as closed, so thatuse
can no longer be used to start new operations.The wrapped FD will be closed once all current users of the FD have finished (unless
close_unix = false
).Has no effect if
t
is already closed.val remove : t -> Unix.file_descr option
remove t
markst
as closed, so thatuse
can no longer be used to start new operations.It then waits for all current users of the wrapped FD to finish using it, and then returns the FD.
This operation suspends the calling fiber and so must run from an Eio fiber. It does not allow itself to be cancelled, since it takes ownership of the FD and that would be leaked if it aborted.
Returns
None
ift
is closed by another fiber first.Flags
val is_blocking : t -> bool
is_blocking t
returns the value ofblocking
passed toof_unix
.If not known, it first probes for it (and if the FD is already closed, returns
false
).val is_seekable : t -> bool
is_seekable t
returns the value ofseekable
passed toof_unix
.If not known, it first probes for it (and if the FD is already closed, returns
false
).Standard FDs
val stdin : t
val stdout : t
val stderr : t
Printing
val pp : t Fmt.t
Displays the FD number.
Ipaddr (eio.Eio_unix.Net.Ipaddr) Module
Net.Ipaddr
Convert between Eio.Net.Ipaddr and Unix.inet_addr.
Internally, these are actually the same type, so these are just casts.
\ No newline at end of file +val to_unix : [< `V4 | `V6 ] Eio.Net.Ipaddr.t -> Unix.inet_addr
val of_unix : Unix.inet_addr -> Eio.Net.Ipaddr.v4v6
Ipaddr (eio.Eio_unix.Net.Ipaddr) Module
Net.Ipaddr
Convert between Eio.Net.Ipaddr and Unix.inet_addr.
Internally, these are actually the same type, so these are just casts.
\ No newline at end of file diff --git a/eio/Eio_unix/Net/class-datagram_socket/index.html b/eio/Eio_unix/Net/class-datagram_socket/index.html deleted file mode 100644 index 1980be36f..000000000 --- a/eio/Eio_unix/Net/class-datagram_socket/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -val to_unix : [< `V4 | `V6 ] Eio.Net.Ipaddr.t -> Unix.inet_addr
val of_unix : Unix.inet_addr -> Eio.Net.Ipaddr.v4v6
datagram_socket (eio.Eio_unix.Net.datagram_socket) Class
Net.datagram_socket
\ No newline at end of file diff --git a/eio/Eio_unix/Net/class-stream_socket/index.html b/eio/Eio_unix/Net/class-stream_socket/index.html deleted file mode 100644 index de8a2417b..000000000 --- a/eio/Eio_unix/Net/class-stream_socket/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -inherit Eio.Net.datagram_socket
stream_socket (eio.Eio_unix.Net.stream_socket) Class
Net.stream_socket
\ No newline at end of file diff --git a/eio/Eio_unix/Net/class-t/index.html b/eio/Eio_unix/Net/class-t/index.html deleted file mode 100644 index da3d1f06a..000000000 --- a/eio/Eio_unix/Net/class-t/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -inherit Eio.Net.stream_socket
t (eio.Eio_unix.Net.t) Class
Net.t
\ No newline at end of file diff --git a/eio/Eio_unix/Net/index.html b/eio/Eio_unix/Net/index.html index cf570ed3b..230cc7962 100644 --- a/eio/Eio_unix/Net/index.html +++ b/eio/Eio_unix/Net/index.html @@ -1,30 +1,47 @@ -inherit Eio.Net.t
method getnameinfo : Eio.Net.Sockaddr.t -> string * string
Net (eio.Eio_unix.Net) Module
Eio_unix.Net
Extended network API with support for file descriptors.
\ No newline at end of file diff --git a/eio/Eio_unix/Pi/index.html b/eio/Eio_unix/Pi/index.html new file mode 100644 index 000000000..bc4e5833d --- /dev/null +++ b/eio/Eio_unix/Pi/index.html @@ -0,0 +1,13 @@ + +Types
These extend the types in
Eio.Net
with support for file descriptors.class virtual stream_socket : object ... end
class virtual datagram_socket : object ... end
class virtual t : object ... end
Unix address conversions
Note: OCaml's
Unix
.sockaddr type considers e.g. TCP port 80 and UDP port 80 to be the same thing, whereas Eio regards them as separate addresses that just happen to have the same representation (a host address and a port number), so we have separate "of_unix" functions for each.val sockaddr_to_unix : +
Net (eio.Eio_unix.Net) Module
Eio_unix.Net
Extended network API with support for file descriptors.
\ No newline at end of file + * int -> ([ `Unix_fd | datagram_socket_ty ] Eio.Std.r + * [ `Unix_fd | datagram_socket_ty ] Eio.Std.r) + Stdlib.Effect.tTypes
These extend the types in
Eio.Net
with support for file descriptors.type stream_socket_ty = [ `Generic | `Unix ] Eio.Net.stream_socket_ty
type datagram_socket_ty = [ `Generic | `Unix ] Eio.Net.datagram_socket_ty
type listening_socket_ty = [ `Generic | `Unix ] Eio.Net.listening_socket_ty
type 'a stream_socket = [> stream_socket_ty ] as 'a Eio.Std.r
type 'a datagram_socket = [> datagram_socket_ty ] as 'a Eio.Std.r
type 'a listening_socket = [> listening_socket_ty ] as 'a Eio.Std.r
type t = [ `Generic | `Unix ] Eio.Net.ty Eio.Std.r
Passing file descriptors
val send_msg : + [> `Platform of [> `Unix ] | `Socket | `Stream ] Eio.Std.r -> + ?fds:Fd.t list -> + Cstruct.t list -> + unit
Like
Eio.Flow.write
, but allows passing file descriptors (for Unix-domain sockets).val recv_msg_with_fds : + [> `Platform of [> `Unix ] | `Socket | `Stream ] Eio.Std.r -> + sw:Eio.Std.Switch.t -> + max_fds:int -> + Cstruct.t list -> + int * Fd.t list
Like
Eio.Flow.single_read
, but also allows receiving file descriptors (for Unix-domain sockets).
fd socket
is the underlying FD ofsocket
.Unix address conversions
Note: OCaml's
Unix
.sockaddr type considers e.g. TCP port 80 and UDP port 80 to be the same thing, whereas Eio regards them as separate addresses that just happen to have the same representation (a host address and a port number), so we have separate "of_unix" functions for each.val sockaddr_to_unix : [< Eio.Net.Sockaddr.stream | Eio.Net.Sockaddr.datagram ] -> Unix.sockaddr
val sockaddr_of_unix_stream : Unix.sockaddr -> Eio.Net.Sockaddr.stream
val sockaddr_of_unix_datagram : Unix.sockaddr -> Eio.Net.Sockaddr.datagram
module Ipaddr : sig ... end
Convert between Eio.Net.Ipaddr and Unix.inet_addr.
Creating or importing sockets
val import_socket_stream : sw:Eio.Std.Switch.t -> close_unix:bool -> Unix.file_descr -> - stream_socket
import_socket_stream ~sw ~close_unix:true fd
is an Eio flow that usesfd
.It can be cast to e.g.
source
for a one-way flow. The socket object will be closed whensw
finishes.The
close_unix
andsw
arguments are passed toFd.of_unix
.val import_socket_datagram : + [ `Unix_fd | stream_socket_ty ] Eio.Std.r
import_socket_stream ~sw ~close_unix:true fd
is an Eio flow that usesfd
.It can be cast to e.g.
source
for a one-way flow. The socket object will be closed whensw
finishes.The
close_unix
andsw
arguments are passed toFd.of_unix
.val import_socket_datagram : sw:Eio.Std.Switch.t -> close_unix:bool -> Unix.file_descr -> - datagram_socket
import_socket_datagram ~sw ~close_unix:true fd
is an Eio datagram socket that usesfd
.The socket object will be closed when
sw
finishes.The
close_unix
andsw
arguments are passed toFd.of_unix
.val socketpair_stream : + [ `Unix_fd | datagram_socket_ty ] Eio.Std.r
import_socket_datagram ~sw ~close_unix:true fd
is an Eio datagram socket that usesfd
.The socket object will be closed when
sw
finishes.The
close_unix
andsw
arguments are passed toFd.of_unix
.val socketpair_stream : sw:Eio.Std.Switch.t -> ?domain:Unix.socket_domain -> ?protocol:int -> unit -> - stream_socket * stream_socket
socketpair_stream ~sw ()
returns a connected pair of flows, such that writes to one can be read by the other.This creates OS-level resources using
socketpair(2)
. Note that, like all FDs created by Eio, they are both marked as close-on-exec by default.val socketpair_datagram : + [ `Unix_fd | stream_socket_ty ] Eio.Std.r + * [ `Unix_fd | stream_socket_ty ] Eio.Std.r
socketpair_stream ~sw ()
returns a connected pair of flows, such that writes to one can be read by the other.This creates OS-level resources using
socketpair(2)
. Note that, like all FDs created by Eio, they are both marked as close-on-exec by default.val socketpair_datagram : sw:Eio.Std.Switch.t -> ?domain:Unix.socket_domain -> ?protocol:int -> unit -> - datagram_socket * datagram_socket
socketpair_datagram ~sw ()
returns a connected pair of flows, such that writes to one can be read by the other.This creates OS-level resources using
socketpair(2)
. Note that, like all FDs created by Eio, they are both marked as close-on-exec by default.Private API for backends
val getnameinfo : Eio.Net.Sockaddr.t -> string * string
getnameinfo sockaddr
returns domain name and service forsockaddr
.type Stdlib.Effect.t +=
| Import_socket_stream : Eio.Std.Switch.t + [ `Unix_fd | datagram_socket_ty ] Eio.Std.r + * [ `Unix_fd | datagram_socket_ty ] Eio.Std.r
socketpair_datagram ~sw ()
returns a connected pair of flows, such that writes to one can be read by the other.This creates OS-level resources using
socketpair(2)
. Note that, like all FDs created by Eio, they are both marked as close-on-exec by default.Private API for backends
val getnameinfo : Eio.Net.Sockaddr.t -> string * string
getnameinfo sockaddr
returns domain name and service forsockaddr
.type Stdlib.Effect.t +=
| Import_socket_stream : Eio.Std.Switch.t * bool - * Unix.file_descr -> stream_socket Stdlib.Effect.t
| Import_socket_datagram : Eio.Std.Switch.t + * Unix.file_descr -> [ `Unix_fd | stream_socket_ty ] Eio.Std.r + Stdlib.Effect.t
| Import_socket_datagram : Eio.Std.Switch.t * bool - * Unix.file_descr -> datagram_socket Stdlib.Effect.t
| Socketpair_stream : Eio.Switch.t + * Unix.file_descr -> [ `Unix_fd | datagram_socket_ty ] Eio.Std.r + Stdlib.Effect.t
| Socketpair_stream : Eio.Switch.t * Unix.socket_domain - * int -> (stream_socket * stream_socket) Stdlib.Effect.t
| Socketpair_datagram : Eio.Switch.t + * int -> ([ `Unix_fd | stream_socket_ty ] Eio.Std.r + * [ `Unix_fd | stream_socket_ty ] Eio.Std.r) + Stdlib.Effect.t
| Socketpair_datagram : Eio.Switch.t * Unix.socket_domain - * int -> (datagram_socket * datagram_socket) Stdlib.Effect.t
Pi (eio.Eio_unix.Pi) Module
Eio_unix.Pi
\ No newline at end of file diff --git a/eio/Eio_unix/Pi/module-type-DATAGRAM_SOCKET/index.html b/eio/Eio_unix/Pi/module-type-DATAGRAM_SOCKET/index.html new file mode 100644 index 000000000..d389b948c --- /dev/null +++ b/eio/Eio_unix/Pi/module-type-DATAGRAM_SOCKET/index.html @@ -0,0 +1,2 @@ + +module type STREAM_SOCKET = sig ... end
type Eio.Resource.pi +=
| Stream_socket : ('t, + (module STREAM_SOCKET + with type t = 't), + [> `Platform of [> `Unix ] | `Socket | `Stream ]) + Eio.Resource.pi
module type FLOW = sig ... end
val flow_handler : + (module FLOW with type t = 't and type tag = 'tag) -> + ('t, [ `Unix_fd | 'tag Eio.Net.stream_socket_ty | Eio.File.rw_ty ]) + Eio.Resource.handler
module type DATAGRAM_SOCKET = sig ... end
val datagram_handler : + (module DATAGRAM_SOCKET with type t = 't and type tag = 'tag) -> + ('t, [ `Unix_fd | 'tag Eio.Net.datagram_socket_ty ]) Eio.Resource.handler
module type LISTENING_SOCKET = sig ... end
val listening_socket_handler : + (module LISTENING_SOCKET with type t = 't and type tag = 'tag) -> + ('t, [ `Unix_fd | 'tag Eio.Net.listening_socket_ty ]) Eio.Resource.handler
DATAGRAM_SOCKET (eio.Eio_unix.Pi.DATAGRAM_SOCKET) Module type
Pi.DATAGRAM_SOCKET
\ No newline at end of file diff --git a/eio/Eio_unix/Pi/module-type-FLOW/index.html b/eio/Eio_unix/Pi/module-type-FLOW/index.html new file mode 100644 index 000000000..cb0900b5f --- /dev/null +++ b/eio/Eio_unix/Pi/module-type-FLOW/index.html @@ -0,0 +1,7 @@ + +
include Eio.Net.Pi.DATAGRAM_SOCKET
val send : t -> ?dst:Eio.Net.Sockaddr.datagram -> Cstruct.t list -> unit
val recv : t -> Cstruct.t -> Eio.Net.Sockaddr.datagram * int
val close : t -> unit
FLOW (eio.Eio_unix.Pi.FLOW) Module type
Pi.FLOW
\ No newline at end of file diff --git a/eio/Eio_unix/Pi/module-type-LISTENING_SOCKET/index.html b/eio/Eio_unix/Pi/module-type-LISTENING_SOCKET/index.html new file mode 100644 index 000000000..40c726e26 --- /dev/null +++ b/eio/Eio_unix/Pi/module-type-LISTENING_SOCKET/index.html @@ -0,0 +1,5 @@ + +
include Eio.File.Pi.WRITE
include Eio.Flow.Pi.SINK
include Eio.File.Pi.READ with type t := t
include Eio.Flow.Pi.SOURCE with type t := t
val pread : t -> file_offset:Optint.Int63.t -> Cstruct.t list -> int
val stat : t -> Eio.File.Stat.t
val pwrite : t -> file_offset:Optint.Int63.t -> Cstruct.t list -> int
include STREAM_SOCKET with type t := t
include Eio.Net.Pi.STREAM_SOCKET with type t := t
include Eio.Flow.Pi.SHUTDOWN with type t := t
val shutdown : t -> Eio.Flow.shutdown_command -> unit
include Eio.Flow.Pi.SOURCE with type t := t
val read_methods : t Eio.Flow.read_method list
val single_read : t -> Cstruct.t -> int
include Eio.Flow.Pi.SINK with type t := t
val single_write : t -> Cstruct.t list -> int
val copy : t -> src:_ Eio.Flow.source -> unit
copy t ~src
allows for optimising copy operations.If you have no optimisations, you can use
simple_copy
to implement this usingsingle_write
.val close : t -> unit
val recv_msg_with_fds : + t -> + sw:Eio.Std.Switch.t -> + max_fds:int -> + Cstruct.t list -> + int * Fd.t list
LISTENING_SOCKET (eio.Eio_unix.Pi.LISTENING_SOCKET) Module type
Pi.LISTENING_SOCKET
\ No newline at end of file diff --git a/eio/Eio_unix/Pi/module-type-STREAM_SOCKET/index.html b/eio/Eio_unix/Pi/module-type-STREAM_SOCKET/index.html new file mode 100644 index 000000000..c35d37960 --- /dev/null +++ b/eio/Eio_unix/Pi/module-type-STREAM_SOCKET/index.html @@ -0,0 +1,7 @@ + +
include Eio.Net.Pi.LISTENING_SOCKET
val accept : + t -> + sw:Eio.Switch.t -> + tag Eio.Net.stream_socket_ty Eio.Std.r * Eio.Net.Sockaddr.stream
val close : t -> unit
STREAM_SOCKET (eio.Eio_unix.Pi.STREAM_SOCKET) Module type
Pi.STREAM_SOCKET
\ No newline at end of file diff --git a/eio/Eio_unix/Private/Rcfd/index.html b/eio/Eio_unix/Private/Rcfd/index.html index fd63c3a2e..b9ce2d151 100644 --- a/eio/Eio_unix/Private/Rcfd/index.html +++ b/eio/Eio_unix/Private/Rcfd/index.html @@ -1,2 +1,2 @@ -
include Eio.Net.Pi.STREAM_SOCKET
include Eio.Flow.Pi.SOURCE with type t := t
val read_methods : t Eio.Flow.read_method list
val single_read : t -> Cstruct.t -> int
include Eio.Flow.Pi.SINK with type t := t
val single_write : t -> Cstruct.t list -> int
val copy : t -> src:_ Eio.Flow.source -> unit
copy t ~src
allows for optimising copy operations.If you have no optimisations, you can use
simple_copy
to implement this usingsingle_write
.val close : t -> unit
val recv_msg_with_fds : + t -> + sw:Eio.Std.Switch.t -> + max_fds:int -> + Cstruct.t list -> + int * Fd.t list
Rcfd (eio.Eio_unix.Private.Rcfd) Module
Private.Rcfd
A safe wrapper around
Unix.file_descr
.When FDs are shared between domains, there is the risk that one domain will try to use an FD just as another domain is closing it. Then this can happen:
- Domain A decides to write to FD 3, which it shares with domain B.
- Domain B closes FD 3.
- Domain C opens a new file, getting assigned FD 3 by the OS.
- Domain A writes to FD 3, corrupting domain C's file.
This would break modularity, since the fibers in domains A and C may have no connection with each other.
To prevent this, we keep a ref-count, tracking how many fibers are using the FD. Wrap uses of the FD in
use
to ensure that it won't be closed while you're using it.Calling
close
while one or more operations are still in progress marks the wrapper as closing (so that no futher operations can start); the last operation to finish will close the underlying FD.\ No newline at end of file +val make : Unix.file_descr -> t
val use : if_closed:(unit -> 'a) -> t -> (Unix.file_descr -> 'a) -> 'a
use t fn ~if_closed
callsfn fd
, preventingfd
from being closed untilfn
returns.
if_closed ()
is used ift
is closed before we can increment the ref-count.use
can be used in parallel from multiple domains at the same time.This operation is lock-free and can be used safely from signal handlers, etc.
val is_open : t -> bool
is_open t
returnstrue
untilt
has been marked as closing, after which it returnsfalse
.This is mostly useful inside the callback of
use
, to test whether another fiber has started closingt
(in which case you may decide to stop early).val close : t -> bool
close t
markst
as closed and arranges for its FD to be closed.If there are calls to
use
in progress, the last one to finish will close the underlying FD. Note that this function returns without waiting for the close to happen in that case.Returns
true
after successfully markingt
as closing, orfalse
if it was already marked.If you need to wait until the underlying FD is closed, use
remove
and then close the FD yourself instead.val remove : t -> Unix.file_descr option
remove t
closest
and returns the FD.It immediately marks
t
as closing (so no further operations can start) and then waits until there are no further users.This operation suspends the calling fiber and so must run from an Eio fiber. It does not allow itself to be cancelled, since it takes ownership of the FD and that would be leaked if it aborted.
If another fiber marks
t
as closing beforeremove
can, it returnsNone
immediately.val peek : t -> Unix.file_descr
peek t
returns the file-descriptor without updating the ref-count.You must ensure that
t
isn't closed while using the result. This is a dangerous operation and may be removed in the future.If
t
was closed, it instead raises an exception (if you're not sure whent
might get closed, you shouldn't be using this function).val pp : t Fmt.t
Displays the FD number.
Rcfd (eio.Eio_unix.Private.Rcfd) Module
Private.Rcfd
A safe wrapper around
Unix.file_descr
.When FDs are shared between domains, there is the risk that one domain will try to use an FD just as another domain is closing it. Then this can happen:
- Domain A decides to write to FD 3, which it shares with domain B.
- Domain B closes FD 3.
- Domain C opens a new file, getting assigned FD 3 by the OS.
- Domain A writes to FD 3, corrupting domain C's file.
This would break modularity, since the fibers in domains A and C may have no connection with each other.
To prevent this, we keep a ref-count, tracking how many fibers are using the FD. Wrap uses of the FD in
use
to ensure that it won't be closed while you're using it.Calling
close
while one or more operations are still in progress marks the wrapper as closing (so that no futher operations can start); the last operation to finish will close the underlying FD.\ No newline at end of file diff --git a/eio/Eio_unix/Private/index.html b/eio/Eio_unix/Private/index.html index dc8f67957..62a2ed9bd 100644 --- a/eio/Eio_unix/Private/index.html +++ b/eio/Eio_unix/Private/index.html @@ -1,2 +1,3 @@ -val make : Unix.file_descr -> t
val use : if_closed:(unit -> 'a) -> t -> (Unix.file_descr -> 'a) -> 'a
use t fn ~if_closed
callsfn fd
, preventingfd
from being closed untilfn
returns.
if_closed ()
is used ift
is closed before we can increment the ref-count.use
can be used in parallel from multiple domains at the same time.This operation is lock-free and can be used safely from signal handlers, etc.
val is_open : t -> bool
is_open t
returnstrue
untilt
has been marked as closing, after which it returnsfalse
.This is mostly useful inside the callback of
use
, to test whether another fiber has started closingt
(in which case you may decide to stop early).val close : t -> bool
close t
markst
as closed and arranges for its FD to be closed.If there are calls to
use
in progress, the last one to finish will close the underlying FD. Note that this function returns without waiting for the close to happen in that case.Returns
true
after successfully markingt
as closing, orfalse
if it was already marked.If you need to wait until the underlying FD is closed, use
remove
and then close the FD yourself instead.val remove : t -> Unix.file_descr option
remove t
closest
and returns the FD.It immediately marks
t
as closing (so no further operations can start) and then waits until there are no further users.This operation suspends the calling fiber and so must run from an Eio fiber. It does not allow itself to be cancelled, since it takes ownership of the FD and that would be leaked if it aborted.
If another fiber marks
t
as closing beforeremove
can, it returnsNone
immediately.val peek : t -> Unix.file_descr
peek t
returns the file-descriptor without updating the ref-count.You must ensure that
t
isn't closed while using the result. This is a dangerous operation and may be removed in the future.If
t
was closed, it instead raises an exception (if you're not sure whent
might get closed, you shouldn't be using this function).val pp : t Fmt.t
Displays the FD number.
Private (eio.Eio_unix.Private) Module
Eio_unix.Private
API for Eio backends only.
\ No newline at end of file +type Stdlib.Effect.t +=
| Await_readable : Unix.file_descr -> unit Stdlib.Effect.t
| Await_writable : Unix.file_descr -> unit Stdlib.Effect.t
| Get_monotonic_clock : Eio.Time.Mono.t Stdlib.Effect.t
| Pipe : Eio.Switch.t -> (source * sink) Stdlib.Effect.t
module Rcfd : sig ... end
A safe wrapper around
Unix.file_descr
.module Fork_action = Private.Fork_action
Private (eio.Eio_unix.Private) Module
Eio_unix.Private
API for Eio backends only.
\ No newline at end of file diff --git a/eio/Eio_unix/Process/Make_mgr/argument-1-X/index.html b/eio/Eio_unix/Process/Make_mgr/argument-1-X/index.html new file mode 100644 index 000000000..a1937616f --- /dev/null +++ b/eio/Eio_unix/Process/Make_mgr/argument-1-X/index.html @@ -0,0 +1,10 @@ + +type Stdlib.Effect.t +=
| Await_readable : Unix.file_descr -> unit Stdlib.Effect.t
| Await_writable : Unix.file_descr -> unit Stdlib.Effect.t
| Get_monotonic_clock : Eio.Time.Mono.ty Eio.Std.r Stdlib.Effect.t
| Pipe : Eio.Switch.t -> (source_ty Eio.Std.r * sink_ty Eio.Std.r) + Stdlib.Effect.t
module Rcfd : sig ... end
A safe wrapper around
Unix.file_descr
.module Fork_action = Private.Fork_action
X (eio.Eio_unix.Process.Make_mgr.X) Parameter
Make_mgr.X
\ No newline at end of file diff --git a/eio/Eio_unix/Process/Make_mgr/index.html b/eio/Eio_unix/Process/Make_mgr/index.html new file mode 100644 index 000000000..1710c2d36 --- /dev/null +++ b/eio/Eio_unix/Process/Make_mgr/index.html @@ -0,0 +1,26 @@ + +val spawn_unix : + t -> + sw:Eio.Std.Switch.t -> + ?cwd:Eio.Fs.dir_ty Eio.Path.t -> + env:string array -> + fds:(int * Fd.t * Private.Fork_action.blocking) list -> + executable:string -> + string list -> + ty Eio.Std.r
Make_mgr (eio.Eio_unix.Process.Make_mgr) Module
Process.Make_mgr
\ No newline at end of file diff --git a/eio/Eio_unix/Process/Pi/index.html b/eio/Eio_unix/Process/Pi/index.html new file mode 100644 index 000000000..630ac8e75 --- /dev/null +++ b/eio/Eio_unix/Process/Pi/index.html @@ -0,0 +1,4 @@ + +Parameters
module X : sig ... end
Signature
include Eio.Process.Pi.MGR + with type t = X.t + with type tag = [ `Generic | `Unix ]
type t = X.t
val pipe : + t -> + sw:Eio.Switch.t -> + [ Eio.Flow.source_ty | Eio.Resource.close_ty ] Eio.Std.r + * [ Eio.Flow.sink_ty | Eio.Resource.close_ty ] Eio.Std.r
val spawn : + t -> + sw:Eio.Switch.t -> + ?cwd:Eio.Fs.dir_ty Eio.Path.t -> + ?stdin:Eio.Flow.source_ty Eio.Std.r -> + ?stdout:Eio.Flow.sink_ty Eio.Std.r -> + ?stderr:Eio.Flow.sink_ty Eio.Std.r -> + ?env:string array -> + ?executable:string -> + string list -> + tag Eio.Process.ty Eio.Std.r
val spawn_unix : + t -> + sw:Eio.Std.Switch.t -> + ?cwd:Eio.Fs.dir_ty Eio.Path.t -> + env:string array -> + fds:(int * Fd.t * Private.Fork_action.blocking) list -> + executable:string -> + string list -> + ty Eio.Std.r
Pi (eio.Eio_unix.Process.Pi) Module
Process.Pi
\ No newline at end of file diff --git a/eio/Eio_unix/Process/Pi/module-type-MGR/index.html b/eio/Eio_unix/Process/Pi/module-type-MGR/index.html new file mode 100644 index 000000000..c460347f1 --- /dev/null +++ b/eio/Eio_unix/Process/Pi/module-type-MGR/index.html @@ -0,0 +1,24 @@ + +module type MGR = sig ... end
type Eio.Resource.pi +=
| Mgr_unix : ('t, (module MGR with type t = 't), [> mgr_ty ]) Eio.Resource.pi
val mgr_unix : + (module MGR with type t = 't and type tag = 'tag) -> + ('t, 'tag Eio.Process.mgr_ty) Eio.Resource.handler
MGR (eio.Eio_unix.Process.Pi.MGR) Module type
Pi.MGR
\ No newline at end of file diff --git a/eio/Eio_unix/Process/class-mgr/index.html b/eio/Eio_unix/Process/class-mgr/index.html deleted file mode 100644 index 369cd4b67..000000000 --- a/eio/Eio_unix/Process/class-mgr/index.html +++ /dev/null @@ -1,17 +0,0 @@ - -
include Eio.Process.Pi.MGR
val pipe : + t -> + sw:Eio.Switch.t -> + [ Eio.Flow.source_ty | Eio.Resource.close_ty ] Eio.Std.r + * [ Eio.Flow.sink_ty | Eio.Resource.close_ty ] Eio.Std.r
val spawn : + t -> + sw:Eio.Switch.t -> + ?cwd:Eio.Fs.dir_ty Eio.Path.t -> + ?stdin:Eio.Flow.source_ty Eio.Std.r -> + ?stdout:Eio.Flow.sink_ty Eio.Std.r -> + ?stderr:Eio.Flow.sink_ty Eio.Std.r -> + ?env:string array -> + ?executable:string -> + string list -> + tag Eio.Process.ty Eio.Std.r
val spawn_unix : + t -> + sw:Eio.Std.Switch.t -> + ?cwd:Eio.Fs.dir_ty Eio.Path.t -> + env:string array -> + fds:(int * Fd.t * Private.Fork_action.blocking) list -> + executable:string -> + string list -> + ty Eio.Std.r
mgr (eio.Eio_unix.Process.mgr) Class
Process.mgr
\ No newline at end of file diff --git a/eio/Eio_unix/Process/index.html b/eio/Eio_unix/Process/index.html index 513b6e018..5b77be1e5 100644 --- a/eio/Eio_unix/Process/index.html +++ b/eio/Eio_unix/Process/index.html @@ -1,10 +1,12 @@ -inherit Eio.Process.mgr
method pipe : sw:Eio.Std.Switch.t -> - < Eio.Flow.source ; Eio.Flow.close > * < Eio.Flow.sink ; Eio.Flow.close >
method virtual spawn_unix : sw:Eio.Std.Switch.t -> - ?cwd:Eio.Fs.dir Eio.Path.t -> - env:string array -> - fds:(int * Eio_unix__.Fd.t * Eio_unix__Fork_action.blocking) list -> - executable:string -> - string list -> - Eio.Process.t
method spawn : sw:Eio.Std.Switch.t -> - ?cwd:Eio.Fs.dir Eio.Path.t -> - ?stdin:Eio.Flow.source -> - ?stdout:Eio.Flow.sink -> - ?stderr:Eio.Flow.sink -> - ?env:string array -> - ?executable:string -> - string list -> - Eio.Process.t
The default implementation uses
spawn_unix
.Process (eio.Eio_unix.Process) Module
Eio_unix.Process
Spawning child processes with extra control.
This extends the
Eio.Process
API with more control over file-descriptors.\ No newline at end of file diff --git a/eio/Eio_unix/Resource/index.html b/eio/Eio_unix/Resource/index.html index 672b73aad..4173a3a43 100644 --- a/eio/Eio_unix/Resource/index.html +++ b/eio/Eio_unix/Resource/index.html @@ -1,2 +1,2 @@ -class virtual mgr : object ... end
val spawn_unix : +
Process (eio.Eio_unix.Process) Module
Eio_unix.Process
Spawning child processes with extra control.
This extends the
Eio.Process
API with more control over file-descriptors.\ No newline at end of file + ty Eio.Std.rTypes
These extend the types in
Eio.Process
with support for file descriptors.type ty = [ `Generic | `Unix ] Eio.Process.ty
type mgr_ty = [ `Generic | `Unix ] Eio.Process.mgr_ty
module Pi : sig ... end
val spawn_unix : sw:Eio.Std.Switch.t -> - mgr -> - ?cwd:Eio.Fs.dir Eio.Path.t -> + _ mgr -> + ?cwd:Eio.Fs.dir_ty Eio.Path.t -> fds:(int * Fd.t * Private.Fork_action.blocking) list -> ?env:string array -> ?executable:string -> string list -> - Eio.Process.t
spawn_unix ~sw mgr ~fds args
spawns a child process running the commandargs
.The arguments are as for
Eio.Process.spawn
, except that it takes a list of FD mappings forFork_action
.inherit_fds directly, rather than just flows for the standard streams.val sigchld : Eio.Condition.t
If an Eio backend installs a SIGCHLD handler, the handler will broadcast on this condition.
This allows non-Eio libraries (such as Lwt) to share its signal handler.
Note: Not all backends install a handler (e.g. eio_linux uses process descriptors instead), so be sure to call
install_sigchld_handler
if you need to use this.
install_sigchld_handler ()
sets the signal handler for SIGCHLD to broadcastsigchld
.
spawn_unix ~sw mgr ~fds args
spawns a child process running the commandargs
.The arguments are as for
Eio.Process.spawn
, except that it takes a list of FD mappings forFork_action
.inherit_fds directly, rather than just flows for the standard streams.val sigchld : Eio.Condition.t
If an Eio backend installs a SIGCHLD handler, the handler will broadcast on this condition.
This allows non-Eio libraries (such as Lwt) to share its signal handler.
Note: Not all backends install a handler (e.g. eio_linux uses process descriptors instead), so be sure to call
install_sigchld_handler
if you need to use this.
install_sigchld_handler ()
sets the signal handler for SIGCHLD to broadcastsigchld
.Resource (eio.Eio_unix.Resource) Module
Eio_unix.Resource
Eio resources backed by an OS file descriptor.
\ No newline at end of file +type t = < fd : Fd.t >
Resources that have FDs are sub-types of
t
.type Eio.Generic.ty +=
| FD : Fd.t Eio.Generic.ty
(*Resources that wrap FDs can handle this in their
*)probe
method to expose the FD.val fd_opt : Eio.Generic.t -> Fd.t option
fd_opt t
returns the FD being wrapped by a generic resource, if any.This just probes
t
usingFD
.Resource (eio.Eio_unix.Resource) Module
Eio_unix.Resource
Eio resources backed by an OS file descriptor.
\ No newline at end of file diff --git a/eio/Eio_unix/Stdenv/index.html b/eio/Eio_unix/Stdenv/index.html index 915664702..ced817276 100644 --- a/eio/Eio_unix/Stdenv/index.html +++ b/eio/Eio_unix/Stdenv/index.html @@ -1,15 +1,15 @@ -type 'a t = [> `Unix_fd ] as 'a Eio.Resource.t
Resources that have FDs are tagged with
`Unix_fd
.val fd_opt : _ Eio.Resource.t -> Fd.t option
fd_opt t
returns the FD being wrapped by a generic resource, if any.This just probes
t
usingFD
.Stdenv (eio.Eio_unix.Stdenv) Module
Eio_unix.Stdenv
The set of resources provided to a process on a Unix-compatible system.
type base = - < stdin : source - ; stdout : sink - ; stderr : sink - ; net : Eio.Net.t - ; domain_mgr : Eio.Domain_manager.t - ; process_mgr : Process.mgr - ; clock : Eio.Time.clock - ; mono_clock : Eio.Time.Mono.t - ; fs : Eio.Fs.dir Eio.Path.t - ; cwd : Eio.Fs.dir Eio.Path.t - ; secure_random : Eio.Flow.source +
Stdenv (eio.Eio_unix.Stdenv) Module
Eio_unix.Stdenv
The set of resources provided to a process on a Unix-compatible system.
\ No newline at end of file diff --git a/eio/Eio_unix/index.html b/eio/Eio_unix/index.html index 2436b9035..4c148ce39 100644 --- a/eio/Eio_unix/index.html +++ b/eio/Eio_unix/index.html @@ -1,2 +1,2 @@ -type base = + < stdin : source_ty Eio.Std.r + ; stdout : sink_ty Eio.Std.r + ; stderr : sink_ty Eio.Std.r + ; net : [ `Unix | `Generic ] Eio.Net.ty Eio.Std.r + ; domain_mgr : Eio.Domain_manager.ty Eio.Std.r + ; process_mgr : Process.mgr_ty Eio.Std.r + ; clock : float Eio.Time.clock_ty Eio.Std.r + ; mono_clock : Eio.Time.Mono.ty Eio.Std.r + ; fs : Eio.Fs.dir_ty Eio.Path.t + ; cwd : Eio.Fs.dir_ty Eio.Path.t + ; secure_random : Eio.Flow.source_ty Eio.Std.r ; debug : Eio.Debug.t ; backend_id : string >
The common set of features provided by all traditional operating systems (BSDs, Linux, Mac, Windows).
You can use the functions in
Eio.Stdenv
to access these fields if you prefer.Eio_unix (eio.Eio_unix) Module
Eio_unix
Extension of
Eio
for integration with OCaml'sUnix
module.Note that OCaml's
Unix
module is not safe, and therefore care must be taken when using these functions. For example, it is possible to leak file descriptors this way, or to use them after they've been closed, allowing one module to corrupt a file belonging to an unrelated module.\ No newline at end of file +type Eio.Exn.Backend.t +=
module Fd : sig ... end
A safe wrapper for
Unix
.file_descr.module Resource : sig ... end
Eio resources backed by an OS file descriptor.
module Net : sig ... end
Extended network API with support for file descriptors.
type source = < Eio.Flow.source ; Resource.t ; Eio.Flow.close >
type sink = < Eio.Flow.sink ; Resource.t ; Eio.Flow.close >
type socket = Net.stream_socket
await_readable fd
blocks untilfd
is readable (or has an error).
await_writable fd
blocks untilfd
is writable (or has an error).
sleep d
sleeps ford
seconds, allowing other fibers to run. This is can be useful for debugging (e.g. to introduce delays to trigger a race condition) without having to plumbEio.Stdenv.mono_clock
through your code. It can also be used in programs that don't care about tracking determinism.
run_in_systhread fn
runs the functionfn
in a newly created system thread (aThread
.t). This allows blocking calls to be made non-blocking.val pipe : Eio.Std.Switch.t -> source * sink
pipe sw
returns a connected pair of flowssrc
andsink
. Data written tosink
can be read fromsrc
. Note that, like all FDs created by Eio, they are both marked as close-on-exec by default.module Process : sig ... end
Spawning child processes with extra control.
module Stdenv : sig ... end
The set of resources provided to a process on a Unix-compatible system.
module Private : sig ... end
API for Eio backends only.
module Ctf : sig ... end
Eio_unix (eio.Eio_unix) Module
Eio_unix
Extension of
Eio
for integration with OCaml'sUnix
module.Note that OCaml's
Unix
module is not safe, and therefore care must be taken when using these functions. For example, it is possible to leak file descriptors this way, or to use them after they've been closed, allowing one module to corrupt a file belonging to an unrelated module.\ No newline at end of file diff --git a/eio/Eio_utils/.dummy b/eio/Eio_utils/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/eio/Eio_utils/Lf_queue/index.html b/eio/Eio_utils/Lf_queue/index.html index 58c7279b1..a6fd5ee0d 100644 --- a/eio/Eio_utils/Lf_queue/index.html +++ b/eio/Eio_utils/Lf_queue/index.html @@ -1,2 +1,2 @@ -type Eio.Exn.Backend.t +=
module Fd : sig ... end
A safe wrapper for
Unix
.file_descr.module Resource : sig ... end
Eio resources backed by an OS file descriptor.
module Net : sig ... end
Extended network API with support for file descriptors.
await_readable fd
blocks untilfd
is readable (or has an error).
await_writable fd
blocks untilfd
is writable (or has an error).
sleep d
sleeps ford
seconds, allowing other fibers to run. This is can be useful for debugging (e.g. to introduce delays to trigger a race condition) without having to plumbEio.Stdenv.mono_clock
through your code. It can also be used in programs that don't care about tracking determinism.
run_in_systhread fn
runs the functionfn
in a newly created system thread (aThread
.t). This allows blocking calls to be made non-blocking.val pipe : Eio.Std.Switch.t -> source_ty Eio.Std.r * sink_ty Eio.Std.r
pipe sw
returns a connected pair of flowssrc
andsink
. Data written tosink
can be read fromsrc
. Note that, like all FDs created by Eio, they are both marked as close-on-exec by default.module Process : sig ... end
Spawning child processes with extra control.
module Stdenv : sig ... end
The set of resources provided to a process on a Unix-compatible system.
module Private : sig ... end
API for Eio backends only.
module Ctf : sig ... end
module Pi : sig ... end
Lf_queue (eio.Eio_utils.Lf_queue) Module
Eio_utils.Lf_queue
A lock-free multi-producer, single-consumer, thread-safe queue without support for cancellation. This makes a good data structure for a scheduler's run queue.
\ No newline at end of file +val create : unit -> 'a t
create ()
is a new empty queue.val push : 'a t -> 'a -> unit
push t x
addsx
to the tail of the queue. This can be used safely by multiple producer domains, in parallel with the other operations.val push_head : 'a t -> 'a -> unit
push_head t x
insertsx
at the head of the queue. This can only be used by the consumer (if run in parallel withpop
, the item might be skipped).val pop : 'a t -> 'a option
pop t
removes the head item fromt
and returns it. ReturnsNone
ift
is currently empty.val is_empty : 'a t -> bool
is_empty t
istrue
if callingpop
would returnNone
.val close : 'a t -> unit
close t
markst
as closed, preventing any further items from being pushed.Lf_queue (eio.Eio_utils.Lf_queue) Module
Eio_utils.Lf_queue
A lock-free multi-producer, single-consumer, thread-safe queue without support for cancellation. This makes a good data structure for a scheduler's run queue.
\ No newline at end of file diff --git a/eio/Eio_utils/Suspended/index.html b/eio/Eio_utils/Suspended/index.html index 69c4283f4..2942f0912 100644 --- a/eio/Eio_utils/Suspended/index.html +++ b/eio/Eio_utils/Suspended/index.html @@ -1,2 +1,2 @@ -val create : unit -> 'a t
create ()
is a new empty queue.val push : 'a t -> 'a -> unit
push t x
addsx
to the tail of the queue. This can be used safely by multiple producer domains, in parallel with the other operations.val push_head : 'a t -> 'a -> unit
push_head t x
insertsx
at the head of the queue. This can only be used by the consumer (if run in parallel withpop
, the item might be skipped).val pop : 'a t -> 'a option
pop t
removes the head item fromt
and returns it. ReturnsNone
ift
is currently empty.val is_empty : 'a t -> bool
is_empty t
istrue
if callingpop
would returnNone
.val close : 'a t -> unit
close t
markst
as closed, preventing any further items from being pushed.Suspended (eio.Eio_utils.Suspended) Module
Eio_utils.Suspended
A suspended fiber with its context.
\ No newline at end of file +module Ctf = Eio.Private.Ctf
type 'a t = {
fiber : Eio.Private.Fiber_context.t;
k : ('a, [ `Exit_scheduler ]) Stdlib.Effect.Deep.continuation;
}
val tid : 'a t -> Eio.Private.Ctf.id
val continue : 'a t -> 'b -> [ `Exit_scheduler ]
val discontinue : 'a t -> exn -> [ `Exit_scheduler ]
Suspended (eio.Eio_utils.Suspended) Module
Eio_utils.Suspended
A suspended fiber with its context.
\ No newline at end of file diff --git a/eio/Eio_utils/Zzz/Key/index.html b/eio/Eio_utils/Zzz/Key/index.html index c29092b27..251b142fe 100644 --- a/eio/Eio_utils/Zzz/Key/index.html +++ b/eio/Eio_utils/Zzz/Key/index.html @@ -1,2 +1,2 @@ -module Ctf = Eio.Private.Ctf
type 'a t = {
fiber : Eio.Private.Fiber_context.t;
k : ('a, [ `Exit_scheduler ]) Stdlib.Effect.Deep.continuation;
}
val tid : 'a t -> Eio.Private.Ctf.id
val continue : 'a t -> 'b -> [ `Exit_scheduler ]
val discontinue : 'a t -> exn -> [ `Exit_scheduler ]
Key (eio.Eio_utils.Zzz.Key) \ No newline at end of file + Module
Zzz.Key
A handle to a registered timer.
Key (eio.Eio_utils.Zzz.Key) \ No newline at end of file diff --git a/eio/Eio_utils/Zzz/index.html b/eio/Eio_utils/Zzz/index.html index 2b5df7270..2e21e8080 100644 --- a/eio/Eio_utils/Zzz/index.html +++ b/eio/Eio_utils/Zzz/index.html @@ -1,5 +1,5 @@ - Module
Zzz.Key
A handle to a registered timer.
Zzz (eio.Eio_utils.Zzz) Module
Eio_utils.Zzz
A set of timers.
module Key : sig ... end
A handle to a registered timer.
val create : unit -> t
create ()
is a fresh empty queue.val add : t -> Mtime.t -> unit Suspended.t -> Key.t
add t time thread
adds a new event, due attime
, and returns its ID. You must useEio.Private.Fiber_context.set_cancel_fn
onthread
before callingpop
. Your cancel function should callremove
(in addition to resumingthread
).val pop : +
Zzz (eio.Eio_utils.Zzz) Module
Eio_utils.Zzz
A set of timers.
\ No newline at end of file diff --git a/eio/Eio_utils/index.html b/eio/Eio_utils/index.html index e0329ab68..2c8bbbc88 100644 --- a/eio/Eio_utils/index.html +++ b/eio/Eio_utils/index.html @@ -1,2 +1,2 @@ -module Key : sig ... end
A handle to a registered timer.
val create : unit -> t
create ()
is a fresh empty queue.val add : t -> Mtime.t -> unit Suspended.t -> Key.t
add t time thread
adds a new event, due attime
, and returns its ID. You must useEio.Private.Fiber_context.set_cancel_fn
onthread
before callingpop
. Your cancel function should callremove
(in addition to resumingthread
).val pop : t -> now:Mtime.t -> [ `Due of unit Suspended.t | `Wait_until of Mtime.t | `Nothing ]
pop ~now t
removes and returns the earliest thread due bynow
. It also clears the thread's cancel function. If no thread is due yet, it returns the time the earliest thread becomes due.Eio_utils (eio.Eio_utils) Module
Eio_utils
Utilities for implementing Eio event loops.
These aren't intended for users of Eio.
\ No newline at end of file +module Lf_queue : sig ... end
A lock-free multi-producer, single-consumer, thread-safe queue without support for cancellation. This makes a good data structure for a scheduler's run queue.
module Suspended : sig ... end
A suspended fiber with its context.
module Zzz : sig ... end
A set of timers.
Eio_utils (eio.Eio_utils) Module
Eio_utils
Utilities for implementing Eio event loops.
These aren't intended for users of Eio.
\ No newline at end of file diff --git a/eio/index.html b/eio/index.html index f1b28a6c0..3550f8053 100644 --- a/eio/index.html +++ b/eio/index.html @@ -1,2 +1,2 @@ -module Lf_queue : sig ... end
A lock-free multi-producer, single-consumer, thread-safe queue without support for cancellation. This makes a good data structure for a scheduler's run queue.
module Suspended : sig ... end
A suspended fiber with its context.
module Zzz : sig ... end
A set of timers.
index (eio.index) eio index
\ No newline at end of file +Library eio
The entry point of this library is the module:
Eio
.Library eio.core
The entry point of this library is the module:
Eio__core
.Library eio.mock
The entry point of this library is the module:
Eio_mock
.Library eio.unix
The entry point of this library is the module:
Eio_unix
.Library eio.utils
The entry point of this library is the module:
Eio_utils
.index (eio.index) eio index
\ No newline at end of file diff --git a/eio_linux/Eio_linux/.dummy b/eio_linux/Eio_linux/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/eio_linux/Eio_linux/Low_level/Process/index.html b/eio_linux/Eio_linux/Low_level/Process/index.html index 2679b8a69..6e09a3b06 100644 --- a/eio_linux/Eio_linux/Low_level/Process/index.html +++ b/eio_linux/Eio_linux/Low_level/Process/index.html @@ -1,2 +1,2 @@ -Library eio
The entry point of this library is the module:
Eio
.Library eio.core
The entry point of this library is the module:
Eio__core
.Library eio.mock
The entry point of this library is the module:
Eio_mock
.Library eio.unix
The entry point of this library is the module:
Eio_unix
.Library eio.utils
The entry point of this library is the module:
Eio_utils
.Process (eio_linux.Eio_linux.Low_level.Process) Module
Low_level.Process
\ No newline at end of file +module Fork_action = Eio_unix.Private.Fork_action
Setup actions to perform in the child process.
val spawn : sw:Eio.Std.Switch.t -> Fork_action.t list -> t
spawn ~sw actions
forks a child process, which executesactions
. The last action should beFork_action.execve
.You will typically want to do
Promise.await (exit_status child)
after this.val signal : t -> int -> unit
signal t x
sends signalx
tot
.This is similar to doing
Unix.kill t.pid x
, except that it ensures no signal is sent aftert
has been reaped.val pid : t -> int
val exit_status : t -> Unix.process_status Eio.Std.Promise.t
exit_status t
is a promise for the process's exit status.Process (eio_linux.Eio_linux.Low_level.Process) Module
Low_level.Process
\ No newline at end of file diff --git a/eio_linux/Eio_linux/Low_level/index.html b/eio_linux/Eio_linux/Low_level/index.html index 1737d2ff1..13e1c47a6 100644 --- a/eio_linux/Eio_linux/Low_level/index.html +++ b/eio_linux/Eio_linux/Low_level/index.html @@ -1,5 +1,5 @@ -module Fork_action = Eio_unix.Private.Fork_action
Setup actions to perform in the child process.
val spawn : sw:Eio.Std.Switch.t -> Fork_action.t list -> t
spawn ~sw actions
forks a child process, which executesactions
. The last action should beFork_action.execve
.You will typically want to do
Promise.await (exit_status child)
after this.val signal : t -> int -> unit
signal t x
sends signalx
tot
.This is similar to doing
Unix.kill t.pid x
, except that it ensures no signal is sent aftert
has been reaped.val pid : t -> int
val exit_status : t -> Unix.process_status Eio.Std.Promise.t
exit_status t
is a promise for the process's exit status.Low_level (eio_linux.Eio_linux.Low_level) Module
Eio_linux.Low_level
Low-level API for using uring directly.
Time functions
Fixed-buffer memory allocation functions
The size of the fixed buffer is set when calling
run
, which attempts to allocate a fixed buffer. However, that may fail due to resource limits.Allocate a chunk of memory from the fixed buffer.
Warning: The memory is NOT zeroed out.
Passing such memory to Linux can be faster than using normal memory, in certain cases. There is a limited amount of such memory, and this will return
None
if none is available at present.Like
alloc_fixed
, but if there are no chunks available then it waits until one is.
with_chunk ~fallback fn
runsfn chunk
with a freshly allocated chunk and then frees it.If no chunks are available, it runs
fallback ()
instead.File manipulation functions
val openat2 : +
Low_level (eio_linux.Eio_linux.Low_level) Module
Eio_linux.Low_level
Low-level API for using uring directly.
Time functions
Fixed-buffer memory allocation functions
The size of the fixed buffer is set when calling
run
, which attempts to allocate a fixed buffer. However, that may fail due to resource limits.Allocate a chunk of memory from the fixed buffer.
Warning: The memory is NOT zeroed out.
Passing such memory to Linux can be faster than using normal memory, in certain cases. There is a limited amount of such memory, and this will return
None
if none is available at present.Like
alloc_fixed
, but if there are no chunks available then it waits until one is.
with_chunk ~fallback fn
runsfn chunk
with a freshly allocated chunk and then frees it.If no chunks are available, it runs
fallback ()
instead.File manipulation functions
val openat2 : sw:Eio.Std.Switch.t -> ?seekable:bool -> access:[ `R | `W | `RW ] -> diff --git a/eio_linux/Eio_linux/index.html b/eio_linux/Eio_linux/index.html index 439e2e89a..4ab252a98 100644 --- a/eio_linux/Eio_linux/index.html +++ b/eio_linux/Eio_linux/index.html @@ -1,5 +1,5 @@ -
Eio_linux (eio_linux.Eio_linux) Module
Eio_linux
Eio backend using Linux's io_uring.
You will normally not use this module directly. Instead, use
Eio_main
.run to start an event loop and then use the API in theEio
module.However, it is possible to use this module directly if you only want to support recent versions of Linux.
type fd := Eio_unix.Fd.t
Eio API
type source = Eio_unix.source
type sink = Eio_unix.sink
type stdenv = Eio_unix.Stdenv.base
Main Loop
val run : +
Eio_linux (eio_linux.Eio_linux) Module
Eio_linux
Eio backend using Linux's io_uring.
You will normally not use this module directly. Instead, use
Eio_main
.run to start an event loop and then use the API in theEio
module.However, it is possible to use this module directly if you only want to support recent versions of Linux.
type fd := Eio_unix.Fd.t
Main Loop
type stdenv = Eio_unix.Stdenv.base
val run : ?queue_depth:int -> ?n_blocks:int -> ?block_size:int -> diff --git a/eio_linux/index.html b/eio_linux/index.html index d69f86df0..925ecb29f 100644 --- a/eio_linux/index.html +++ b/eio_linux/index.html @@ -1,2 +1,2 @@ -
index (eio_linux.index) eio_linux index
\ No newline at end of file +Library eio_linux
The entry point of this library is the module:
Eio_linux
.index (eio_linux.index) eio_linux index
\ No newline at end of file diff --git a/eio_main/Eio_main/.dummy b/eio_main/Eio_main/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/eio_main/Eio_main/index.html b/eio_main/Eio_main/index.html index 3180843f4..53eb2b7c5 100644 --- a/eio_main/Eio_main/index.html +++ b/eio_main/Eio_main/index.html @@ -1,2 +1,2 @@ -Library eio_linux
The entry point of this library is the module:
Eio_linux
.Eio_main (eio_main.Eio_main) Module
Eio_main
Select a suitable event loop for Eio.
\ No newline at end of file +val run : (Eio_unix.Stdenv.base -> 'a) -> 'a
run fn
runs an event loop and then callsfn env
within it.
env
provides access to the process's environment (file-system, network, etc).env
itself and the resources inside it can be shared safely between Eio domains.When
fn
ends, the event loop finishes.This should be called once, at the entry point of an application. It must not be called by libraries. Doing so would force the library to depend on Unix (making it unusable from unikernels or browsers), prevent the user from choosing their own event loop, and prevent using the library with other Eio libraries.
run
will select an appropriate event loop for the current platform. On many systems, it will useEio_posix.run
.On recent-enough versions of Linux, it will use
Eio_linux.run
. You can override this by setting the $EIO_BACKEND environment variable to either "linux", "posix" or "windows".Eio_main (eio_main.Eio_main) Module
Eio_main
Select a suitable event loop for Eio.
\ No newline at end of file diff --git a/eio_main/index.html b/eio_main/index.html index 69d25c193..2b25d6efa 100644 --- a/eio_main/index.html +++ b/eio_main/index.html @@ -1,2 +1,2 @@ -val run : (Eio_unix.Stdenv.base -> 'a) -> 'a
run fn
runs an event loop and then callsfn env
within it.
env
provides access to the process's environment (file-system, network, etc).env
itself and the resources inside it can be shared safely between Eio domains.When
fn
ends, the event loop finishes.This should be called once, at the entry point of an application. It must not be called by libraries. Doing so would force the library to depend on Unix (making it unusable from unikernels or browsers), prevent the user from choosing their own event loop, and prevent using the library with other Eio libraries.
run
will select an appropriate event loop for the current platform. On many systems, it will useEio_posix.run
.On recent-enough versions of Linux, it will use
Eio_linux.run
. You can override this by setting the $EIO_BACKEND environment variable to either "linux", "posix" or "windows".index (eio_main.index) eio_main index
\ No newline at end of file +Library eio_main
The entry point of this library is the module:
Eio_main
.index (eio_main.index) eio_main index
\ No newline at end of file diff --git a/eio_posix/Eio_posix/.dummy b/eio_posix/Eio_posix/.dummy deleted file mode 100644 index e69de29bb..000000000 diff --git a/eio_posix/Eio_posix/Low_level/Open_flags/index.html b/eio_posix/Eio_posix/Low_level/Open_flags/index.html index 7150247df..adaaedbd4 100644 --- a/eio_posix/Eio_posix/Low_level/Open_flags/index.html +++ b/eio_posix/Eio_posix/Low_level/Open_flags/index.html @@ -1,2 +1,2 @@ -Library eio_main
The entry point of this library is the module:
Eio_main
.Open_flags (eio_posix.Eio_posix.Low_level.Open_flags) Module
Low_level.Open_flags
\ No newline at end of file +val rdonly : t
val rdwr : t
val wronly : t
val append : t
val creat : t
val directory : t
val dsync : t option
val excl : t
val noctty : t
val nofollow : t
val sync : t
val trunc : t
val resolve_beneath : t option
val path : t option
val empty : t
Open_flags (eio_posix.Eio_posix.Low_level.Open_flags) Module
Low_level.Open_flags
\ No newline at end of file diff --git a/eio_posix/Eio_posix/Low_level/Process/index.html b/eio_posix/Eio_posix/Low_level/Process/index.html index 5680b145f..f510e9e47 100644 --- a/eio_posix/Eio_posix/Low_level/Process/index.html +++ b/eio_posix/Eio_posix/Low_level/Process/index.html @@ -1,2 +1,2 @@ -val rdonly : t
val rdwr : t
val wronly : t
val append : t
val creat : t
val directory : t
val dsync : t option
val excl : t
val noctty : t
val nofollow : t
val sync : t
val trunc : t
val resolve_beneath : t option
val path : t option
val empty : t
Process (eio_posix.Eio_posix.Low_level.Process) Module
Low_level.Process
\ No newline at end of file +module Fork_action = Eio_unix.Private.Fork_action
Setup actions to perform in the child process.
val spawn : sw:Eio.Std.Switch.t -> Fork_action.t list -> t
spawn ~sw actions
forks a child process, which executesactions
. The last action should beFork_action.execve
.You will typically want to do
Promise.await (exit_status child)
after this.val signal : t -> int -> unit
signal t x
sends signalx
tot
.This is similar to doing
Unix.kill t.pid x
, except that it ensures no signal is sent aftert
has been reaped.val pid : t -> int
val exit_status : t -> Unix.process_status Eio.Std.Promise.t
exit_status t
is a promise for the process's exit status.Process (eio_posix.Eio_posix.Low_level.Process) Module
Low_level.Process
\ No newline at end of file diff --git a/eio_posix/Eio_posix/Low_level/index.html b/eio_posix/Eio_posix/Low_level/index.html index 818ea680e..b3824b2b2 100644 --- a/eio_posix/Eio_posix/Low_level/index.html +++ b/eio_posix/Eio_posix/Low_level/index.html @@ -1,10 +1,20 @@ -module Fork_action = Eio_unix.Private.Fork_action
Setup actions to perform in the child process.
val spawn : sw:Eio.Std.Switch.t -> Fork_action.t list -> t
spawn ~sw actions
forks a child process, which executesactions
. The last action should beFork_action.execve
.You will typically want to do
Promise.await (exit_status child)
after this.val signal : t -> int -> unit
signal t x
sends signalx
tot
.This is similar to doing
Unix.kill t.pid x
, except that it ensures no signal is sent aftert
has been reaped.val pid : t -> int
val exit_status : t -> Unix.process_status Eio.Std.Promise.t
exit_status t
is a promise for the process's exit status.Low_level (eio_posix.Eio_posix.Low_level) Module
Eio_posix.Low_level
Low-level API for making POSIX calls directly.
This module provides an effects-based API for calling POSIX functions.
Normally it's better to use the cross-platform
Eio
APIs instead, which uses these functions automatically where appropriate.These functions mostly copy the POSIX APIs directly, except that:
- They suspend the calling fiber instead of returning
EAGAIN
or similar.- They handle
EINTR
by automatically restarting the call.- They wrap
Unix
.file_descr inFd
, to avoid use-after-close bugs.- They attach new FDs to switches, to avoid resource leaks.
type fd := Eio_unix.Fd.t
val await_readable : fd -> unit
val await_writable : fd -> unit
val read : fd -> bytes -> int -> int -> int
val write : fd -> bytes -> int -> int -> int
val socket : +
Low_level (eio_posix.Eio_posix.Low_level) Module
Eio_posix.Low_level
Low-level API for making POSIX calls directly.
This module provides an effects-based API for calling POSIX functions.
Normally it's better to use the cross-platform
Eio
APIs instead, which uses these functions automatically where appropriate.These functions mostly copy the POSIX APIs directly, except that:
- They suspend the calling fiber instead of returning
EAGAIN
or similar.- They handle
EINTR
by automatically restarting the call.- They wrap
Unix
.file_descr inFd
, to avoid use-after-close bugs.- They attach new FDs to switches, to avoid resource leaks.
type fd := Eio_unix.Fd.t
val await_readable : fd -> unit
val await_writable : fd -> unit
val read : fd -> bytes -> int -> int -> int
val write : fd -> bytes -> int -> int -> int
val socket : sw:Eio.Std.Switch.t -> Unix.socket_domain -> Unix.socket_type -> int -> - fd
val connect : fd -> Unix.sockaddr -> unit
val accept : sw:Eio.Std.Switch.t -> fd -> fd * Unix.sockaddr
val shutdown : fd -> Unix.shutdown_command -> unit
val recv_msg : fd -> Cstruct.t array -> Unix.sockaddr * int
val send_msg : fd -> ?dst:Unix.sockaddr -> Cstruct.t array -> int
val fstat : fd -> Unix.LargeFile.stats
val mkdir : ?dirfd:fd -> mode:int -> string -> unit
val unlink : ?dirfd:fd -> dir:bool -> string -> unit
val readv : fd -> Cstruct.t array -> int
val writev : fd -> Cstruct.t array -> int
val preadv : file_offset:Optint.Int63.t -> fd -> Cstruct.t array -> int
val pwritev : file_offset:Optint.Int63.t -> fd -> Cstruct.t array -> int
val pipe : sw:Eio.Std.Switch.t -> fd * fd
module Open_flags : sig ... end
val openat : + fd
val connect : fd -> Unix.sockaddr -> unit
val accept : sw:Eio.Std.Switch.t -> fd -> fd * Unix.sockaddr
val shutdown : fd -> Unix.shutdown_command -> unit
val recv_msg : fd -> Cstruct.t array -> Unix.sockaddr * int
val recv_msg_with_fds : + sw:Eio.Std.Switch.t -> + max_fds:int -> + fd -> + Cstruct.t array -> + Unix.sockaddr * int * fd list
val fstat : fd -> Unix.LargeFile.stats
val mkdir : ?dirfd:fd -> mode:int -> string -> unit
val unlink : ?dirfd:fd -> dir:bool -> string -> unit
val readv : fd -> Cstruct.t array -> int
val writev : fd -> Cstruct.t array -> int
val preadv : file_offset:Optint.Int63.t -> fd -> Cstruct.t array -> int
val pwritev : file_offset:Optint.Int63.t -> fd -> Cstruct.t array -> int
val pipe : sw:Eio.Std.Switch.t -> fd * fd
module Open_flags : sig ... end
val openat : ?dirfd:fd -> sw:Eio.Std.Switch.t -> mode:int -> diff --git a/eio_posix/Eio_posix/index.html b/eio_posix/Eio_posix/index.html index 556ed5c25..1c23c003d 100644 --- a/eio_posix/Eio_posix/index.html +++ b/eio_posix/Eio_posix/index.html @@ -1,2 +1,2 @@ -
Eio_posix (eio_posix.Eio_posix) Module
Eio_posix
Fallback Eio backend for POSIX systems.
\ No newline at end of file +type stdenv = Eio_unix.Stdenv.base
The type of the standard set of resources available on POSIX systems.
val run : (stdenv -> 'a) -> 'a
run main
runs an event loop and callsmain stdenv
inside it.For portable code, you should use
Eio_main
.run instead, which will call this for you if appropriate.module Low_level : sig ... end
Low-level API for making POSIX calls directly.
Eio_posix (eio_posix.Eio_posix) Module
Eio_posix
Fallback Eio backend for POSIX systems.
\ No newline at end of file diff --git a/eio_posix/index.html b/eio_posix/index.html index 7b90817e9..f903af782 100644 --- a/eio_posix/index.html +++ b/eio_posix/index.html @@ -1,2 +1,2 @@ -type stdenv = Eio_unix.Stdenv.base
The type of the standard set of resources available on POSIX systems.
val run : (stdenv -> 'a) -> 'a
run main
runs an event loop and callsmain stdenv
inside it.For portable code, you should use
Eio_main
.run instead, which will call this for you if appropriate.module Low_level : sig ... end
Low-level API for making POSIX calls directly.
index (eio_posix.index) eio_posix index
\ No newline at end of file +Library eio_posix
The entry point of this library is the module:
Eio_posix
.index (eio_posix.index) eio_posix index
\ No newline at end of file diff --git a/eio_windows/index.html b/eio_windows/index.html index 3bda19958..343d8d67e 100644 --- a/eio_windows/index.html +++ b/eio_windows/index.html @@ -1,2 +1,2 @@ -Library eio_posix
The entry point of this library is the module:
Eio_posix
.index (eio_windows.index) \ No newline at end of file + eio_windows index
index (eio_windows.index) \ No newline at end of file diff --git a/index.html b/index.html index 373a00b5b..aacefbd83 100644 --- a/index.html +++ b/index.html @@ -11,11 +11,11 @@ eio_windows index
OCaml package documentation
-
- eio v0.11
-- eio_linux v0.11
-- eio_main v0.11
-- eio_posix v0.11
-- eio_windows v0.11
+- eio v0.11-43-gad7149d
+- eio_linux v0.11-43-gad7149d
+- eio_main v0.11-43-gad7149d
+- eio_posix v0.11-43-gad7149d
+- eio_windows v0.11-43-gad7149d