Module Affect_unix.Unix

Unix module overriden with cooperative functions and actions.

Warning. Most of the functionality of this module relies on an Unix.unblocker being setup on the executing domain.

The full Unix module from the OCaml unix library is included here. It is hidden from the docs due to a suboptimal reading experience.

  include module type of Unix
    with type file_descr = Unix.file_descr
     and …

File descriptor operations

val close_noerr : Unix.file_descr -> unit

close_noerr is like Unix.close but never raises.

Sockets

val socket : ?cloexec:bool -> Unix.socket_domain -> Unix.socket_type -> int -> Unix.file_descr

socket is like Unix.socket except it has cloexec set to true by default and it sets the socket to non-blocking mode with Unix.set_nonblock.

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

accept is a cooperative Unix.accept.

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

connect is a cooperative Unix.connect.

Reads

val read : Unix.file_descr -> bytes -> int -> int -> int

read is a cooperative Unix.read.

Writes

val write : Unix.file_descr -> bytes -> int -> int -> int

write is a cooperative Unix.write.

val single_write : Unix.file_descr -> bytes -> int -> int -> int

write is a cooperative Unix.single_write.

Actions

val wait_readable : Unix.file_descr -> 'tag -> 'tag Affect.Action.t

wait_readable fd tag is the action used by the read operations and accept. The action invocation is enabled and synchronizes with tag whenever the non-blocking file descriptor fd becomes available for reading.

val wait_writable : Unix.file_descr -> 'tag -> 'tag Affect.Action.t

wait_writable fd tag is the action used by the write operations and connect. The action invocation is enabled and synchronizes with tag whenever the non-blocking file descriptor fd becomes available for writing.

Signals

module Signal : sig ... end

Waiting on signals.

Unblocking the cooperants

val unblocker : unit -> Affect.Action.unblocker

unblocker () is an action unblocker to use with Affect.Fun.Async.main for handling actions from Unix, Mtime and Ptime.

val main : ?sigpipe:Signal.handler -> ?domain_spawn:((unit -> unit) -> unit Stdlib.Domain.t) -> ?domain_count:int -> ?schedule:Affect.Fun.Async.Schedule.t -> ?handler:Affect.Fun.Async.Call_handler.t -> (unit -> 'a) -> 'a

Invoking main expands to:

Unix.Signal.set_and_restore Sys.sigpipe sigpipe @@ fun () ->
let unblocker = Unix.unblocker () in
Fun.Async.main ~unblocker ?domain_spawn ?domain_count ?schedule ?handler f

The default of sigpipe is Unix.Signal.handler.Ignore which is the right default.

Cooperation strategy

Changes from the Unix module

Altered functions

Additions