libassa
3.5.0
|
#include <FdSet.h>
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 |
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.
typedef std::list<u_int>::iterator ASSA::FdSet::ActiveFDs_Iter [private] |
ASSA::FdSet::FdSet | ( | ) | [inline] |
bool FdSet::clear | ( | handler_t | fd_ | ) |
Clear flag (OFF) for the argument fd.
fd_ | Bit to clear |
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().
{ 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; }
void ASSA::FdSet::dump | ( | ) | [inline] |
Determine highest handler in the set.
Definition at line 120 of file FdSet.h.
References DL, dump_c_str(), and ASSA::REACT.
{ 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().
{ 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 ()); }
bool ASSA::FdSet::isSet | ( | handler_t | fd_ | ) | [inline] |
Test whether fd's flag is on.
fd_ | Bit to test |
Definition at line 122 of file FdSet.h.
Referenced by clear(), ASSA::Reactor::dispatchHandler(), and sync().
{ return FD_ISSET (fd_, this); }
int FdSet::maxInSet | ( | ) |
Find out the highest file descriptor in the set.
Definition at line 101 of file FdSet.cpp.
References m_actfds.
Referenced by ASSA::MaskSet::max_fd().
{ #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 }
int ASSA::FdSet::numSet | ( | ) | [inline] |
Determine how many bits are set (ON) in the set.
Definition at line 126 of file FdSet.h.
References m_actfds.
Referenced by dump_c_str(), and ASSA::Reactor::isAnyReady().
{ #if defined (WIN32) return this->fd_count; #else /* UNIX */ return m_actfds.size (); #endif }
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().
{ ::memset(this, 0, sizeof (fd_set)); #if !defined (WIN32) m_actfds.clear (); #endif }
bool FdSet::setFd | ( | handler_t | fd_ | ) |
Set flag (ON) for the argument fd.
fd_ | Bit to set. |
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().
{ 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; }
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().
{ #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 }
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().