Module Cf_poll


module Cf_poll: sig .. end
I/O event multiplexing.


Overview

This module implements an abstraction useful for multiplexing I/O events within a single thread of control. Use this module in cases when a program must block until an I/O event is ready at one of a collection of system resources.

Note: On some platforms in the future, this module may be implemented around a specialized kernel event queue, e.g. /dev/poll on Solaris, or kevent/kqueue on Mac OS X. In this early implementation, however, the module is implemented as a wrapper around Unix.select on all platforms.

Types

type t 
A polling mux.

type more =
| More
| Last
The sum type of results from cycling a polling mux.

type 'a state =
| Unloaded
| Loaded of t
| Working of t * 'a
| Final of 'a
| Exception of exn
The basic polymorphic sum type for the state of an I/O event. Specializations of the basic I/O event class type may need more states. The basic states are:
class type virtual ['a] event = object .. end
The type of objects representing an I/O events that produce results of type 'a.
exception Not_ready
The exception raised when the get method is applied to an I/O event object that has not been serviced by a polling mux.

Functions and Classes

To use a polling mux, follow these steps:


val create : unit -> t
Use create () to construct a new polling mux.
val cycle : t -> more
Use cycle p to wait until one or more of the I/O event objects loaded into the mux p is ready to be serviced, then service them (which includes invoking their obj#service method). Returns Last if there are no more events loaded into the polling mux. Otherwise, returns More.
type rwx = [ `R | `W | `X ] 
File events are associated with read, write or exception I/O events.
class virtual ['a] file : [< rwx ] -> Unix.file_descr -> ['a] event
Use inherit file rwx fd to derive an I/O event object that waits for the file descriptor fd to be ready for reading, writing, or exception (according to the value of rwx).
class virtual ['a] signal : int -> ['a] event
Use inherit signal n to derive an I/O event that is serviced when the system delivers the signal n.
class virtual ['a] time : ?t0:Cf_tai64n.t -> float -> object .. end
Use inherit time ?start interval to derive an I/O event that is serviced after the system clock reaches a specific time and at constrant intervals thereafter.
class virtual ['a] idle : object .. end
Use inherit idle to derive an I/O event that is serviced whenever a polling mux cycle would otherwise block for any non-zero length of time.