package core_unix

  1. Overview
  2. Docs
Unix-specific portions of Core

Install

Dune Dependency

Authors

Maintainers

Sources

v0.17.1.tar.gz
md5=9370dca36f518fcea046d2752e3de22b
sha512=c4e8ce9d5885ac8fa8d554a97e1857f3a1c933e0eb5dfd4fe874412b9d09e6d0a2973b644733855553f33f5c859719228f0e6aaf3a2b7eb5befb46fc513750de

doc/src/core_unix.linux_ext/epoll_intf.ml.html

Source file epoll_intf.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
open Base
open Core
open Core_unix

(** epoll(): a Linux I/O multiplexer of the same family as select() or poll().  Its main
    differences are support for Edge- or Level-triggered notifications (we're using
    Level-triggered to emulate "select") and much better scaling with the number of file
    descriptors.

    See the man pages for a full description of the epoll facility. *)

module type S = sig
  module Flags : sig
    (** An [Epoll.Flags.t] is an immutable set of flags for which one can register
        interest in a file descriptor.  It is implemented as a bitmask, and so all
        operations (+, -, etc.) are constant time with no allocation.

        [sexp_of_t] produces a human-readable list of bits, e.g., "(in out)". *)
    type t [@@deriving sexp_of]

    include Flags.S with type t := t

    (** The names of the flags match the man pages.  E.g. [in_] = "EPOLLIN", [out] =
        "EPOLLOUT", etc. *)

    (** Associated fd is readable                      *)
    val none : t

    (** Associated fd is readable                      *)
    val in_ : t

    (** Associated fd is writable                      *)
    val out : t

    (*_ val rdhup   : t (\* Event flag For detecting tcp half-close        *\) *)

    (** Urgent data available                          *)
    val pri : t

    (** Error condition (always on, no need to set it) *)
    val err : t

    (** Hang up happened (always on)                   *)
    val hup : t

    (** Edge-Triggered behavior (see man page)         *)
    val et : t

    (** One-shot behavior for the associated fd        *)
    val oneshot : t
  end

  (** An [Epoll.t] maintains a map from [File_descr.t] to [Flags.t], where the domain is
      the set of file descriptors that one is interested in, and the flags associated
      with each file descriptor specify the types of events one is interested in being
      notified about for that file descriptor.  Our implementation maintains a
      user-level table equivalent to the kernel epoll set, so that [sexp_of_t] produces
      useful human-readable information, and so that we can present our standard table
      interface.

      The implementation assumes that one never closes a file descriptor that is the
      domain of an [Epoll.t], since doing so might remove the [fd] from the kernel epoll
      set without the implementation's knowledge.

      An [Epoll.t] also has a buffer that is used to store the set of ready [fd]s
      returned by calling [wait]. *)
  type t [@@deriving sexp_of]

  val invariant : t -> unit

  (** [create ~num_file_descrs] creates a new epoll set able to watch file descriptors
      in \[0, [num_file_descrs]).  Additionally, the set allocates space for reading the
      "ready" events when [wait] returns, allowing for up to [max_ready_events] to be
      returned in a single call to [wait]. *)
  val create : (num_file_descrs:int -> max_ready_events:int -> t) Or_error.t

  val close : t -> unit

  (** Map operations *)

  (** [find] raises in the case that [t] is closed. *)
  val find : t -> File_descr.t -> Flags.t option

  val find_exn : t -> File_descr.t -> Flags.t
  val set : t -> File_descr.t -> Flags.t -> unit
  val remove : t -> File_descr.t -> unit
  val iter : t -> f:(File_descr.t -> Flags.t -> unit) -> unit
  val fold : t -> init:'a -> f:(File_descr.t -> Flags.t -> 'a -> 'a) -> 'a

  (** [wait t ~timeout] blocks until at least one file descriptor in [t] is ready for
      one of the events it is being watched for, or [timeout] passes.  [wait] side
      effects [t] by storing the ready set in it.  One can subsequently access the ready
      set by calling [iter_ready] or [fold_ready].

      With [wait ~timeout:(`After span)], [span <= 0] is treated as [0].  If [span > 0],
      then [span] is rounded to the nearest millisecond, with a minimum value of one
      millisecond.

      Note that this method should not be considered thread-safe.  There is mutable
      state in [t] that will be changed by invocations to [wait] that cannot be
      prevented by mutexes around [wait]. *)
  val wait
    :  t
    -> timeout:[ `Never | `Immediately | `After of Time_ns.Span.t ]
    -> [ `Ok | `Timeout ]

  (** [wait_timeout_after t span = wait t ~timeout:(`After span)].  [wait_timeout_after]
      is a performance hack to avoid allocating [`After span]. *)
  val wait_timeout_after : t -> Time_ns.Span.t -> [ `Ok | `Timeout ]

  (** [iter_ready] and [fold_ready] iterate over the ready set computed by the last
      call to [wait]. *)
  val iter_ready : t -> f:(File_descr.t -> Flags.t -> unit) -> unit

  val fold_ready : t -> init:'a -> f:('a -> File_descr.t -> Flags.t -> 'a) -> 'a

  module Expert : sig
    (** [clear_ready t] sets the number of ready events in [t] to [0]. This
        should be called after all the events in [t] have been processed,
        following a call to {!wait}. *)
    val clear_ready : t -> unit
  end

  (*_
    (* pwait -> with the specified sigmask, analogous to pselect *)
    (* val pwait   : t -> timeout:Span.t -> int list -> [ `Ok of Ready_fds.t | `Timeout ] *)
  *)
end
OCaml

Innovation. Community. Security.