package devkit

  1. Overview
  2. Docs

Asynchronous IO helpers

module Ev = Libevent
module Internal : sig ... end
val simple_event : Ev.event_base -> ?ev:Ev.event -> ?timeout:float -> Unix.file_descr -> Ev.event_flags list -> (Ev.event -> Unix.file_descr -> Ev.event_flags -> unit) -> Ev.event

Create a new event or use the provided ev and make it persistent with the infinite timeout (or use the provided timeout). Schedule this event with provided callback f. Don't forget del to unschedule.

val setup_simple_event : Ev.event_base -> ?ev:Ev.event -> ?timeout:float -> Unix.file_descr -> Ev.event_flags list -> (Ev.event -> Unix.file_descr -> Ev.event_flags -> unit) -> unit
type result =
  1. | End
  2. | Data of int
  3. | Block
  4. | Exn of exn
val read_some : Unix.file_descr -> bytes -> int -> int -> result
val write_some : Unix.file_descr -> string -> int -> int -> int
val read_available : limit:int -> Unix.file_descr -> [> `Chunk of string * bool | `Limit of string ]

Read out all immediately available input (no blocking)

  • returns

    `Limit when limit is exceeded, `Chunk (data,final) otherwise

val show_error : [< `Eof | `EofImm | `Exn of exn | `ExnImm of exn | `Timeout ] -> string
val read_buf : Ev.event_base -> ?ev:Ev.event -> ?timeout:float -> bytes -> Unix.file_descr -> ([> `Eof | `EofImm | `Exn of exn | `ExnImm of exn | `Timeout ] -> int -> unit) -> (bytes -> unit) -> unit

read_buf buf fd err k - asynchronously fill buf with data from fd and call k buf when done (buffer is full). fd should be nonblocking. Call err on error (EOF).

val read_n : Ev.event_base -> ?ev:Ev.event -> ?timeout:float -> int -> Unix.file_descr -> ([> `Eof | `EofImm | `Exn of exn | `ExnImm of exn | `Timeout ] -> int -> unit) -> (string -> unit) -> unit
val periodic_timer_0 : Ev.event_base -> bool ref -> float -> float -> ?name:string -> (unit -> unit) -> Ev.event

Call f with delay-second pauses between invocations. Set stop to true to stop the timer. NB do not Ev.del the event inside the f callback.

val periodic_timer_now : Ev.event_base -> ?stop:bool ref -> float -> ?name:string -> (unit -> unit) -> Ev.event
val periodic_timer_wait : Ev.event_base -> ?stop:bool ref -> float -> ?name:string -> (unit -> unit) -> Ev.event
val setup_periodic_timer_now : Ev.event_base -> ?stop:bool ref -> float -> ?name:string -> (unit -> unit) -> unit
val setup_periodic_timer_wait : Ev.event_base -> ?stop:bool ref -> float -> ?name:string -> (unit -> unit) -> unit
module Peer : sig ... end
val delay : Ev.event_base -> float -> ('a -> unit) -> 'b -> unit
val poll : Ev.event_base -> unit