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.result
apply queue f v
appliesf v
onqueue
and catchesUnix
.Unix_error.EINTR
is handled by retrying the call.
val call : ('a -> 'b) -> 'a -> ('b, [> error ]) Fut.result
call f v
appliesf v
synchronously and catchesUnix
.Unix_error.EINTR
is handled by retrying the call.
Signals
val signal : int -> int Fut.t
signal s
determines withs
the next time the signals
is received by the program.Warning. The first time
signal s
is called for a givens
Fut
overwrites any handler that could be already installed bySys
.signal for that signal. Conversly if any other part of the program overwrites the handler installed byFut
fors
don't expect the futures returned bysignal s
to ever determine.
File descriptors
val nonblock_stdio : unit -> (unit, [> error ]) Fut.result
nonblock_stdio ()
setsUnix
.stdin,Unix
.stdout,Unix
.stderr to non-blocking mode.
val close : Unix.file_descr -> (unit, [> error ]) Fut.result
close fd
is likeUnix.close fd
, except it handlesEINTR
and sets any pending read or write onfd
to never determine.
val dup2 : Unix.file_descr -> Unix.file_descr -> (unit, [> error ]) Fut.result
dup2 fd1 fd2
is likeUnix.dup2 fd1 fd2
, except it handlesEINTR
and sets any pending read or write onfd2
to never determine.
val pipe : unit -> (Unix.file_descr * Unix.file_descr, [> error ]) Fut.result
pipe ()
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.result
socket d t p
is likeUnix.socket d t p
except 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.result
socketpair d t p
is likeUnix.socketpair d t p
except it sets the resulting file descriptors to non-blocking mode withUnix.set_nonblock
.
val accept : Unix.file_descr -> Unix.file_descr * Unix.sockaddr
accept fd
is likeUnix.accept fd
except it handlesEINTR
andEWOULDBLOCK
and sets the resulting file descriptor to non-blocking mode withUnix.set_nonblock
.
val connect : Unix.file_descr -> Unix.sockaddr -> (unit, [> error ]) Fut.result
connect
is likeUnix
.connect except it handlesEINTR
andEINPROGRESS
.
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.result
read fd s j l
is likeUnix.read fd s j l
except it handlesEINTR
,EAGAIN
andEWOULDBLOCK
. It is set to never determine iffd
is closed withclose
ordup2
.
val write : Unix.file_descr -> Stdlib.Bytes.t -> int -> int -> (int, [> error ]) Fut.result
write fd s j l
is likeUnix.single_write fd s j l
except it handlesEINTR
,EAGAIN
andEWOULDBLOCK
. It is set to never determine iffd
is closed withclose
ordup2
.