libassa 3.5.1
Loading...
Searching...
No Matches
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.
 
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

◆ 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.

119{ 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.

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)
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
A wrapper class to provide AutoPtr with reference semantics.
Definition AutoPtr.h:32
std::list< u_int >::iterator ActiveFDs_Iter
Definition FdSet.h:110
std::list< u_int > m_actfds
Definition FdSet.h:112
bool isSet(handler_t fd_)
Test whether fd's flag is on.
Definition FdSet.h:122
@ 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.

120{ DL ((REACT, "%s\n", dump_c_str ().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.

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

122{ 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.

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}

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.

127{
128#if defined (WIN32)
129 return this->fd_count;
130#else /* UNIX */
131 return m_actfds.size ();
132#endif
133}

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.

91{
92 ::memset(this, 0, sizeof (fd_set));
93
94#if !defined (WIN32)
95 m_actfds.clear ();
96#endif
97}

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.

21{
22 FD_SET (fd_, this);
23
24#if !defined (WIN32)
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}

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.

73{
74#if !defined (WIN32)
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}

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: