Source

ocaml_epoll / epoll.ml

Full commit
type t = Unix.file_descr

type flags

type flag = 
  | IN
  | PRI
  | OUT
  | RDNORM
  | RDBAND
  | WRNORM
  | WRBAND
  | MSG
  | ERR
  | HUP
  | RDHUP
  | ONESHOT
  | ET 

external make_flags : flag array -> flags = "caml_to_c_epoll_event_flags"
external get_flags  : flags -> flag list  = "c_to_caml_epoll_event_flags"

external create  : int -> t = "caml_epoll_create"
let close = Unix.close

external ctl_add : t -> Unix.file_descr -> flags -> unit = "caml_epoll_ctl_add"
external ctl_mod : t -> Unix.file_descr -> flags -> unit = "caml_epoll_ctl_mod"
external ctl_del : t -> Unix.file_descr -> unit          = "caml_epoll_ctl_del"

external wait : t -> maxevents:int -> timeout:int -> (Unix.file_descr * flags) array = "caml_epoll_wait"
  (* CR jfuruse: 
     It creates an array, which causes lots of allocations. 
     We can optimize this by just copying the memory area and provide special iterator on it. *)