xorp

SelectorList Class Reference

A class to provide an interface to I/O multiplexing. More...

#include <selector.hh>

Inheritance diagram for SelectorList:
NONCOPYABLE

List of all members.

Classes

struct  Node

Public Member Functions

 SelectorList (ClockBase *clock)
 Default constructor.
virtual ~SelectorList ()
 Destructor.
void set_debug (bool v)
bool is_debug () const
bool add_ioevent_cb (XorpFd fd, IoEventType type, const IoEventCb &cb, int priority=XorpTask::PRIORITY_DEFAULT)
 Add a hook for pending I/O operations on a callback.
void remove_ioevent_cb (XorpFd fd, IoEventType type=IOT_ANY)
 Remove hooks for pending I/O operations.
bool ready ()
 Find out if any of the selectors are ready.
int get_ready_priority (bool force)
 Find out the highest priority from the ready file descriptors.
int wait_and_dispatch (TimeVal &timeout)
 Wait for a pending I/O events and invoke callbacks when they become ready.
int wait_and_dispatch (int millisecs)
 Wait for a pending I/O events and invoke callbacks when they become ready.
size_t descriptor_count () const
 Get the count of the descriptors that have been added.
void get_fd_set (SelectorMask selected_mask, fd_set &fds) const
 Get a copy of the current list of monitored file descriptors in Unix fd_set format.
int get_max_fd () const
 Get a the value of the largest monitored file descriptor.
void set_observer (SelectorListObserverBase &obs)
 Set the SelectorObserver object that will receive notifications.
void remove_observer ()
 Remove the SelectorObserver object that receives notifications.

Protected Member Functions

void callback_bad_descriptors ()

Private Types

enum  { SEL_RD_IDX = 0, SEL_WR_IDX = 1, SEL_EX_IDX = 2, SEL_MAX_IDX = 3 }

Private Member Functions

int do_select (struct timeval *to, bool force)

Private Attributes

ClockBase_clock
SelectorListObserverBase_observer
fd_set _fds [SEL_MAX_IDX]
fd_set _testfds [SEL_MAX_IDX]
int _testfds_n
int _maxpri_fd
int _maxpri_sel
int _last_served_fd
int _last_served_sel
vector< Node_selector_entries
int _maxfd
size_t _descriptor_count
bool _is_debug

Detailed Description

A class to provide an interface to I/O multiplexing.

A SelectorList provides an entity where callbacks for pending I/O operations on file descriptors may be registered. The callbacks are invoked when one of the wait_and_dispatch methods is called and I/O is pending on the particular descriptors.


Member Function Documentation

bool SelectorList::add_ioevent_cb ( XorpFd  fd,
IoEventType  type,
const IoEventCb &  cb,
int  priority = XorpTask::PRIORITY_DEFAULT 
)

Add a hook for pending I/O operations on a callback.

Only one callback may be registered for each possible I/O event type (read, write, exception).

Multiple event types may share the same callback. If multiple event types share the same callback and multiple types of event are pending, the callback is invoked just once and the mask argument to the callback shows which events are pending.

Parameters:
filedescriptor.
maskmask of I/O event types that should invoke callback. An OR'ed combination of the available SelectorMask values.
scbcallback object that will be invoked when the descriptor.
Returns:
true if function succeeds, false otherwise.
size_t SelectorList::descriptor_count ( ) const [inline]

Get the count of the descriptors that have been added.

Returns:
the count of the descriptors that have been added.
void SelectorList::get_fd_set ( SelectorMask  selected_mask,
fd_set &  fds 
) const

Get a copy of the current list of monitored file descriptors in Unix fd_set format.

Parameters:
theselected mask as SelectorMask (SEL_RD, SEL_WR, or SEL_EX)
Returns:
the selected fd_set.
int SelectorList::get_max_fd ( ) const

Get a the value of the largest monitored file descriptor.

Returns:
the maximum fd.
int SelectorList::get_ready_priority ( bool  force)

Find out the highest priority from the ready file descriptors.

Returns:
the priority of the highest priority ready file descriptor.
bool SelectorList::ready ( )

Find out if any of the selectors are ready.

Returns:
true if any selector is ready.
void SelectorList::remove_ioevent_cb ( XorpFd  fd,
IoEventType  type = IOT_ANY 
)

Remove hooks for pending I/O operations.

Parameters:
fdthe file descriptor.
maskof event types to be removed, e.g. an OR'ed combination of the available SelectorMask values.
void SelectorList::remove_observer ( )

Remove the SelectorObserver object that receives notifications.

Returns:
void
void SelectorList::set_observer ( SelectorListObserverBase obs)

Set the SelectorObserver object that will receive notifications.

Returns:
void
int SelectorList::wait_and_dispatch ( TimeVal timeout)

Wait for a pending I/O events and invoke callbacks when they become ready.

Parameters:
timeoutthe maximum period to wait for.
Returns:
the number of callbacks that were made.
int SelectorList::wait_and_dispatch ( int  millisecs)

Wait for a pending I/O events and invoke callbacks when they become ready.

Parameters:
millisecsthe maximum period in milliseconds to wait for.
Returns:
the number of callbacks that were made.

The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations