Module Futu
Unix system calls as futures.
This module wraps Unix system calls that support asynchronous operation and a few other as futures abstracting away the underylying IO multiplexing mechanism.
For other blocking Unix system calls you can invoke them with Unix.apply which uses future queues to perform the call, catches unix errors and automatically handles the EINTR error by retrying the call.
Important. File descriptors created outside this module must be set to non-blocking mode with Unix.set_nonblock before they are used with functions of this module.
%%VERSION%% — homepage
Unix results and errors
type error=[|`Unix of Unix.error * string * string]The type for Unix errors as reported by
Unix.Unix_error exceptions.
val apply : ?queue:Fut.queue -> ('a -> 'b) -> 'a -> ('b, [> error ]) Fut.resultapply queue f vappliesf vonqueueand catchesUnix.Unix_error.EINTRis handled by retrying the call.
val call : ('a -> 'b) -> 'a -> ('b, [> error ]) Fut.resultcall f vappliesf vsynchronously and catchesUnix.Unix_error.EINTRis handled by retrying the call.
Signals
val signal : int -> int Fut.tsignal sdetermines withsthe next time the signalsis received by the program.Warning. The first time
signal sis called for a givensFutoverwrites any handler that could be already installed bySys.signal for that signal. Conversly if any other part of the program overwrites the handler installed byFutforsdon't expect the futures returned bysignal sto ever determine.
File descriptors
val nonblock_stdio : unit -> (unit, [> error ]) Fut.resultnonblock_stdio ()setsUnix.stdin,Unix.stdout,Unix.stderr to non-blocking mode.
val close : Unix.file_descr -> (unit, [> error ]) Fut.resultclose fdis likeUnix.close fd, except it handlesEINTRand sets any pending read or write onfdto never determine.
val dup2 : Unix.file_descr -> Unix.file_descr -> (unit, [> error ]) Fut.resultdup2 fd1 fd2is likeUnix.dup2 fd1 fd2, except it handlesEINTRand sets any pending read or write onfd2to never determine.
val pipe : unit -> (Unix.file_descr * Unix.file_descr, [> error ]) Fut.resultpipe ()is likeUnix.pipe (), except is sets both file descriptors to non-blocking mode withUnix.set_nonblock.
Sockets
val socket : Unix.socket_domain -> Unix.socket_type -> int -> (Unix.file_descr, [> error ]) Fut.resultsocket d t pis likeUnix.socket d t pexcept it sets the resulting file descriptor to non-blocking mode withUnix.set_nonblock.
val socketpair : Unix.socket_domain -> Unix.socket_type -> int -> (Unix.file_descr * Unix.file_descr, [> error ]) Fut.resultsocketpair d t pis likeUnix.socketpair d t pexcept it sets the resulting file descriptors to non-blocking mode withUnix.set_nonblock.
val accept : Unix.file_descr -> Unix.file_descr * Unix.sockaddraccept fdis likeUnix.accept fdexcept it handlesEINTRandEWOULDBLOCKand sets the resulting file descriptor to non-blocking mode withUnix.set_nonblock.
val connect : Unix.file_descr -> Unix.sockaddr -> (unit, [> error ]) Fut.resultconnectis likeUnix.connect except it handlesEINTRandEINPROGRESS.
val bind : Unix.file_descr -> Unix.sockaddr -> (unit, [> error ]) Fut.result
IO
Important. If you use these functions on a file descriptor fd use close and dup2 instead of the corresponding functions of the Unix module. This will prevent any EBADF errors if there are undetermined futures concerning fd.
val read : Unix.file_descr -> Stdlib.Bytes.t -> int -> int -> (int, [> error ]) Fut.resultread fd s j lis likeUnix.read fd s j lexcept it handlesEINTR,EAGAINandEWOULDBLOCK. It is set to never determine iffdis closed withcloseordup2.
val write : Unix.file_descr -> Stdlib.Bytes.t -> int -> int -> (int, [> error ]) Fut.resultwrite fd s j lis likeUnix.single_write fd s j lexcept it handlesEINTR,EAGAINandEWOULDBLOCK. It is set to never determine iffdis closed withcloseordup2.