package affect
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha512=b328f6696e60c489da8cc2e8fad0537ca6634a39fc0c5de5840d4f98561f110617ef79ba8285ee8427dd99908c6b3d39114973598cddc5ded91abcce3b91b9a6
doc/affect.unix/Affect_unix/Unix/index.html
Module Affect_unix.UnixSource
Unix module overriden with cooperative functions and actions.
- The module tries to be as faithfull as possible to the OCaml
Unixmodule 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
close_noerr is like Unix.close but never raises.
Sockets
val socket :
?cloexec:bool ->
Unix.socket_domain ->
Unix.socket_type ->
int ->
Unix.file_descrsocket 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.
accept is a cooperative Unix.accept.
connect is a cooperative Unix.connect.
Reads
read is a cooperative Unix.read.
val read_bigarray :
Unix.file_descr ->
(_, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t ->
int ->
int ->
intread_bigarray is a cooperative Unix.read_bigarray.
Writes
write is a cooperative Unix.write.
val write_bigarray :
Unix.file_descr ->
(_, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t ->
int ->
int ->
intwrite_bigarray is a cooperative Unix.write_bigarray.
write_substring is a cooperative Unix.write_substring.
single_write is a cooperative Unix.single_write.
val single_write_bigarray :
Unix.file_descr ->
(_, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t ->
int ->
int ->
intsingle_write_bigarray is a cooperative Unix.single_write_bigarray.
single_write_substring is a cooperative Unix.single_write_substring.
Actions
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.
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
Unblocking the cooperants
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 Domain.t) ->
?domain_count:int ->
?schedule:Affect.Fun.Async.Schedule.t ->
?handler:Affect.Fun.Async.Call_handler.t ->
(unit -> 'a) ->
'aInvoking 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 fThe default of sigpipe is Unix.Signal.handler.Ignore which is the right default.
Changes from the Unix module
Altered functions
accept, assume a non-blocking file descriptor, handlesEWOULDBLOCKandEGAINby invokingwait_readable.connect, assumes a non-blocking file descriptor, handleEINPROGRESSby invokingwait_readableand after that checks if an error occcured withUnix.getsockopt_errorsocket, after the socket is created it is directly set to non-blocking mode with a call toUnix.set_nonblock.read,read_bigarray,write,write_bigarray,write_substring,single_write,single_write_bigarray,single_write_substringassume a non-blocking file descriptor and handlesEWOULDBLOCKandEAGAINby invokingwait_readableorwait_writable.
Additions
- The
Signalmodule is added.