class Poller

A class to monitor a set of file descriptors for readiness events.

Inheritance:


Public Methods

[more]virtual int init()
Initialize the Poller
[more]virtual int setSignum(int signum)
Tell the Poller which signal number to use.
[more]virtual void shutdown()
Release any resouces allocated internally by this Poller
[more]virtual int add(int fd, Client* client, short eventmask) = 0
Add a file descriptor to the set we monitor.
[more]virtual int del(int fd) = 0
Remove a file descriptor
[more]virtual int setMask(int fd, short eventmask) = 0
Give a new value for the given file descriptor's eventmask
[more]virtual int orMask(int fd, short eventmask) = 0
Set fd's eventmask to its present value OR'd with the given one
[more]virtual int andMask(int fd, short eventmask) = 0
Set fd's eventmask to its present value AND'd with the given one
[more]virtual void clearReadiness(int fd, short eventmask)
Reset the given readiness bits.
[more]virtual int waitForEvents(int timeout_millisec) = 0
Sleep at most timeout_millisec waiting for an I/O readiness event on the file descriptors we're watching.
[more]virtual int getNextEvent(PollEvent* e) = 0
Get the next event that was found by waitForEvents.
[more]virtual int waitAndDispatchEvents(int timeout_millisec) = 0
Sleep at most timeout_millisec waiting for an I/O readiness event on the file descriptors we're watching, and dispatch events to the handler for each file descriptor that is ready for I/O.
[more]int initWakeUpPipe()
Get ready for future calls to wakeUp().
[more]int wakeUp()
Wake up a thread which is currently sleeping in a call to waitForEvents().

Public Members

[more]struct PollEvent
A class to represent a readiness event
class Client
A class to handle a particular file descriptor's readiness events


Documentation

A class to monitor a set of file descriptors for readiness events. Current an efficient wrapper around the poll() system call. This is the code you would have written yourself if you had had the time...
ostruct PollEvent
A class to represent a readiness event

oint fd
the file descriptor that is ready for I/O (same as in struct pollfd)

oshort revents
the kind of I/O this fd is currently ready for (same as in struct pollfd)

oClient* client
the object to call to handle I/O on this fd

ovirtual int init()
Initialize the Poller

ovirtual int setSignum(int signum)
Tell the Poller which signal number to use. Call once after init(), before add(). Only used by Poller_sigio.

ovirtual void shutdown()
Release any resouces allocated internally by this Poller

ovirtual int add(int fd, Client* client, short eventmask) = 0
Add a file descriptor to the set we monitor.
Parameters:
- fd file descriptor to add
- client object to handle events for this fd. May use same client with more than one fd.
eventmask - initial event mask for this fd

ovirtual int del(int fd) = 0
Remove a file descriptor

ovirtual int setMask(int fd, short eventmask) = 0
Give a new value for the given file descriptor's eventmask

ovirtual int orMask(int fd, short eventmask) = 0
Set fd's eventmask to its present value OR'd with the given one

ovirtual int andMask(int fd, short eventmask) = 0
Set fd's eventmask to its present value AND'd with the given one

ovirtual void clearReadiness(int fd, short eventmask)
Reset the given readiness bits. Do this after you finish handling an event and don't want to be notified about it again until the OS says it's newly ready. This does nothing except in one-shot notification schemes like Poller_sigio.

ovirtual int waitForEvents(int timeout_millisec) = 0
Sleep at most timeout_millisec waiting for an I/O readiness event on the file descriptors we're watching. Fills internal array of readiness events. Call getNextEvent() repeatedly to read its contents.
Returns:
0 on success, EWOULDBLOCK if no events ready

ovirtual int getNextEvent(PollEvent* e) = 0
Get the next event that was found by waitForEvents.
Returns:
0 on success, EWOULDBLOCK if no more events

ovirtual int waitAndDispatchEvents(int timeout_millisec) = 0
Sleep at most timeout_millisec waiting for an I/O readiness event on the file descriptors we're watching, and dispatch events to the handler for each file descriptor that is ready for I/O. This is included as an example of how to use waitForEvents and getNextEvent. Real programs should probably avoid waitAndDispatchEvents and call waitForEvents and getNextEvent instead for maximum control over client deletion.

oint initWakeUpPipe()
Get ready for future calls to wakeUp(). Allocates a pipe internally.
Returns:
0 on success; Unix error code on failure.

oint wakeUp()
Wake up a thread which is currently sleeping in a call to waitForEvents(). May be called from any thread, but you must have called initWakeUpPipe() once before the first call to waitForEvents().
Returns:
0 on success; Unix error code on failure. @note Threadsafe.


Direct child classes:
Poller_sigio
Poller_select
Poller_poll
Poller_kqueue
Poller_devpoll

Alphabetic index HTML hierarchy of classes or Java



This page was generated with the help of DOC++.