package miou

  1. Overview
  2. Docs
module Cond : sig ... end

Due to our scheduler, we must re-implement few things like "Condition" to be able to wait and signal (or broadcast) our tasks. The suspension of a task must always be notified to Miou. It is possible to use real Condition.t with Miou - however, some mechanisms such as cancellation will not work.

The Unix layer of Miou.

This module offers a re-implementation of the I/O according to Miou's model. In addition to managing possible suspensions due to I/O, the module also provides a notion of "ownership" which checks at runtime whether the task is able to perform I/O on the file_descr used. It also checks (again at runtime) that these file_descr have been released.

For more information, please read the Miou.Ownership module.

type file_descr

Type of file-descriptors.

val read : file_descr -> bytes -> off:int -> len:int -> int

read fd buf ~off ~len reads len bytes from fd into buf starting at off. Return the number of bytes actually read.

val write : file_descr -> string -> off:int -> len:int -> unit

write fd str ~off ~len writes len bytes starting at off from str on fd.

val connect : file_descr -> Unix.sockaddr -> unit

connect fd sockaddr is a Miou friendly Unix.connect. The function accepts only file_descrs in non-blocking mode.

val accept : ?cloexec:bool -> file_descr -> file_descr * Unix.sockaddr

accept ?cloexec fd is a Miou friendly Unix.accept which returns file descritptors in non-blocking mode.

val close : file_descr -> unit

close fd closes and Miou.Ownership.disown properly the given fd. Its use ensures that there is no leakage of resources.

val sleep : float -> unit

sleep v suspends the current task and sleeps v seconds.

val of_file_descr : ?non_blocking:bool -> ?owner:Miou.Ownership.t -> Unix.file_descr -> file_descr

of_file_descr ?non_blocking ?owner fd creates a new file_descr. Depending on non_blocking (defaults to true), we set the given fd to non-blocking mode or not. The user can also specify the owner of the given fd. Otherwise, we consider the current task as the owner.

val to_file_descr : file_descr -> Unix.file_descr

to_file_descr fd returns the real Unix.file_descr.

owner fd returns the witness of the task's ownership. It is useful to pass the ownership to a sub-task:

let fd = tcpv4 () in
let p0 = Miou.call_cc ~give:[ owner fd ] @@ fun () ->
  connect fd addr; transfer fd in
Miou.await p0
val tcpv4 : unit -> file_descr

tcpv4 () allocates a new socket owned by the current task.

val tcpv6 : unit -> file_descr

tcpv6 () allocates a new socket owned by the current task.

val transfer : file_descr -> file_descr

transfer fd transfers the ownership of fd into the parent of the current task.

val disown : file_descr -> unit

disown fd informs Miou that the current task is not the owner of the given fd anymore. It's useful when you want to pass the given fd to another task.

val bind_and_listen : ?backlog:int -> file_descr -> Unix.sockaddr -> unit

bind_and_listen fd sockaddr binds the given socket to the given sockaddr and set up the given fd for receiving connection requests. backlog is the maximal number of pending requests.

val run : ?g:Random.State.t -> ?domains:int -> (unit -> 'a) -> 'a
OCaml

Innovation. Community. Security.