module Cf_poll:I/O event multiplexing.sig
..end
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.
type
t
type
more_t =
| |
More |
| |
Last |
type'a
state_t =[ `Exception of exn | `Final of 'a | `Loaded of t | `Unloaded ]
`Unloaded
, not loaded into a polling event queue.`Loaded q
, loaded into the polling event queue q
.`Final v
finished with a normal result v
.`Exception x
, finished with an exceptional result x
.class type virtual['a]
event =object
..end
'a
.
exception Not_ready
get
method is applied to an I/O event
object that has not been serviced by a polling mux.To use a polling mux, follow these steps:
create ()
;file
, signal
, time
and idle
I/O events;load
method on each one using the new mux;cycle
function to the mux;canget
and get
methods to the events to obtain the results.val create : unit -> t
create ()
to construct a new polling mux.val cycle : t -> more_t
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
.class virtual['a]
file :[< `R | `W | `X ] -> Unix.file_descr ->
object
..end
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
inherit signal n
to derive an I/O event that is serviced when the
system delivers the signal n
.
class virtual['a]
time :Cf_tai64n.t ->
object
..end
inherit time epoch
to derive an I/O event that is serviced when the
system clock reaches the time epoch
.
class virtual['a]
idle :object
..end
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.