Mixe for Privacy and Anonymity in the Internet
Public Member Functions | Private Attributes | List of all members
CASocketGroup Class Reference

#include <CASocketGroup.hpp>

Inheritance diagram for CASocketGroup:
Collaboration diagram for CASocketGroup:

Public Member Functions

 CASocketGroup (bool bWrite)
 
 ~CASocketGroup ()
 
SINT32 setPoolForWrite (bool bWrite)
 
SINT32 add (SOCKET &s)
 
SINT32 add (CASocket &s)
 
SINT32 add (CAMuxSocket &s)
 
SINT32 remove (CASocket &s)
 
SINT32 remove (CAMuxSocket &s)
 
SINT32 select ()
 
SINT32 select (UINT32 time_ms)
 Waits for events on the sockets. More...
 
bool isSignaled (CASocket &s)
 
bool isSignaled (CASocket *ps)
 
bool isSignaled (CAMuxSocket &s)
 

Private Attributes

fd_set m_fdset
 
fd_set m_signaled_set
 
fd_set * m_set_read
 
fd_set * m_set_write
 
SINT32 m_max
 
CAMutex m_csFD_SET
 

Detailed Description

Definition at line 36 of file CASocketGroup.hpp.

Constructor & Destructor Documentation

◆ CASocketGroup()

CASocketGroup::CASocketGroup ( bool  bWrite)

Definition at line 37 of file CASocketGroup.cpp.

38  {
39  #ifndef HAVE_POLL
40  FD_ZERO(&m_fdset);
41  FD_ZERO(&m_signaled_set);
42  #ifndef _WIN32
43  m_max=0;
44  #endif
45  #else
46  m_pollfd=new struct pollfd[MAX_POLLFD];
47  memset((void*)m_pollfd,0,sizeof(struct pollfd)*MAX_POLLFD);
48  m_max=0;
49  #endif
50  setPoolForWrite(bWrite);
51  }
#define MAX_POLLFD
Definition: StdAfx.h:192
SINT32 setPoolForWrite(bool bWrite)

References m_fdset, m_max, m_signaled_set, MAX_POLLFD, and setPoolForWrite().

Here is the call graph for this function:

◆ ~CASocketGroup()

CASocketGroup::~CASocketGroup ( )
inline

Definition at line 40 of file CASocketGroup.hpp.

41  {
42  #ifdef HAVE_POLL
43  delete[] m_pollfd;
44  m_pollfd = NULL;
45  #endif
46  }

Member Function Documentation

◆ add() [1/3]

SINT32 CASocketGroup::add ( CAMuxSocket s)
inline

Definition at line 98 of file CASocketGroup.hpp.

99  {
100  m_csFD_SET.lock();
101  #ifndef HAVE_POLL
102  #ifndef _WIN32
103  if(m_max<(s.getSocket())+1)
104  m_max=(s.getSocket())+1;
105  #endif
106  #pragma warning( push )
107  #pragma warning( disable : 4127 ) //Disable: Bedingter Ausdruck ist konstant
108  FD_SET(s.getSocket(),&m_fdset);
109  #pragma warning( pop )
110  #else
111  SINT sock=s.getSocket();
112  m_pollfd[sock].fd=sock;
113  m_pollfd[sock].revents=0;
114  if(m_max<(sock+1))
115  m_max=sock+1;
116  //CAMsg::printMsg(LOG_DEBUG,"CASocketGroup::add() - socket: %d\n",sock);
117  #endif
118  m_csFD_SET.unlock();
119  return E_SUCCESS;
120  }
signed int SINT
Definition: basetypedefs.h:156
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
SOCKET getSocket()
Definition: CAMuxSocket.hpp:92
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2

References E_SUCCESS, CAMuxSocket::getSocket(), CAMutex::lock(), m_csFD_SET, m_fdset, m_max, and CAMutex::unlock().

Here is the call graph for this function:

◆ add() [2/3]

SINT32 CASocketGroup::add ( CASocket s)
inline

Definition at line 74 of file CASocketGroup.hpp.

75  {
76  SINT sock = s.getSocket();
77  m_csFD_SET.lock();
78  #ifndef HAVE_POLL
79  #ifndef _WIN32
80  if (m_max < (sock) + 1)
81  m_max = (sock) + 1;
82  #endif
83  #pragma warning( push )
84  #pragma warning( disable : 4127 ) //Disable: Bedingter Ausdruck ist konstant
85  FD_SET(sock, &m_fdset);
86  #pragma warning( pop )
87  #else
88  m_pollfd[sock].fd=sock;
89  m_pollfd[sock].revents=0;
90  if(m_max<(sock+1))
91  m_max=sock+1;
92  //CAMsg::printMsg(LOG_DEBUG,"CASocketGroup::add() - socket: %d\n",sock);
93  #endif
95  return E_SUCCESS;
96  }
SOCKET getSocket()
Returns the number of the Socket used.
Definition: CASocket.hpp:87

References E_SUCCESS, CASocket::getSocket(), CAMutex::lock(), m_csFD_SET, m_fdset, m_max, and CAMutex::unlock().

Here is the call graph for this function:

◆ add() [3/3]

SINT32 CASocketGroup::add ( SOCKET s)
inline

Definition at line 50 of file CASocketGroup.hpp.

51  {
52  m_csFD_SET.lock();
53 #ifndef HAVE_POLL
54 #ifndef _WIN32
55  if (m_max < (s) + 1)
56  m_max = (s) + 1;
57 #endif
58 #pragma warning(push)
59 #pragma warning(disable : 4127) //Disable: Bedingter Ausdruck ist konstant
60  FD_SET(s, &m_fdset);
61 #pragma warning(pop)
62 #else
63  m_pollfd[s].fd = s;
64  m_pollfd[s].revents = 0;
65  if (m_max < (s + 1))
66  m_max = s + 1;
67  //CAMsg::printMsg(LOG_DEBUG,"CASocketGroup::add() - socket: %d\n",sock);
68 #endif
70  return E_SUCCESS;
71  }

References E_SUCCESS, CAMutex::lock(), m_csFD_SET, m_fdset, m_max, and CAMutex::unlock().

Referenced by CAChain::addToSocketGroup(), CAMuxSocket::receive(), CAClientSocket::receiveFully(), CASocket::sendFully(), CASocket::sendFullyTimeOut(), and CASocket::setSocket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isSignaled() [1/3]

bool CASocketGroup::isSignaled ( CAMuxSocket s)
inline

Definition at line 145 of file CASocketGroup.hpp.

146  {
147  #ifndef HAVE_POLL
148  return FD_ISSET(s.getSocket(),&m_signaled_set)!=0;
149  #else
150  return m_pollfd[s.getSocket()].revents!=0;
151  #endif
152  }

References CAMuxSocket::getSocket(), and m_signaled_set.

Here is the call graph for this function:

◆ isSignaled() [2/3]

bool CASocketGroup::isSignaled ( CASocket s)
inline

Definition at line 127 of file CASocketGroup.hpp.

128  {
129  #ifndef HAVE_POLL
130  return FD_ISSET(s.getSocket(),&m_signaled_set)!=0;
131  #else
132  return m_pollfd[s.getSocket()].revents!=0;
133  #endif
134  }

References CASocket::getSocket(), and m_signaled_set.

Here is the call graph for this function:

◆ isSignaled() [3/3]

bool CASocketGroup::isSignaled ( CASocket ps)
inline

Definition at line 136 of file CASocketGroup.hpp.

137  {
138  #ifndef HAVE_POLL
139  return FD_ISSET(ps->getSocket(),&m_signaled_set)!=0;
140  #else
141  return m_pollfd[ps->getSocket()].revents!=0;
142  #endif
143  }

References CASocket::getSocket(), and m_signaled_set.

Here is the call graph for this function:

◆ remove() [1/2]

SINT32 CASocketGroup::remove ( CAMuxSocket s)

Definition at line 97 of file CASocketGroup.cpp.

98  {
99  m_csFD_SET.lock();
100  #ifndef HAVE_POLL
101  #pragma warning( push )
102  #pragma warning( disable : 4127 ) //Disable: Bedingter Ausdruck ist konstant
103  FD_CLR(s.getSocket(),&m_fdset);
104  #pragma warning (pop)
105  #else
106  SINT sock=s.getSocket();
107  m_pollfd[sock].fd=-1;
108  //CAMsg::printMsg(LOG_DEBUG,"CASocketGroup::remove() - socket: %d\n",sock);
109  #endif
110  m_csFD_SET.unlock();
111  return E_SUCCESS;
112  }

References E_SUCCESS, CAMuxSocket::getSocket(), CAMutex::lock(), m_csFD_SET, m_fdset, and CAMutex::unlock().

Here is the call graph for this function:

◆ remove() [2/2]

SINT32 CASocketGroup::remove ( CASocket s)

Definition at line 80 of file CASocketGroup.cpp.

81  {
82  m_csFD_SET.lock();
83  #ifndef HAVE_POLL
84  #pragma warning( push )
85  #pragma warning( disable : 4127 ) //Disable: Bedingter Ausdruck ist konstant
86  FD_CLR(s.getSocket(),&m_fdset);
87  #pragma warning (pop)
88  #else
89  SINT sock=s.getSocket();
90  m_pollfd[sock].fd=-1;
91  //CAMsg::printMsg(LOG_DEBUG,"CASocketGroup::remove() - socket: %d\n",sock);
92  #endif
94  return E_SUCCESS;
95  }

References E_SUCCESS, CASocket::getSocket(), CAMutex::lock(), m_csFD_SET, m_fdset, and CAMutex::unlock().

Referenced by CAChain::removeFromSocketGroup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ select() [1/2]

SINT32 CASocketGroup::select ( )

Definition at line 114 of file CASocketGroup.cpp.

115  {
116  #ifndef HAVE_POLL
117  m_csFD_SET.lock();
118  memcpy(&m_signaled_set,&m_fdset,sizeof(fd_set));
119  m_csFD_SET.unlock();
120  #ifdef _DEBUG
121  #ifdef _WIN32
122  int ret=::select(0,m_set_read,m_set_write,NULL,NULL);
123  #else
124  int ret=::select(m_max,m_set_read,m_set_write,NULL,NULL);
125  #endif
126  if(ret==SOCKET_ERROR)
127  {
128  CAMsg::printMsg(LOG_DEBUG,"SocketGroup Select-Fehler: %i\n",GET_NET_ERROR);
129  }
130  return ret;
131  #else
132  #ifdef _WIN32
133  return ::select(0,m_set_read,m_set_write,NULL,NULL);
134  #else
135  return ::select(m_max,m_set_read,m_set_write,NULL,NULL);
136  #endif
137  #endif
138  #else
139  m_csFD_SET.lock();
140  SINT32 ret=::poll((struct pollfd*)m_pollfd,m_max,-1);
141  m_csFD_SET.unlock();
142  return ret;
143  #endif
144  }
#define GET_NET_ERROR
Definition: StdAfx.h:469
#define SOCKET_ERROR
Definition: StdAfx.h:464
signed int SINT32
Definition: basetypedefs.h:132
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251
fd_set * m_set_write
fd_set * m_set_read

References GET_NET_ERROR, CAMutex::lock(), m_csFD_SET, m_fdset, m_max, m_set_read, m_set_write, m_signaled_set, CAMsg::printMsg(), SOCKET_ERROR, and CAMutex::unlock().

Referenced by CAMuxSocket::receive(), CAClientSocket::receiveFully(), CASocket::receiveFullyT(), CASocket::receiveLine(), select(), CASingleSocketGroup::select_once(), CASocket::sendFully(), and CASocket::sendFullyTimeOut().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ select() [2/2]

SINT32 CASocketGroup::select ( UINT32  time_ms)

Waits for events on the sockets.

If after ms milliseconds no event occurs, E_TIMEDOUT is returned

Parameters
time_ms- maximum milliseconds to wait
Return values
E_TIMEDOUT,ifother ms milliseconds no event occurs
E_UNKNOWN,ifan error occured
Returns
number of read/writeable sockets

Definition at line 153 of file CASocketGroup.cpp.

154  {
155  SINT32 ret;
156  #ifndef HAVE_POLL
157  m_csFD_SET.lock();
158  memcpy(&m_signaled_set,&m_fdset,sizeof(fd_set));
159  m_csFD_SET.unlock();
160  timeval ti;
161  ti.tv_sec=0;
162  ti.tv_usec=time_ms*1000;
163 
164  #ifdef _WIN32
165  if(m_signaled_set.fd_count==0)
166  {
167  Sleep(time_ms);
168  ret=E_TIMEDOUT;
169  }
170  else
171  ret=::select(0,m_set_read,m_set_write,NULL,&ti);
172  #else
173  ret=::select(m_max,m_set_read,m_set_write,NULL,&ti);
174  #endif
175  #else
176  m_csFD_SET.lock();
177  ret=::poll((struct pollfd*)m_pollfd,m_max,time_ms);
178  m_csFD_SET.unlock();
179  #endif
180  if(ret==0)
181  {
182  return E_TIMEDOUT;
183  }
184  if(ret==SOCKET_ERROR)
185  {
186  ret=GET_NET_ERROR;
187  #ifdef _DEBUG
188  CAMsg::printMsg(LOG_DEBUG,"SocketGroup Select-Fehler: %i\n",ret);
189  #endif
190  if(ret==EINTR)
191  return E_TIMEDOUT;
192  return E_UNKNOWN;
193  }
194  return ret;
195  }
#define E_UNKNOWN
Definition: errorcodes.hpp:3
#define E_TIMEDOUT
Definition: errorcodes.hpp:10

References E_TIMEDOUT, E_UNKNOWN, GET_NET_ERROR, CAMutex::lock(), m_csFD_SET, m_fdset, m_max, m_set_read, m_set_write, m_signaled_set, CAMsg::printMsg(), select(), SOCKET_ERROR, and CAMutex::unlock().

Here is the call graph for this function:

◆ setPoolForWrite()

SINT32 CASocketGroup::setPoolForWrite ( bool  bWrite)
inline

Definition at line 53 of file CASocketGroup.cpp.

54  {
55  #ifndef HAVE_POLL
56  if(!bWrite)
57  {
59  m_set_write=NULL;
60 
61  }
62  else
63  {
64  m_set_read=NULL;
66  }
67  #else
68  for(int i=0;i<MAX_POLLFD;i++)
69  {
70  if(bWrite)
71  m_pollfd[i].events=POLLOUT;
72  else
73  m_pollfd[i].events=POLLIN;
74  m_pollfd[i].fd=-1;
75  }
76  #endif
77  return E_SUCCESS;
78  }

References E_SUCCESS, m_set_read, m_set_write, m_signaled_set, and MAX_POLLFD.

Referenced by CASocketGroup().

Here is the caller graph for this function:

Member Data Documentation

◆ m_csFD_SET

CAMutex CASocketGroup::m_csFD_SET
private

Definition at line 166 of file CASocketGroup.hpp.

Referenced by add(), remove(), and select().

◆ m_fdset

fd_set CASocketGroup::m_fdset
private

Definition at line 156 of file CASocketGroup.hpp.

Referenced by add(), CASocketGroup(), remove(), and select().

◆ m_max

SINT32 CASocketGroup::m_max
private

Definition at line 160 of file CASocketGroup.hpp.

Referenced by add(), CASocketGroup(), and select().

◆ m_set_read

fd_set* CASocketGroup::m_set_read
private

Definition at line 158 of file CASocketGroup.hpp.

Referenced by select(), and setPoolForWrite().

◆ m_set_write

fd_set * CASocketGroup::m_set_write
private

Definition at line 158 of file CASocketGroup.hpp.

Referenced by select(), and setPoolForWrite().

◆ m_signaled_set

fd_set CASocketGroup::m_signaled_set
private

Definition at line 157 of file CASocketGroup.hpp.

Referenced by CASocketGroup(), isSignaled(), select(), and setPoolForWrite().


The documentation for this class was generated from the following files: