package eio_posix

  1. Overview
  2. Docs

Module Low_level.FdSource

A safe wrapper for Unix.file_descr.

Sourcetype t

A wrapper around a Unix.file_descr.

Sourceval of_unix : sw:Eio.Std.Switch.t -> blocking:bool -> close_unix:bool -> Unix.file_descr -> t

of_unix ~sw ~blocking ~close_unix fd wraps fd.

  • parameter sw

    Close fd automatically when sw is finished.

  • parameter blocking

    Indicates whether fd is in blocking mode. Normally you should call Unix.set_nonblock fd first and pass false here.

  • parameter close_unix

    Whether close also closes fd (this should normally be true).

Sourceval use_exn : string -> t -> (Unix.file_descr -> 'a) -> 'a

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.

Sourceval close : t -> unit

close t marks t as closed, so that use_exn 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).

Sourceval is_blocking : t -> bool

is_blocking t returns the value of blocking passed to of_unix.

Sourceval stdin : t
Sourceval stdout : t
Sourceval stderr : t
Sourceval to_unix : [ `Peek | `Take ] -> t -> Unix.file_descr

to_unix `Take t closes t without closing the wrapped FD, which it returns to the caller once all operations on it have finished.

to_unix `Peek t returns the wrapped FD directly. You must ensure that it is not closed while using it.

Get the underlying ref-counted FD. Note: you must not close this directly, as that will not remove the hook.

Sourcetype has_fd = < fd : t >

Resources that have FDs are sub-types of has_fd.

Sourcetype Eio.Generic.ty +=
  1. | FD : t Eio.Generic.ty
    (*

    Resources that wrap FDs can handle this in their probe method to expose the FD.

    *)
Sourceval get_fd_opt : Eio.Generic.t -> t option

get_fd_opt r returns the t being wrapped by a resource, if any.

This just probes r using FD.

OCaml

Innovation. Community. Security.