libassa  3.5.1
FdSet.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //------------------------------------------------------------------------------
3 // FdSet.h
4 //------------------------------------------------------------------------------
5 // Copyright (C) 1997-2002 Vladislav Grinchenko
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //------------------------------------------------------------------------------
12 #ifndef FDSET_H
13 #define FDSET_H
14 
17 #include <string.h>
18 #include <sys/time.h> /* select(3) */
19 
20 #if defined(Linux) /* select(3) */
21 # include <sys/types.h>
22 # include <unistd.h>
23 #endif
24 
25 #include <algorithm>
26 #include <string>
27 #include <sstream>
28 #include <iostream>
29 #include <list>
30 
31 #include "assa/Logger.h"
32 
33 namespace ASSA {
34 
51 class FdSet : public fd_set
52 {
53 public:
56  FdSet ();
57 
62  bool setFd (handler_t fd_);
63 
68  bool clear (handler_t fd_);
69 
74  bool isSet (handler_t fd_);
75 
78  void sync ();
79 
82  void reset ();
83 
84 
88  int maxInSet ();
89 
93  int numSet ();
94 
101  void dump ();
102 
105  std::string dump_c_str ();
106 
107 private:
108 
109 #if !defined (WIN32)
110  typedef std::list<u_int>::iterator ActiveFDs_Iter;
111 
112  std::list<u_int> m_actfds;
113 #endif
114 };
115 
116 //------------------------------------------------------------------------------
117 // Member Functions
118 //------------------------------------------------------------------------------
119 inline FdSet::FdSet () { reset (); }
120 inline void FdSet::dump () { DL ((REACT, "%s\n", dump_c_str ().c_str ())); }
121 
122 inline bool FdSet::isSet (handler_t fd_) { return FD_ISSET (fd_, this); }
123 
124 inline int
126 numSet ()
127 {
128 #if defined (WIN32)
129  return this->fd_count;
130 #else /* UNIX */
131  return m_actfds.size ();
132 #endif
133 }
134 
135 
136 } // end namespace ASSA
137 
138 #endif /* FDSET_H */
An abstraction to message logging facility.
#define DL(X)
A macro for writing debug message to the Logger.
Definition: Logger.h:273
int handler_t
Definition: Logger_Impl.h:82
Class FdSet.
Definition: FdSet.h:52
std::list< u_int >::iterator ActiveFDs_Iter
Definition: FdSet.h:110
std::list< u_int > m_actfds
Definition: FdSet.h:112
void reset()
Reset every bit in the set (OFF).
Definition: FdSet.cpp:90
bool setFd(handler_t fd_)
Set flag (ON) for the argument fd.
Definition: FdSet.cpp:20
void sync()
Sync internals after used by select(3C)
Definition: FdSet.cpp:72
std::string dump_c_str()
Return object state dump as an ASCII string.
Definition: FdSet.cpp:116
int maxInSet()
Find out the highest file descriptor in the set.
Definition: FdSet.cpp:101
FdSet()
Constructor.
Definition: FdSet.h:119
void dump()
Determine highest handler in the set.
Definition: FdSet.h:120
bool isSet(handler_t fd_)
Test whether fd's flag is on.
Definition: FdSet.h:122
bool clear(handler_t fd_)
Clear flag (OFF) for the argument fd.
Definition: FdSet.cpp:39
int numSet()
Determine how many bits are set (ON) in the set.
Definition: FdSet.h:126
Definition: Acceptor.h:40
@ REACT
Class Reactor/PrioriyQueue messages
Definition: LogMask.h:39