-
Notifications
You must be signed in to change notification settings - Fork 177
/
Copy pathlwt_engine.mli
221 lines (166 loc) · 6.85 KB
/
lwt_engine.mli
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
(* This file is part of Lwt, released under the MIT license. See LICENSE.md for
details, or visit https://github.com/ocsigen/lwt/blob/master/LICENSE.md. *)
(** Lwt unix main loop engine *)
(** {2 Events} *)
type event
(** Type of events. An event represent a callback registered to be
called when some event occurs. *)
val stop_event : event -> unit
(** [stop_event event] stops the given event. *)
val fake_event : event
(** Event which does nothing when stopped. *)
(** {2 Event loop functions} *)
val iter : bool -> unit
(** [iter block] performs one iteration of the main loop. If [block]
is [true] the function must block until one event becomes
available, otherwise it should just check for available events
and return immediately. *)
val on_readable : Unix.file_descr -> (event -> unit) -> event
(** [on_readable fd f] calls [f] each time [fd] becomes readable. *)
val on_writable : Unix.file_descr -> (event -> unit) -> event
(** [on_readable fd f] calls [f] each time [fd] becomes writable. *)
val on_timer : float -> bool -> (event -> unit) -> event
(** [on_timer delay repeat f] calls [f] one time after [delay]
seconds. If [repeat] is [true] then [f] is called each [delay]
seconds, otherwise it is called only one time. *)
val readable_count : unit -> int
(** Returns the number of events waiting for a file descriptor to
become readable. *)
val writable_count : unit -> int
(** Returns the number of events waiting for a file descriptor to
become writable. *)
val timer_count : unit -> int
(** Returns the number of registered timers. *)
val fake_io : Unix.file_descr -> unit
(** Simulates activity on the given file descriptor. *)
(** {2 Engines} *)
(** An engine represents a set of functions used to register different
kinds of callbacks for different kinds of events. *)
(** Abstract class for engines. *)
class virtual abstract : object
method destroy : unit
(** Destroy the engine, remove all its events and free its
associated resources. *)
method transfer : abstract -> unit
(** [transfer engine] moves all events from the current engine to
[engine]. Note that timers are reset in the destination
engine, i.e. if a timer with a delay of 2 seconds was
registered 1 second ago it will occur in 2 seconds in the
destination engine. *)
(** {2 Event loop methods} *)
method virtual iter : bool -> unit
method on_readable : Unix.file_descr -> (event -> unit) -> event
method on_writable : Unix.file_descr -> (event -> unit) -> event
method on_timer : float -> bool -> (event -> unit) -> event
method fake_io : Unix.file_descr -> unit
method readable_count : int
method writable_count : int
method timer_count : int
(** {2 Backend methods} *)
(** Notes:
- the callback passed to register methods is of type [unit -> unit]
and not [event -> unit]
- register methods return a lazy value which unregisters the
event when forced
*)
method virtual private cleanup : unit
(** Cleanup resources associated with the engine. *)
method virtual private register_readable : Unix.file_descr -> (unit -> unit) -> unit Lazy.t
method virtual private register_writable : Unix.file_descr -> (unit -> unit) -> unit Lazy.t
method virtual private register_timer : float -> bool -> (unit -> unit) -> unit Lazy.t
end
(** Type of engines. *)
class type t = object
inherit abstract
method iter : bool -> unit
method private cleanup : unit
method private register_readable : Unix.file_descr -> (unit -> unit) -> unit Lazy.t
method private register_writable : Unix.file_descr -> (unit -> unit) -> unit Lazy.t
method private register_timer : float -> bool -> (unit -> unit) -> unit Lazy.t
end
(** {2 Predefined engines} *)
type ev_loop
module Ev_backend :
sig
type t
val default : t
val select : t
val poll : t
val epoll : t
val kqueue : t
val devpoll : t
val port : t
val pp : Format.formatter -> t -> unit
end
(** Type of libev loops. *)
(** Engine based on libev. If not compiled with libev support, the
creation of the class will raise {!Lwt_sys.Not_available}. *)
class libev : ?backend:Ev_backend.t -> unit -> object
inherit t
val loop : ev_loop
(** The libev loop used for this engine. *)
method loop : ev_loop
(** Returns [loop]. *)
end
(** Engine based on [Unix.select]. *)
class select : t
(** Abstract class for engines based on a select-like function. *)
class virtual select_based : object
inherit t
method private virtual select : Unix.file_descr list -> Unix.file_descr list -> float -> Unix.file_descr list * Unix.file_descr list
(** [select fds_r fds_w timeout] waits for either:
- one of the file descriptor of [fds_r] to become readable
- one of the file descriptor of [fds_w] to become writable
- timeout to expire
and returns the list of readable file descriptor and the list
of writable file descriptors. *)
end
(** Abstract class for engines based on a poll-like function. *)
class virtual poll_based : object
inherit t
method private virtual poll : (Unix.file_descr * bool * bool) list -> float -> (Unix.file_descr * bool * bool) list
(** [poll fds tiomeout], where [fds] is a list of tuples of the
form [(fd, check_readable, check_writable)], waits for either:
- one of the file descriptor with [check_readable] set to
[true] to become readable
- one of the file descriptor with [check_writable] set to
[true] to become writable
- timeout to expire
and returns the list of file descriptors with their readable
and writable status. *)
end
(** {2 The current engine} *)
val get : unit -> t
(** [get ()] returns the engine currently in use. *)
val set : ?transfer : bool -> ?destroy : bool -> #t -> unit
(** [set ?transfer ?destroy engine] replaces the current engine by
the given one.
If [transfer] is [true] (the default) all events from the
current engine are transferred to the new one.
If [destroy] is [true] (the default) then the current engine is
destroyed before being replaced. *)
module Versioned :
sig
class libev_1 : object
inherit t
val loop : ev_loop
method loop : ev_loop
end
[@@ocaml.deprecated
" Deprecated in favor of Lwt_engine.libev. See
https://github.com/ocsigen/lwt/pull/269"]
(** Old version of {!Lwt_engine.libev}. The current {!Lwt_engine.libev} allows
selecting the libev back end.
@deprecated Use {!Lwt_engine.libev}.
@since 2.7.0 *)
class libev_2 : ?backend:Ev_backend.t -> unit -> object
inherit t
val loop : ev_loop
method loop : ev_loop
end
[@@ocaml.deprecated
" In Lwt >= 3.0.0, this is an alias for Lwt_engine.libev."]
(** Since Lwt 3.0.0, this is just an alias for {!Lwt_engine.libev}.
@deprecated Use {!Lwt_engine.libev}.
@since 2.7.0 *)
end