package eio
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=da260d9da38b3dde9f316652a20b13a261cf90b85a2498ac669b7d564e61942d
sha512=5886e1159f48ede237769baa1d8b5daafa0310e4192d7fe0e8c32aef70f2b6378cef72d0fbae308457e25d87a69802b9ee83a5e8f23e0591d83086a92d701c46
doc/eio.unix/Eio_unix/Fd/index.html
Module Eio_unix.Fd
Source
A safe wrapper for Unix.file_descr
.
A wrapper around a Unix.file_descr
.
Creation
val of_unix :
sw:Eio.Std.Switch.t ->
?blocking:bool ->
?seekable:bool ->
close_unix:bool ->
Unix.file_descr ->
t
of_unix ~sw ~close_unix fd
wraps fd
.
of_unix_list ~sw fds
is like List.map (of_unix ~sw ~close_unix:true) fds
, except that if sw
is off then it closes all the FDs.
Using FDs
use t fn ~if_closed
calls fn wrapped_fd
, ensuring that wrapped_fd
will not be closed before fn
returns.
If t
is already closed, it returns if_closed ()
instead.
use_exn op t fn
calls fn wrapped_fd
, ensuring that wrapped_fd
will not be closed before fn
returns.
If t
is already closed, it raises an exception, using op
as the name of the failing operation.
use_exn_list op fds fn
calls use_exn
on each FD in fds
, calling fn wrapped_fds
on the results.
use_exn_opt op fd fn
is like use_exn
, but if fd = None
then it just calls fn None
.
Closing
close t
marks t
as closed, so that use
can no longer be used to start new operations.
The wrapped FD will be closed once all current users of the FD have finished (unless close_unix = false
).
Has no effect if t
is already closed.
remove t
marks t
as closed, so that use
can no longer be used to start new operations.
It then waits for all current users of the wrapped FD to finish using it, and then returns the FD.
This operation suspends the calling fiber and so must run from an Eio fiber. It does not allow itself to be cancelled, since it takes ownership of the FD and that would be leaked if it aborted.
Returns None
if t
is closed by another fiber first.
is_open t
returns true
until t
has been marked as closing, after which it returns false
.
This is mostly useful inside the callback of use
, to test whether another fiber has started closing t
(in which case you may decide to stop early).
Flags
is_blocking t
returns the value of blocking
passed to of_unix
.
If not known, it first probes for it (and if the FD is already closed, returns false
).
is_seekable t
returns the value of seekable
passed to of_unix
.
If not known, it first probes for it (and if the FD is already closed, returns false
).