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

#include <CASocketGroupEpoll.hpp>

Collaboration diagram for CASocketGroupEpoll:

Public Member Functions

 CASocketGroupEpoll (bool bWrite)
 
 ~CASocketGroupEpoll ()
 
SINT32 setPoolForWrite (bool bWrite)
 
SINT32 add (CASocket &s)
 Adds the socket s to the socket group. More...
 
SINT32 add (CAMuxSocket &s)
 Adds the socket s to the socket group. More...
 
SINT32 add (CASocket &s, void *datapointer)
 
SINT32 add (CAMuxSocket &s, void *datapointer)
 Adds the socket s to the socket group. More...
 
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)
 
bool isSignaled (void *datapointer)
 
void * getFirstSignaledSocketData ()
 
void * getNextSignaledSocketData ()
 

Private Attributes

EPOLL_HANDLE m_hEPFD
 
struct epoll_event * m_pEvents
 
struct epoll_event * m_pEpollEvent
 
SINT32 m_iNumOfReadyFD
 
SINT32 m_iAktSignaledSocket
 
CAMutexm_pcsFD_SET
 

Detailed Description

Definition at line 42 of file CASocketGroupEpoll.hpp.

Constructor & Destructor Documentation

◆ CASocketGroupEpoll()

CASocketGroupEpoll::CASocketGroupEpoll ( bool  bWrite)

Definition at line 31 of file CASocketGroupEpoll.cpp.

32  {
33  m_pcsFD_SET = new CAMutex();
34  m_hEPFD=epoll_create(MAX_POLLFD);
35  m_pEpollEvent=new struct epoll_event;
36  memset(m_pEpollEvent,0,sizeof(struct epoll_event));
37  m_pEvents=new struct epoll_event[MAX_POLLFD];
38  setPoolForWrite(bWrite);
39  }
#define MAX_POLLFD
Definition: StdAfx.h:192
struct epoll_event * m_pEvents
struct epoll_event * m_pEpollEvent
SINT32 setPoolForWrite(bool bWrite)

References m_hEPFD, m_pcsFD_SET, m_pEpollEvent, m_pEvents, MAX_POLLFD, and setPoolForWrite().

Here is the call graph for this function:

◆ ~CASocketGroupEpoll()

CASocketGroupEpoll::~CASocketGroupEpoll ( )

Definition at line 41 of file CASocketGroupEpoll.cpp.

42  {
44  delete[] m_pEvents;
45  m_pEvents = NULL;
46  delete m_pEpollEvent;
47  m_pEpollEvent = NULL;
48  delete m_pcsFD_SET;
49  }
#define epoll_close
Definition: StdAfx.h:434

References epoll_close, m_hEPFD, m_pcsFD_SET, m_pEpollEvent, and m_pEvents.

Member Function Documentation

◆ add() [1/4]

SINT32 CASocketGroupEpoll::add ( CAMuxSocket s)
inline

Adds the socket s to the socket group.

Definition at line 56 of file CASocketGroupEpoll.hpp.

57  {
58  return add(s, NULL);
59  }
SINT32 add(CASocket &s)
Adds the socket s to the socket group.

References add().

Here is the call graph for this function:

◆ add() [2/4]

SINT32 CASocketGroupEpoll::add ( CAMuxSocket s,
void *  datapointer 
)
inline

Adds the socket s to the socket group.

Additional one can set a parameter datapointer, which is assoziated with the socket s

Definition at line 95 of file CASocketGroupEpoll.hpp.

96  {
97  return add(*(s.getCASocket()),datapointer);
98  }
CASocket * getCASocket()
Definition: CAMuxSocket.hpp:84

References add(), and CAMuxSocket::getCASocket().

Here is the call graph for this function:

◆ add() [3/4]

SINT32 CASocketGroupEpoll::add ( CASocket s)
inline

Adds the socket s to the socket group.

Definition at line 50 of file CASocketGroupEpoll.hpp.

51  {
52  return add(s,NULL);
53  }

Referenced by add(), CALocalProxy::loop(), CAFirstMixA::loop(), CALastMixA::loop(), and CAFirstMixB::loop().

Here is the caller graph for this function:

◆ add() [4/4]

SINT32 CASocketGroupEpoll::add ( CASocket s,
void *  datapointer 
)
inline

Definition at line 65 of file CASocketGroupEpoll.hpp.

66  {
67  SINT32 ret=E_SUCCESS;
68  m_pcsFD_SET->lock();
69  SOCKET socket=s.getSocket();
70  if (datapointer != NULL)
71  m_pEpollEvent->data.ptr = datapointer;
72  else
73  m_pEpollEvent->data.fd = socket;
74 
75  if (epoll_ctl(m_hEPFD, EPOLL_CTL_ADD, socket, m_pEpollEvent) != 0)
76  {
77  SINT32 err = GETERROR;
78  if (err == EEXIST)
79  {
80  ret=E_ALREADY_CONTAINED;
81  }
82  else
83  {
84  CAMsg::printMsg(LOG_DEBUG, "Failed to add socket %i to epoll group --- errno: %i\n", socket, err);
85  ret = E_UNKNOWN;
86  }
87  }
89  return ret;
90  }
#define GETERROR
Definition: StdAfx.h:473
#define SOCKET
Definition: StdAfx.h:460
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
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
SOCKET getSocket()
Returns the number of the Socket used.
Definition: CASocket.hpp:87
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_UNKNOWN
Definition: errorcodes.hpp:3

References E_SUCCESS, E_UNKNOWN, GETERROR, CASocket::getSocket(), CAMutex::lock(), m_hEPFD, m_pcsFD_SET, m_pEpollEvent, CAMsg::printMsg(), SOCKET, and CAMutex::unlock().

Here is the call graph for this function:

◆ getFirstSignaledSocketData()

void* CASocketGroupEpoll::getFirstSignaledSocketData ( )
inline

Definition at line 202 of file CASocketGroupEpoll.hpp.

203  {
205  if(m_iNumOfReadyFD>0)
206  return m_pEvents[0].data.ptr;
207  return NULL;
208  }

References m_iAktSignaledSocket, m_iNumOfReadyFD, and m_pEvents.

Referenced by CAFirstMixA::loop(), CALastMixA::loop(), CAFirstMixB::loop(), CALastMixB::loop(), and CAFirstMixA::sendToUsers().

Here is the caller graph for this function:

◆ getNextSignaledSocketData()

void* CASocketGroupEpoll::getNextSignaledSocketData ( )
inline

Definition at line 211 of file CASocketGroupEpoll.hpp.

212  {
215  return m_pEvents[m_iAktSignaledSocket].data.ptr;
216  return NULL;
217  }

References m_iAktSignaledSocket, m_iNumOfReadyFD, and m_pEvents.

Referenced by CAFirstMixA::loop(), CALastMixA::loop(), CAFirstMixB::loop(), CALastMixB::loop(), and CAFirstMixA::sendToUsers().

Here is the caller graph for this function:

◆ isSignaled() [1/4]

bool CASocketGroupEpoll::isSignaled ( CAMuxSocket s)
inline

Definition at line 179 of file CASocketGroupEpoll.hpp.

180  {
181  SINT32 socket=s.getSocket();
182  for(SINT32 i=0;i<m_iNumOfReadyFD;i++)
183  {
184  if(socket==m_pEvents[i].data.fd)
185  return true;
186  }
187  return false;
188  }
SOCKET getSocket()
Definition: CAMuxSocket.hpp:92
UINT8 data[PAYLOAD_SIZE]
Definition: typedefs.hpp:2

References data, CAMuxSocket::getSocket(), m_iNumOfReadyFD, and m_pEvents.

Here is the call graph for this function:

◆ isSignaled() [2/4]

bool CASocketGroupEpoll::isSignaled ( CASocket s)
inline

Definition at line 155 of file CASocketGroupEpoll.hpp.

156  {
157  SINT32 socket=s.getSocket();
158  for(SINT32 i=0;i<m_iNumOfReadyFD;i++)
159  {
160  if(socket==m_pEvents[i].data.fd)
161  return true;
162  }
163  return false;
164  }

References data, CASocket::getSocket(), m_iNumOfReadyFD, and m_pEvents.

Referenced by CAChain::isSignaledInSocketGroup(), CALocalProxy::loop(), CAFirstMixA::loop(), CALastMixA::loop(), CAFirstMixB::loop(), and CAFirstMixA::sendToUsers().

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

◆ isSignaled() [3/4]

bool CASocketGroupEpoll::isSignaled ( CASocket ps)
inline

Definition at line 167 of file CASocketGroupEpoll.hpp.

168  {
169  SINT32 socket=ps->getSocket();
170  for(SINT32 i=0;i<m_iNumOfReadyFD;i++)
171  {
172  if(socket==m_pEvents[i].data.fd)
173  return true;
174  }
175  return false;
176  }

References data, CASocket::getSocket(), m_iNumOfReadyFD, and m_pEvents.

Here is the call graph for this function:

◆ isSignaled() [4/4]

bool CASocketGroupEpoll::isSignaled ( void *  datapointer)
inline

Definition at line 191 of file CASocketGroupEpoll.hpp.

192  {
193  for(SINT32 i=0;i<m_iNumOfReadyFD;i++)
194  {
195  if(datapointer==m_pEvents[i].data.ptr)
196  return true;
197  }
198  return false;
199  }

References data, m_iNumOfReadyFD, and m_pEvents.

◆ remove() [1/2]

SINT32 CASocketGroupEpoll::remove ( CAMuxSocket s)
inline

Definition at line 111 of file CASocketGroupEpoll.hpp.

112  {
113  return remove(*(s.getCASocket()));
114  }
SINT32 remove(CASocket &s)

References CAMuxSocket::getCASocket(), and remove().

Here is the call graph for this function:

◆ remove() [2/2]

SINT32 CASocketGroupEpoll::remove ( CASocket s)
inline

Definition at line 100 of file CASocketGroupEpoll.hpp.

101  {
102  SINT32 ret=E_SUCCESS;
103  m_pcsFD_SET->lock();
104  if(epoll_ctl(m_hEPFD,EPOLL_CTL_DEL,s.getSocket(),m_pEpollEvent)!=0)
105  ret=E_UNKNOWN;
106  ASSERT(ret==E_SUCCESS,"Error in Epoll socket group remove")
107  m_pcsFD_SET->unlock();
108  return ret;
109  }
#define ASSERT(cond, msg)
Definition: StdAfx.h:546

References ASSERT, E_SUCCESS, E_UNKNOWN, CASocket::getSocket(), CAMutex::lock(), m_hEPFD, m_pcsFD_SET, m_pEpollEvent, and CAMutex::unlock().

Referenced by CAFirstMixA::closeConnection(), CALocalProxy::loop(), CALastMixA::loop(), CAFirstMixB::loop(), remove(), and CAChain::removeFromAllSocketGroupsInternal().

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

◆ select() [1/2]

SINT32 CASocketGroupEpoll::select ( )
inline

Definition at line 116 of file CASocketGroupEpoll.hpp.

117  {
118  m_pcsFD_SET->lock();
120  if(m_iNumOfReadyFD>0)
121  {
122  m_pcsFD_SET->unlock();
123  return m_iNumOfReadyFD;
124  }
125  m_pcsFD_SET->unlock();
126  return E_UNKNOWN;
127  }

References E_UNKNOWN, CAMutex::lock(), m_hEPFD, m_iNumOfReadyFD, m_pcsFD_SET, m_pEvents, MAX_POLLFD, and CAMutex::unlock().

Referenced by CALocalProxy::loop(), CAFirstMixA::loop(), CALastMixA::loop(), CAFirstMixB::loop(), CALastMixB::loop(), and CAFirstMixA::sendToUsers().

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

◆ select() [2/2]

SINT32 CASocketGroupEpoll::select ( UINT32  time_ms)
inline

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 136 of file CASocketGroupEpoll.hpp.

137  {
138  m_pcsFD_SET->lock();
139  m_iNumOfReadyFD=epoll_wait(m_hEPFD,m_pEvents,MAX_POLLFD,time_ms);
140  if(m_iNumOfReadyFD>0)
141  {
142  m_pcsFD_SET->unlock();
143  return m_iNumOfReadyFD;
144  }
145  else if(m_iNumOfReadyFD==0)
146  {
147  m_pcsFD_SET->unlock();
148  return E_TIMEDOUT;
149  }
150  m_pcsFD_SET->unlock();
151  return E_UNKNOWN;
152  }
#define E_TIMEDOUT
Definition: errorcodes.hpp:10

References E_TIMEDOUT, E_UNKNOWN, CAMutex::lock(), m_hEPFD, m_iNumOfReadyFD, m_pcsFD_SET, m_pEvents, MAX_POLLFD, and CAMutex::unlock().

Here is the call graph for this function:

◆ setPoolForWrite()

SINT32 CASocketGroupEpoll::setPoolForWrite ( bool  bWrite)

Definition at line 51 of file CASocketGroupEpoll.cpp.

52  {
53  if(bWrite)
54  m_pEpollEvent->events=EPOLLOUT|EPOLLERR|EPOLLHUP;
55  else
56  m_pEpollEvent->events=EPOLLIN| EPOLLERR|EPOLLHUP;
57  return E_SUCCESS;
58  }

References E_SUCCESS, and m_pEpollEvent.

Referenced by CASocketGroupEpoll().

Here is the caller graph for this function:

Member Data Documentation

◆ m_hEPFD

EPOLL_HANDLE CASocketGroupEpoll::m_hEPFD
private

Definition at line 220 of file CASocketGroupEpoll.hpp.

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

◆ m_iAktSignaledSocket

SINT32 CASocketGroupEpoll::m_iAktSignaledSocket
private

◆ m_iNumOfReadyFD

SINT32 CASocketGroupEpoll::m_iNumOfReadyFD
private

◆ m_pcsFD_SET

CAMutex* CASocketGroupEpoll::m_pcsFD_SET
private

Definition at line 225 of file CASocketGroupEpoll.hpp.

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

◆ m_pEpollEvent

struct epoll_event* CASocketGroupEpoll::m_pEpollEvent
private

◆ m_pEvents

struct epoll_event* CASocketGroupEpoll::m_pEvents
private

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