package polly

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Module Polly provides access to the Linux epoll system call for monitoring a set of file descriptors for events that the client is interested in.

type t
val create : unit -> t

create () returns an epoll(2) file descriptor which is passed later to wait, add, upd, and del. It must be passed to close when no longer needed.

val close : t -> unit

close t closes the file descriptor underlying t

module Events : sig ... end
val add : t -> Unix.file_descr -> Events.t -> unit

add epoll fd events registers fd with epoll to monitor for events

val upd : t -> Unix.file_descr -> Events.t -> unit

upd epoll fd events updates the events set of fd where fd has been previously been registered. upd is called mod in the Linux documentation but mod is already an infix operator in OCaml.

val del : t -> Unix.file_descr -> unit

del epoll fd unregister fd from epoll

val wait : t -> int -> int -> (t -> Unix.file_descr -> Events.t -> unit) -> int

wait epoll max timeout f waits for events on the fds registered with epoll to happen or to return after timeout. When fds are found to be ready, wait iterates over them by calling f epoll fd events. f receives epoll, the fd being monitored, and the events. At most max fds are being iterated over by a call to wait. Note that still more than max fds could be ready to be processed - they would be handled by the next call to wait.

It is important to address the events that trigger an fd to be handled as otherwise the same fd will be handled again at the next call to wait, leading to a tight loop. This is worth checking using strace(1).

See the epoll_wait(2) manual page for the details of the system call.

  • parameter epoll

    epoll

  • parameter max

    max fds to handle

  • parameter init

    initial value passed to f below

  • parameter f

    callback

  • returns

    number of fds ready, 0 = timeout

val wait_fold : t -> int -> int -> 'a -> (t -> Unix.file_descr -> Events.t -> 'a -> 'a) -> 'a

wait_fold epoll max timeout init f works similar to wait except that function f additionally receives and produces a value of type 'a that is threaded through the invocations of f; the final value is returned.

  • parameter epoll

    epoll

  • parameter max

    max fds to handle

  • parameter timeout

    timeout in milliseconds: -1 = wait forever

  • parameter init

    initial value passed to f below

  • parameter f

    callback

  • returns

    number of fds ready, 0 = timeout

module EventFD : sig ... end

This module provides an interface to the eventfd(2) system call

OCaml

Innovation. Community. Security.