Loading...
Searching...
No Matches
ASSA::FdSet Class Reference

Class FdSet. More...

`#include <FdSet.h>`

Inheritance diagram for ASSA::FdSet:

## 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_int > | m_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

## ActiveFDs_Iter

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

private

Definition at line 110 of file FdSet.h.

## Constructor & Destructor Documentation

## FdSet()

ASSA::FdSet::FdSet | ( |  | ) |

inline

Constructor.

Definition at line 119 of file FdSet.h.

{ reset (); }
ASSA::FdSet::reset
void reset()
Reset every bit in the set (OFF).
Definition FdSet.cpp:90

References reset().

## Member Function Documentation

## clear()

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 38 of file FdSet.cpp.

{
DL ((REACT,"Clearing fd=%d\n", fd_));
if (!isSet (fd_)) {
DL ((REACT,"Not set! - ignoring.\n"));
return false;
}
FD_CLR (fd_, this);
if (FD_ISSET (fd_, this)) {
DL ((REACT,"Woop - an error! FD_CLR failed!\n"));
}
#if !defined (WIN32)
ActiveFDs_Iter iter;
iter = std::find (m_actfds.begin (),
m_actfds.end (),
fd_);
if (iter != m_actfds.end ()) {
DL ((REACT,"fd=%d found and erased\n", fd_));
m_actfds.erase (iter);
}
else {
DL ((REACT,"fd=%d not found in m_actfds list!\n", fd_));
}
#endif
return true;
}
DL
#define DL(X)
A macro for writing debug message to the Logger.
Definition Logger.h:273
ASSA::AutoPtrRef
A wrapper class to provide AutoPtr with reference semantics.
Definition AutoPtr.h:32
ASSA::FdSet::ActiveFDs_Iter
std::list< u_int >::iterator ActiveFDs_Iter
Definition FdSet.h:110
ASSA::FdSet::m_actfds
std::list< u_int > m_actfds
Definition FdSet.h:112
ASSA::FdSet::isSet
bool isSet(handler_t fd_)
Test whether fd's flag is on.
Definition FdSet.h:122
ASSA::REACT
@ REACT
Class Reactor/PrioriyQueue messages
Definition LogMask.h:39

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

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

## dump()

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.

{ DL ((REACT, "%s\n", dump_c_str ().c_str ())); }
ASSA::FdSet::dump_c_str
std::string dump_c_str()
Return object state dump as an ASCII string.
Definition FdSet.cpp:116

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

## dump_c_str()

std::string FdSet::dump_c_str | ( |  | ) |

Return object state dump as an ASCII string.

Definition at line 115 of file FdSet.cpp.

{
std::ostringstream report;
report << " enabled=" << numSet ();
#if defined (WIN32)
if (this->fd_count) {
report << " : ";
}
for (int i=0; i < this->fd_count; i++) {
report << " " << this->fd_array[i];
}
#else /* UNIX */
ActiveFDs_Iter iter = m_actfds.begin ();
if (m_actfds.size ()) {
report << " : ";
}
while (iter != m_actfds.end ()) {
report << " " << (u_int)*iter;
iter++;
}
#endif
report << std::ends;
return (report.str ());
}
u_int
unsigned int u_int
Definition Logger_Impl.h:40
ASSA::FdSet::numSet
int numSet()
Determine how many bits are set (ON) in the set.
Definition FdSet.h:126

References m_actfds, and numSet().

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

## isSet()

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.

{ return FD_ISSET (fd_, this); }

Referenced by clear(), and sync().

## maxInSet()

int FdSet::maxInSet | ( |  | ) |

Find out the highest file descriptor in the set.

Returns
  highest value of file descriptor.

Definition at line 100 of file FdSet.cpp.

{
#if defined (WIN32)
return 0; // win32 select doesn't need this value
#else
if (m_actfds.size () == 0) {
return 0;
}
ActiveFDs_Iter iter = std::max_element (m_actfds.begin (), m_actfds.end ());
return (*iter);
#endif
}

References m_actfds.

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

## numSet()

int ASSA::FdSet::numSet | ( |  | ) |

inline

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

Returns
  Number of bits set

Definition at line 125 of file FdSet.h.

{
#if defined (WIN32)
return this->fd_count;
#else /* UNIX */
return m_actfds.size ();
#endif
}

References m_actfds.

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

## reset()

void FdSet::reset | ( |  | ) |

Reset every bit in the set (OFF).

Definition at line 89 of file FdSet.cpp.

{
::memset(this, 0, sizeof (fd_set));
#if !defined (WIN32)
m_actfds.clear ();
#endif
}

References m_actfds.

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

## setFd()

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 19 of file FdSet.cpp.

{
FD_SET (fd_, this);
#if !defined (WIN32)
ActiveFDs_Iter iter;
iter = std::find (m_actfds.begin (),
m_actfds.end (),
fd_);
if (iter == m_actfds.end ()) { // not found
m_actfds.push_back (fd_);
}
#endif
return true;
}

References m_actfds.

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

## sync()

void FdSet::sync | ( |  | ) |

Sync internals after used by select(3C)

Definition at line 71 of file FdSet.cpp.

{
#if !defined (WIN32)
ActiveFDs_Iter iter;
restart:
iter = m_actfds.begin ();
while (iter != m_actfds.end ()) {
if (!isSet (*iter)) {
m_actfds.erase (iter);
goto restart;
}
iter++;
}
#endif
}

References isSet(), and m_actfds.

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

## Member Data Documentation

## m_actfds

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:

- FdSet.h
- FdSet.cpp