00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef FDSET_H
00013 #define FDSET_H
00014
00017 #include <string.h>
00018
00019 #include <sys/time.h>
00020
00021 #if defined(Linux)
00022 # include <sys/types.h>
00023 # include <unistd.h>
00024 #endif
00025
00026 #include "assa/Logger.h"
00027
00028 namespace ASSA {
00029
00035 class FdSet : public fd_set
00036 {
00037 public:
00040 FdSet ();
00041
00044 ~FdSet () {}
00045
00050 bool setFd (const unsigned int fd_);
00051
00056 bool clear (const unsigned int fd_);
00057
00062 bool isSet (const unsigned int fd_);
00063
00066 void reset (void);
00067
00071 int numSet ();
00072
00075 void dump (void);
00076 };
00077
00078 inline
00079 FdSet::
00080 FdSet ()
00081 {
00082 reset ();
00083 }
00084
00085 inline bool
00086 FdSet::
00087 setFd (const unsigned int fd_)
00088 {
00089 if ( fd_ <= FD_SETSIZE ) {
00090 FD_SET (fd_, this);
00091 return true;
00092 }
00093 return false;
00094 }
00095
00096 inline bool
00097 FdSet::
00098 clear (const unsigned int fd_)
00099 {
00100 if ( fd_ <= FD_SETSIZE ) {
00101 FD_CLR (fd_, this);
00102 return true;
00103 }
00104 return false;
00105 }
00106
00107 inline bool
00108 FdSet::
00109 isSet (const unsigned int fd_)
00110 {
00111 return FD_ISSET (fd_, this);
00112 }
00113
00114 inline void
00115 FdSet::
00116 reset (void)
00117 {
00118 ::memset(this, 0, sizeof (*this));
00119 }
00120
00121 inline int
00122 FdSet::
00123 numSet ()
00124 {
00125 register int i, n;
00126
00127 for (i=0, n=0; i < FD_SETSIZE; i++) {
00128 if ( isSet (i) ) {
00129 n++;
00130 }
00131 }
00132 return n;
00133 }
00134
00135 inline void
00136 FdSet::
00137 dump (void)
00138 {
00139 for (int i=0; i< FD_SETSIZE; i++) {
00140 if ( isSet (i) ) {
00141 DL((REACT,"fd # %d\n",i));
00142 }
00143 }
00144 }
00145
00146 }
00147
00148 #endif