[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    Dispatcher(3X) manual page Table of Contents

Name

Dispatcher - wait on multiple file descriptors until a condition occurs

Synopsis

#include <ivplus/dispatcher.h>

Description

Conceptually, Dispatcher plays the role of detecting new data on multiple input file descriptors and dispatching the data to the appropriate IOHandler. The Dispatcher also notifies IOHandlers of expired timers. Notification of either an I/O condition or an expired timer occurs by calling one of the IOHandler’s virtual functions (see IOHandler(3X) ). Since a program needs only one instance of Dispatcher, a static member function is provided to create that instance if necessary, and return it.

Class Hierarchy

Dispatcher

Constructors

Dispatcher()

Creates a new dispatcher.

Public Data

enum DispatcherMask { ReadMask, WriteMask, ExceptMask }

The DispatcherMask is used to describe I/O conditions that an IOHandler is interested in. A ReadMask indicates interest in reading data from a file descriptor. A WriteMask indicates interest in writing data to a file descriptor. An ExceptMask indicates interest in handling an exception from the file descriptor.

Public Operations

virtual void dispatch()

Blocks indefinitely until an I/O condition occurs or a timer expires. Then notifies the attached IOHandler.

virtual boolean dispatch(long& sec, long& usec)

Blocks no longer than the given number of seconds and microseconds. If both numbers are zero, the function will return immediately after checking all file descriptors and timers. The return value will be true if an I/O condition caused the function to return and false if the function returned because a timer expired or it exceeded the given poll time. The function will decrease the given poll time by the amount of time it spent blocking.

virtual IOHandler* handler(int fd, DispatcherMask) const

Returns a file descriptor’s IOHandler. The DispatcherMask describes the I/O condition that the IOHandler is interested in, such as if the file descriptor has new data available for reading. If the I/O condition occurs, the IOHandler will be expected to read data from the file descriptor, write data to the file descriptor, or handle the exception depending on the I/O condition.

static Dispatcher& instance()

Creates an instance of Dispatcher if it doesn’t already exist and returns it.

static void instance(Dispatcher*)

Sets the instance of Dispatcher that will be used throughout the program.

virtual void link(int fd, DispatcherMask, IOHandler*)

Links a file descriptor to an IOHandler. The given DispatcherMask describes the I/O condition that the IOHandler should handle.

virtual void startTimer(long sec, long usec, IOHandler*)

Attaches an IOHandler to a timer. A timer expires after sec seconds and usec microseconds have elapsed. If a timer expires, the dispatcher will notify the attached IOHandler. Timers will not expire until the program calls either variant of Dispatcher::dispatch().

virtual void stopTimer(IOHandler*)

Removes a timer before it expires. A timer expires after the given number of seconds and microseconds have elapsed. If a timer expires, the dispatcher will notify the attached IOHandler. Timers will not expire until the program calls either variant of Dispatcher::dispatch().

virtual void unlink(int fd)

Unlinks a file descriptor from an IOHandler.

X Resources

None.

Examples

No example for this man page. See IOHandler(3X) for examples.

Files


dispatcher.h

See Also

select(2) , IOHandler(3X) .


Table of Contents