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 set (OFF).
int numSet ()
 Determine how many bits are set (ON) in the set.
void dump ()
 Write to debug log all bits 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 50 of file FdSet.h.


Member Typedef Documentation

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

Definition at line 99 of file FdSet.h.


Constructor & Destructor Documentation

ASSA::FdSet::FdSet  )  [inline]
 

Constructor.

Definition at line 108 of file FdSet.h.

References reset().

00108 { reset (); }


Member Function Documentation

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 }

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

Write to debug log all bits set.

Definition at line 109 of file FdSet.h.

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

00109 { 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 101 of file FdSet.cpp.

References numSet().

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

00102 {
00103     std::ostringstream report;
00104 
00105     report << " enabled=" << numSet ();
00106 
00107 #if defined (WIN32)
00108     if (this->fd_count) {
00109         report << " : ";
00110     }
00111     for (int i=0; i < this->fd_count; i++) {
00112         report << " " << this->fd_array[i];
00113     }
00114 #else /* UNIX */
00115     ActiveFDs_Iter iter = m_actfds.begin ();
00116     if (m_actfds.size ()) {
00117         report << " : ";
00118     }
00119     while (iter != m_actfds.end ()) {
00120         report << " " << (u_int)*iter;
00121         iter++;
00122     }
00123 #endif
00124 
00125     report << std::ends;
00126     return (report.str ());
00127 }

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 111 of file FdSet.h.

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

00111 { return FD_ISSET (fd_, this); }

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

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

Returns:
Number of bits set

Definition at line 115 of file FdSet.h.

References m_actfds.

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

00116 { 
00117 #if defined (WIN32)
00118     return this->fd_count; 
00119 #else  /* UNIX */
00120     return m_actfds.size ();
00121 #endif
00122 }

void FdSet::reset  ) 
 

Reset every bit in 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 }

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 }

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 }


Member Data Documentation

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

Definition at line 101 of file FdSet.h.

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


The documentation for this class was generated from the following files:
Generated on Sun Aug 13 15:08:19 2006 for libassa by  doxygen 1.4.6