ASSA::FdSet Class Reference

Class FdSet. More...

#include <FdSet.h>

List of all members.

Public Member Functions

 FdSet ()
 Constructor.
bool setFd (handler_t fd_)
 Set flag (ON) for the argument fd.
bool clear (handler_t fd_)
 Clear flag (OFF) for the argument fd.
bool isSet (handler_t fd_)
 Test whether fd's flag is on.
void sync ()
 Sync internals after used by select(3C).
void reset ()
 Reset every bit in the set (OFF).
int maxInSet ()
 Find out the highest file descriptor in the set.
int numSet ()
 Determine how many bits are set (ON) in the set.
void dump ()
 Determine highest handler in the set.
std::string dump_c_str ()
 Return object state dump as an ASCII string.

Private Types

typedef std::list< u_int >
::iterator 
ActiveFDs_Iter

Private Attributes

std::list< u_intm_actfds


Detailed Description

Class FdSet.

Wrapper around struct fd_set. This class hides the differences between UNIX/POSIX and WIN32 implementations of fd_set data structure.

The main difference is that while fd_set on POSIX system is represented as bit flags, the same structure on WIN32 system is opaque and not limited by FD_SETSIZE.

In fact, it is represented as an array of SOCKETs (read u_int[FD_SETSIZE]) along with the number of FDs in the set. This allows a WIN32 socket descriptor value to fall anywhere in the range from 0 to max(u_int -1).

handler_t type hides the type difference.

Definition at line 51 of file FdSet.h.


Member Typedef Documentation

typedef std::list<u_int>::iterator ASSA::FdSet::ActiveFDs_Iter [private]

Definition at line 110 of file FdSet.h.


Constructor & Destructor Documentation

ASSA::FdSet::FdSet (  )  [inline]

Constructor.

Definition at line 119 of file FdSet.h.

References reset().

00119 { reset (); }


Member Function Documentation

bool FdSet::setFd ( handler_t  fd_  ) 

Set flag (ON) for the argument fd.

Parameters:
fd_ Bit to set.
Returns:
false if argument is out of bounds, true otherwise.

Definition at line 20 of file FdSet.cpp.

References m_actfds.

Referenced by ASSA::Reactor::checkFDs(), ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >::handle_read(), and ASSA::Reactor::registerIOHandler().

00021 { 
00022     FD_SET (fd_, this); 
00023 
00024 #if !defined (WIN32)
00025     ActiveFDs_Iter iter;
00026     iter = std::find (m_actfds.begin (), 
00027                       m_actfds.end (), 
00028                       fd_);
00029     if (iter == m_actfds.end ()) { // not found
00030         m_actfds.push_back (fd_);
00031     }
00032 #endif
00033 
00034     return true;
00035 }

bool FdSet::clear ( handler_t  fd_  ) 

Clear flag (OFF) for the argument fd.

Parameters:
fd_ Bit to clear
Returns:
false if argument is out of bounds; true otherwise.

Definition at line 39 of file FdSet.cpp.

References DL, isSet(), m_actfds, and ASSA::REACT.

Referenced by ASSA::Reactor::checkFDs(), ASSA::Reactor::dispatchHandler(), ASSA::Reactor::removeHandler(), and ASSA::Reactor::removeIOHandler().

00040 {
00041     DL ((REACT,"Clearing fd=%d\n", fd_));
00042 
00043     if (!isSet (fd_)) {
00044         DL ((REACT,"Not set! - ignoring.\n"));
00045         return false;
00046     }
00047 
00048     FD_CLR (fd_, this); 
00049     if (FD_ISSET (fd_, this)) {
00050         DL ((REACT,"Woop - an error! FD_CLR failed!\n"));
00051     }
00052 
00053 #if !defined (WIN32)
00054     ActiveFDs_Iter iter;
00055     iter = std::find (m_actfds.begin (), 
00056                       m_actfds.end (), 
00057                       fd_);
00058     if (iter != m_actfds.end ()) { 
00059         DL ((REACT,"fd=%d found and erased\n", fd_));
00060         m_actfds.erase (iter);
00061     }
00062     else {
00063         DL ((REACT,"fd=%d not found in m_actfds list!\n", fd_));
00064     }
00065 #endif
00066 
00067     return true;
00068 }

bool ASSA::FdSet::isSet ( handler_t  fd_  )  [inline]

Test whether fd's flag is on.

Parameters:
fd_ Bit to test
Returns:
true if fd_ bit is set; false otherwise

Definition at line 122 of file FdSet.h.

Referenced by clear(), ASSA::Reactor::dispatchHandler(), and sync().

00122 { return FD_ISSET (fd_, this); }

void FdSet::sync (  ) 

Sync internals after used by select(3C).

Definition at line 72 of file FdSet.cpp.

References isSet(), and m_actfds.

Referenced by ASSA::MaskSet::sync().

00073 { 
00074 #if !defined (WIN32)
00075     ActiveFDs_Iter iter;
00076   restart:
00077     iter = m_actfds.begin ();
00078     while (iter != m_actfds.end ()) {
00079         if (!isSet (*iter)) {
00080             m_actfds.erase (iter);
00081             goto restart;
00082         }
00083         iter++;
00084     }
00085 #endif
00086 }

void FdSet::reset (  ) 

Reset every bit in the set (OFF).

Definition at line 90 of file FdSet.cpp.

References m_actfds.

Referenced by FdSet(), ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >::handle_read(), and ASSA::MaskSet::reset().

00091 { 
00092     ::memset(this, 0, sizeof (fd_set)); 
00093 
00094 #if !defined (WIN32)
00095     m_actfds.clear ();
00096 #endif
00097 }

int FdSet::maxInSet (  ) 

Find out the highest file descriptor in the set.

Returns:
highest value of file descriptor.

Definition at line 101 of file FdSet.cpp.

References m_actfds.

Referenced by ASSA::MaskSet::max_fd().

00102 {
00103 #if defined (WIN32)
00104     return 0;                   // win32 select doesn't need this value
00105 #else
00106     if (m_actfds.size () == 0) {
00107         return 0;
00108     }
00109     ActiveFDs_Iter iter = std::max_element (m_actfds.begin (), m_actfds.end ());
00110     return (*iter);
00111 #endif
00112 }

int ASSA::FdSet::numSet (  )  [inline]

Determine how many bits are set (ON) in the set.

Returns:
Number of bits set

Definition at line 126 of file FdSet.h.

References m_actfds.

Referenced by dump_c_str(), and ASSA::Reactor::isAnyReady().

00127 { 
00128 #if defined (WIN32)
00129     return this->fd_count; 
00130 #else  /* UNIX */
00131     return m_actfds.size ();
00132 #endif
00133 }

void ASSA::FdSet::dump (  )  [inline]

Determine highest handler in the set.

Returns:
highest value in the set Write to debug log all bits set.

Definition at line 120 of file FdSet.h.

References DL, dump_c_str(), and ASSA::REACT.

00120 { DL ((REACT, "%s\n", dump_c_str ().c_str ())); }

std::string FdSet::dump_c_str (  ) 

Return object state dump as an ASCII string.

Definition at line 116 of file FdSet.cpp.

References ASSA::ends(), m_actfds, and numSet().

Referenced by ASSA::MaskSet::dump(), and dump().

00117 {
00118     std::ostringstream report;
00119 
00120     report << " enabled=" << numSet ();
00121 
00122 #if defined (WIN32)
00123     if (this->fd_count) {
00124         report << " : ";
00125     }
00126     for (int i=0; i < this->fd_count; i++) {
00127         report << " " << this->fd_array[i];
00128     }
00129 #else /* UNIX */
00130     ActiveFDs_Iter iter = m_actfds.begin ();
00131     if (m_actfds.size ()) {
00132         report << " : ";
00133     }
00134     while (iter != m_actfds.end ()) {
00135         report << " " << (u_int)*iter;
00136         iter++;
00137     }
00138 #endif
00139 
00140     report << std::ends;
00141     return (report.str ());
00142 }


Member Data Documentation

std::list<u_int> ASSA::FdSet::m_actfds [private]

Definition at line 112 of file FdSet.h.

Referenced by clear(), dump_c_str(), maxInSet(), numSet(), reset(), setFd(), and sync().


The documentation for this class was generated from the following files:

Generated on Tue Aug 5 17:17:03 2008 for libassa by  doxygen 1.5.6