libassa  3.5.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Private Types | Private Attributes | List of all members
ASSA::FdSet Class Reference

Class FdSet. More...

#include <FdSet.h>

Inheritance diagram for ASSA::FdSet:

Public Member Functions

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

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().

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

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().

40 {
41  DL ((REACT,"Clearing fd=%d\n", fd_));
42 
43  if (!isSet (fd_)) {
44  DL ((REACT,"Not set! - ignoring.\n"));
45  return false;
46  }
47 
48  FD_CLR (fd_, this);
49  if (FD_ISSET (fd_, this)) {
50  DL ((REACT,"Woop - an error! FD_CLR failed!\n"));
51  }
52 
53 #if !defined (WIN32)
54  ActiveFDs_Iter iter;
55  iter = std::find (m_actfds.begin (),
56  m_actfds.end (),
57  fd_);
58  if (iter != m_actfds.end ()) {
59  DL ((REACT,"fd=%d found and erased\n", fd_));
60  m_actfds.erase (iter);
61  }
62  else {
63  DL ((REACT,"fd=%d not found in m_actfds list!\n", fd_));
64  }
65 #endif
66 
67  return true;
68 }
#define DL(X)
A macro for writing debug message to the Logger.
Definition: Logger.h:273
bool isSet(handler_t fd_)
Test whether fd's flag is on.
Definition: FdSet.h:122
Class Reactor/PrioriyQueue messages.
Definition: LogMask.h:39
std::list< u_int >::iterator ActiveFDs_Iter
Definition: FdSet.h:110
std::list< u_int > m_actfds
Definition: FdSet.h:112
void ASSA::FdSet::dump ( )
inline

Determine highest handler in the set.

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

Definition at line 120 of file FdSet.h.

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

120 { DL ((REACT, "%s\n", dump_c_str ().c_str ())); }
#define DL(X)
A macro for writing debug message to the Logger.
Definition: Logger.h:273
Class Reactor/PrioriyQueue messages.
Definition: LogMask.h:39
std::string dump_c_str()
Return object state dump as an ASCII string.
Definition: FdSet.cpp:116
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().

117 {
118  std::ostringstream report;
119 
120  report << " enabled=" << numSet ();
121 
122 #if defined (WIN32)
123  if (this->fd_count) {
124  report << " : ";
125  }
126  for (int i=0; i < this->fd_count; i++) {
127  report << " " << this->fd_array[i];
128  }
129 #else /* UNIX */
130  ActiveFDs_Iter iter = m_actfds.begin ();
131  if (m_actfds.size ()) {
132  report << " : ";
133  }
134  while (iter != m_actfds.end ()) {
135  report << " " << (u_int)*iter;
136  iter++;
137  }
138 #endif
139 
140  report << std::ends;
141  return (report.str ());
142 }
unsigned int u_int
Definition: Logger_Impl.h:40
Socket & ends(Socket &os_)
ends manipulator.
Definition: Socket.h:622
std::list< u_int >::iterator ActiveFDs_Iter
Definition: FdSet.h:110
std::list< u_int > m_actfds
Definition: FdSet.h:112
int numSet()
Determine how many bits are set (ON) in the set.
Definition: FdSet.h:126
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().

122 { return FD_ISSET (fd_, this); }
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().

102 {
103 #if defined (WIN32)
104  return 0; // win32 select doesn't need this value
105 #else
106  if (m_actfds.size () == 0) {
107  return 0;
108  }
109  ActiveFDs_Iter iter = std::max_element (m_actfds.begin (), m_actfds.end ());
110  return (*iter);
111 #endif
112 }
std::list< u_int >::iterator ActiveFDs_Iter
Definition: FdSet.h:110
std::list< u_int > m_actfds
Definition: FdSet.h:112
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().

127 {
128 #if defined (WIN32)
129  return this->fd_count;
130 #else /* UNIX */
131  return m_actfds.size ();
132 #endif
133 }
std::list< u_int > m_actfds
Definition: FdSet.h:112
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().

91 {
92  ::memset(this, 0, sizeof (fd_set));
93 
94 #if !defined (WIN32)
95  m_actfds.clear ();
96 #endif
97 }
std::list< u_int > m_actfds
Definition: FdSet.h:112
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().

21 {
22  FD_SET (fd_, this);
23 
24 #if !defined (WIN32)
25  ActiveFDs_Iter iter;
26  iter = std::find (m_actfds.begin (),
27  m_actfds.end (),
28  fd_);
29  if (iter == m_actfds.end ()) { // not found
30  m_actfds.push_back (fd_);
31  }
32 #endif
33 
34  return true;
35 }
std::list< u_int >::iterator ActiveFDs_Iter
Definition: FdSet.h:110
std::list< u_int > m_actfds
Definition: FdSet.h:112
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().

73 {
74 #if !defined (WIN32)
75  ActiveFDs_Iter iter;
76  restart:
77  iter = m_actfds.begin ();
78  while (iter != m_actfds.end ()) {
79  if (!isSet (*iter)) {
80  m_actfds.erase (iter);
81  goto restart;
82  }
83  iter++;
84  }
85 #endif
86 }
bool isSet(handler_t fd_)
Test whether fd's flag is on.
Definition: FdSet.h:122
std::list< u_int >::iterator ActiveFDs_Iter
Definition: FdSet.h:110
std::list< u_int > m_actfds
Definition: FdSet.h:112

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: