package eio_posix

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Low-level API for making POSIX calls directly.

This module provides an effects-based API for calling POSIX functions.

Normally it's better to use the cross-platform Eio APIs instead, which uses these functions automatically where appropriate.

These functions mostly copy the POSIX APIs directly, except that:

  1. They suspend the calling fiber instead of returning EAGAIN or similar.
  2. They handle EINTR by automatically restarting the call.
  3. They wrap Unix.file_descr in Fd, to avoid use-after-close bugs.
  4. They attach new FDs to switches, to avoid resource leaks.
type fd := Eio_unix.Fd.t
type dir_fd =
  1. | Fd of fd
    (*

    Confined to fd.

    *)
  2. | Cwd
    (*

    Confined to "."

    *)
  3. | Fs
    (*

    Unconfined "."; also allows absolute paths

    *)
val await_readable : string -> fd -> unit
val await_writable : string -> fd -> unit
val sleep_until : Mtime.t -> unit
val read : fd -> bytes -> int -> int -> int
val write : fd -> bytes -> int -> int -> int
val socket : sw:Eio.Std.Switch.t -> Unix.socket_domain -> Unix.socket_type -> int -> fd
val connect : fd -> Unix.sockaddr -> unit
val accept : sw:Eio.Std.Switch.t -> fd -> fd * Unix.sockaddr
val shutdown : fd -> Unix.shutdown_command -> unit
val recv_msg : fd -> Cstruct.t array -> Unix.sockaddr * int
val recv_msg_with_fds : sw:Eio.Std.Switch.t -> max_fds:int -> fd -> Cstruct.t array -> Unix.sockaddr * int * fd list
val send_msg : fd -> ?fds:fd list -> ?dst:Unix.sockaddr -> Cstruct.t array -> int
val getrandom : Cstruct.t -> unit
val lseek : fd -> Optint.Int63.t -> [ `Set | `Cur | `End ] -> Optint.Int63.t
val fsync : fd -> unit
val ftruncate : fd -> Optint.Int63.t -> unit
type stat
val create_stat : unit -> stat
val fstat : buf:stat -> fd -> unit
val fstatat : buf:stat -> follow:bool -> dir_fd -> string -> unit
val blksize : stat -> int64
val uid : stat -> int64
val gid : stat -> int64
val ino : stat -> int64
val size : stat -> int64
val rdev : stat -> int64
val dev : stat -> int64
val perm : stat -> int
val mode : stat -> int
val kind : stat -> Eio.File.Stat.kind
val atime_sec : stat -> int64
val ctime_sec : stat -> int64
val mtime_sec : stat -> int64
val atime_nsec : stat -> int
val ctime_nsec : stat -> int
val mtime_nsec : stat -> int
val realpath : string -> string
val mkdir : mode:int -> dir_fd -> string -> unit
val rename : dir_fd -> string -> dir_fd -> string -> unit
val readdir : dir_fd -> string -> string array
val readv : fd -> Cstruct.t array -> int
val writev : fd -> Cstruct.t array -> int
val preadv : file_offset:Optint.Int63.t -> fd -> Cstruct.t array -> int
val pwritev : file_offset:Optint.Int63.t -> fd -> Cstruct.t array -> int
val pipe : sw:Eio.Std.Switch.t -> fd * fd
module Open_flags : sig ... end
val openat : sw:Eio.Std.Switch.t -> mode:int -> dir_fd -> string -> Open_flags.t -> fd

Note: the returned FD is always non-blocking and close-on-exec.

module Process : sig ... end
OCaml

Innovation. Community. Security.