package affect

  1. Overview
  2. Docs

Module Affect_unix.UnixSource

Unix module overriden with cooperative functions and actions.

  • The module tries to be as faithfull as possible to the OCaml Unix module so that there are few surprises when one is swapped for the other.
  • Using this module does not automatically make all of its functionality cooperative, some functions may still block your asynchronous functions. Cooperativeness is gradually added on best-effort basis, see the list of functions that have their behaviour changed.

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

Sourceval close_noerr : Unix.file_descr -> unit

close_noerr is like Unix.close but never raises.

Sockets

Sourceval 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.

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

accept is a cooperative Unix.accept.

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

connect is a cooperative Unix.connect.

Reads

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

read is a cooperative Unix.read.

read_bigarray is a cooperative Unix.read_bigarray.

Writes

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

write is a cooperative Unix.write.

Sourceval write_bigarray : Unix.file_descr -> (_, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t -> int -> int -> int

write_bigarray is a cooperative Unix.write_bigarray.

Sourceval write_substring : Unix.file_descr -> string -> int -> int -> int

write_substring is a cooperative Unix.write_substring.

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

single_write is a cooperative Unix.single_write.

Sourceval single_write_bigarray : Unix.file_descr -> (_, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t -> int -> int -> int

single_write_bigarray is a cooperative Unix.single_write_bigarray.

Sourceval single_write_substring : Unix.file_descr -> string -> int -> int -> int

single_write_substring is a cooperative Unix.single_write_substring.

Actions

Sourceval 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.

Sourceval 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

Sourcemodule Signal : sig ... end

Waiting on signals.

Unblocking the cooperants

Sourceval 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.

Sourceval main : ?sigpipe:Signal.handler -> ?domain_spawn:((unit -> unit) -> unit 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.

Changes from the Unix module

Altered functions

Additions