Module Lwt_engine
Lwt unix main loop engine
Events
type eventType of events. An event represent a callback registered to be called when some event occurs.
val stop_event : event -> unitstop_event event stops the given event.
val fake_event : eventEvent which does nothing when stopped.
Event loop functions
val iter : bool -> unititer 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.
on_readable fd f calls f each time fd becomes readable.
on_readable fd f calls f each time fd becomes writable.
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 -> intReturns the number of events waiting for a file descriptor to become readable.
val writable_count : unit -> intReturns the number of events waiting for a file descriptor to become writable.
val timer_count : unit -> intReturns the number of registered timers.
val fake_io : Unix.file_descr -> unitSimulates activity on the given file descriptor.
val fork : unit -> unitCalled internally by Lwt_unix.fork to make sure we don't get strange behaviour
val forwards_signal : int -> boolforwards_signal signum is true if the engine will call Lwt_unix.handle_signal when signal signum occurs. In this case, Lwt will not install its own signal handler.
Normally, this just returns false, but when Lwt is used in combination with other IO libraries, this allows sharing e.g. the SIGCHLD handler.
Engines
An engine represents a set of functions used to register different kinds of callbacks for different kinds of events.
type engine_id = ..val id : unit -> engine_idclass virtual abstract : object ... endAbstract class for engines.
class type t = object ... endType of engines.
Predefined engines
type ev_loopmodule Ev_backend : sig ... endType of libev loops.
type engine_id += | Engine_id__libev of Ev_backend.t
class libev : ?backend:Ev_backend.t -> unit -> object ... endEngine based on libev. If not compiled with libev support, the creation of the class will raise Lwt_sys.Not_available.
type engine_id += | Engine_id__select
Engine based on Unix.select.
type engine_id += | Engine_id__poll
class virtual select_based : object ... endAbstract class for engines based on a select-like function.
class virtual poll_based : object ... endAbstract class for engines based on a poll-like function.
The current engine
val get : unit -> tget () returns the engine currently in use.
val set : ?transfer:bool -> ?destroy:bool -> t -> unitset ?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 ... end