|
Mixe for Privacy and Anonymity in the Internet
|
#include <CASocketGroupEpoll.hpp>
Public Member Functions | |
| CASocketGroupEpoll (bool bWrite) | |
| ~CASocketGroupEpoll () | |
| SINT32 | setPoolForWrite (bool bWrite) |
| SINT32 | add (CASocket &s, void *datapointer) |
| Adds the socket s to the socket group. | |
| SINT32 | add (CAMuxSocket &s, void *datapointer) |
| Adds the socket s to the socket group. | |
| SINT32 | remove (CASocket &s) |
| SINT32 | remove (CAMuxSocket &s) |
| SINT32 | select () |
| SINT32 | select (UINT32 time_ms) |
| Waits for events on the sockets. | |
| bool | isSignaled (void *datapointer) |
| void * | getFirstSignaledSocketData () |
| void * | getNextSignaledSocketData () |
Private Attributes | |
| SINT32 | m_hEPFD |
| struct epoll_event * | m_pEvents |
| struct epoll_event * | m_pEpollEvent |
| SINT32 | m_iNumOfReadyFD |
| SINT32 | m_iAktSignaledSocket |
| CAMutex | m_csFD_SET |
Definition at line 38 of file CASocketGroupEpoll.hpp.
| CASocketGroupEpoll::CASocketGroupEpoll | ( | bool | bWrite | ) |
Definition at line 31 of file CASocketGroupEpoll.cpp.
References m_hEPFD, m_pEpollEvent, m_pEvents, MAX_POLLFD, and setPoolForWrite().
{
m_hEPFD=epoll_create(MAX_POLLFD);
m_pEpollEvent=new struct epoll_event;
memset(m_pEpollEvent,0,sizeof(struct epoll_event));
m_pEvents=new struct epoll_event[MAX_POLLFD];
setPoolForWrite(bWrite);
}
Definition at line 40 of file CASocketGroupEpoll.cpp.
References m_hEPFD, m_pEpollEvent, and m_pEvents.
{
close(m_hEPFD);
delete[] m_pEvents;
m_pEvents = NULL;
delete m_pEpollEvent;
m_pEpollEvent = NULL;
}
| SINT32 CASocketGroupEpoll::add | ( | CASocket & | s, |
| void * | datapointer | ||
| ) | [inline] |
Adds the socket s to the socket group.
Additional one can set a parameter datapointer, which is assoziated with the socke s
Definition at line 47 of file CASocketGroupEpoll.hpp.
References E_SUCCESS, CASocket::getSocket(), CAMutex::lock(), m_csFD_SET, m_hEPFD, m_pEpollEvent, SOCKET, and CAMutex::unlock().
Referenced by CAFirstMix::doUserLogin_internal(), CAFirstMixB::loop(), and CAFirstMixA::loop().
{
SINT32 ret=E_SUCCESS;
m_csFD_SET.lock();
SOCKET socket=s.getSocket();
m_pEpollEvent->data.ptr=datapointer;
//if(epoll_ctl(m_hEPFD,EPOLL_CTL_ADD,socket,m_pEpollEvent)!=0)
// ret=E_UNKNOWN;
ret=epoll_ctl(m_hEPFD,EPOLL_CTL_ADD,socket,m_pEpollEvent);
m_csFD_SET.unlock();
return ret;
}
| 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 socke s
Definition at line 63 of file CASocketGroupEpoll.hpp.
References E_SUCCESS, CAMuxSocket::getSocket(), CAMutex::lock(), m_csFD_SET, m_hEPFD, m_pEpollEvent, SOCKET, and CAMutex::unlock().
{
SINT32 ret=E_SUCCESS;
m_csFD_SET.lock();
SOCKET socket=s.getSocket();
m_pEpollEvent->data.ptr=datapointer;
//if(epoll_ctl(m_hEPFD,EPOLL_CTL_ADD,socket,m_pEpollEvent)!=0)
// ret=E_UNKNOWN;
ret=epoll_ctl(m_hEPFD,EPOLL_CTL_ADD,socket,m_pEpollEvent);
m_csFD_SET.unlock();
return ret;
}
| void* CASocketGroupEpoll::getFirstSignaledSocketData | ( | ) | [inline] |
Definition at line 183 of file CASocketGroupEpoll.hpp.
References m_iAktSignaledSocket, m_iNumOfReadyFD, and m_pEvents.
Referenced by CAFirstMixB::loop(), CAFirstMixA::loop(), and CAFirstMixA::sendToUsers().
{
m_iAktSignaledSocket=0;
if(m_iNumOfReadyFD>0)
return m_pEvents[0].data.ptr;
return NULL;
}
| void* CASocketGroupEpoll::getNextSignaledSocketData | ( | ) | [inline] |
Definition at line 191 of file CASocketGroupEpoll.hpp.
References m_iAktSignaledSocket, m_iNumOfReadyFD, and m_pEvents.
Referenced by CAFirstMixB::loop(), CAFirstMixA::loop(), and CAFirstMixA::sendToUsers().
{
m_iAktSignaledSocket++;
if(m_iNumOfReadyFD>m_iAktSignaledSocket)
return m_pEvents[m_iAktSignaledSocket].data.ptr;
return NULL;
}
| bool CASocketGroupEpoll::isSignaled | ( | void * | datapointer | ) | [inline] |
Definition at line 173 of file CASocketGroupEpoll.hpp.
References m_iNumOfReadyFD, and m_pEvents.
Referenced by CAChain::isSignaledInSocketGroup(), CAFirstMixB::loop(), CAFirstMixA::loop(), and CAFirstMixA::sendToUsers().
{
for(SINT32 i=0;i<m_iNumOfReadyFD;i++)
{
if(datapointer==m_pEvents->data.ptr)
return true;
}
return false;
}
| SINT32 CASocketGroupEpoll::remove | ( | CASocket & | s | ) | [inline] |
Definition at line 76 of file CASocketGroupEpoll.hpp.
References ASSERT, E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_csFD_SET, m_hEPFD, m_pEpollEvent, and CAMutex::unlock().
Referenced by CAFirstMixA::closeConnection(), CAFirstMixB::loop(), and CAChain::removeFromAllSocketGroupsInternal().
{
SINT32 ret=E_SUCCESS;
m_csFD_SET.lock();
if(epoll_ctl(m_hEPFD,EPOLL_CTL_DEL,s.getSocket(),m_pEpollEvent)!=0)
ret=E_UNKNOWN;
ASSERT(ret==E_SUCCESS,"Error in Epoll socket group remove")
m_csFD_SET.unlock();
return ret;
}
| SINT32 CASocketGroupEpoll::remove | ( | CAMuxSocket & | s | ) | [inline] |
Definition at line 87 of file CASocketGroupEpoll.hpp.
References ASSERT, E_SUCCESS, E_UNKNOWN, CAMutex::lock(), m_csFD_SET, m_hEPFD, m_pEpollEvent, and CAMutex::unlock().
{
SINT32 ret=E_SUCCESS;
m_csFD_SET.lock();
if(epoll_ctl(m_hEPFD,EPOLL_CTL_DEL,s.getSocket(),m_pEpollEvent)!=0)
ret=E_UNKNOWN;
ASSERT(ret==E_SUCCESS,"Error in Epoll socket group remove")
m_csFD_SET.unlock();
return ret;
}
| SINT32 CASocketGroupEpoll::select | ( | ) | [inline] |
Definition at line 98 of file CASocketGroupEpoll.hpp.
References E_UNKNOWN, CAMutex::lock(), m_csFD_SET, m_hEPFD, m_iNumOfReadyFD, m_pEvents, MAX_POLLFD, and CAMutex::unlock().
Referenced by CAFirstMixB::loop(), CAFirstMixA::loop(), and CAFirstMixA::sendToUsers().
{
m_csFD_SET.lock();
m_iNumOfReadyFD=epoll_wait(m_hEPFD,m_pEvents,MAX_POLLFD,-1);
if(m_iNumOfReadyFD>0)
{
m_csFD_SET.unlock();
return m_iNumOfReadyFD;
}
m_csFD_SET.unlock();
return E_UNKNOWN;
}
| SINT32 CASocketGroupEpoll::select | ( | UINT32 | time_ms | ) | [inline] |
Waits for events on the sockets.
If after ms milliseconds no event occurs, E_TIMEDOUT is returned
| time_ms | - maximum milliseconds to wait |
| E_TIMEDOUT,if | other ms milliseconds no event occurs |
| E_UNKNOWN,if | an error occured |
Definition at line 118 of file CASocketGroupEpoll.hpp.
References E_TIMEDOUT, E_UNKNOWN, CAMutex::lock(), m_csFD_SET, m_hEPFD, m_iNumOfReadyFD, m_pEvents, MAX_POLLFD, and CAMutex::unlock().
{
m_csFD_SET.lock();
m_iNumOfReadyFD=epoll_wait(m_hEPFD,m_pEvents,MAX_POLLFD,time_ms);
if(m_iNumOfReadyFD>0)
{
m_csFD_SET.unlock();
return m_iNumOfReadyFD;
}
else if(m_iNumOfReadyFD==0)
{
m_csFD_SET.unlock();
return E_TIMEDOUT;
}
m_csFD_SET.unlock();
return E_UNKNOWN;
}
| SINT32 CASocketGroupEpoll::setPoolForWrite | ( | bool | bWrite | ) |
Definition at line 49 of file CASocketGroupEpoll.cpp.
References E_SUCCESS, and m_pEpollEvent.
Referenced by CASocketGroupEpoll().
{
if(bWrite)
m_pEpollEvent->events=EPOLLOUT|EPOLLERR|EPOLLHUP;
else
m_pEpollEvent->events=EPOLLIN|EPOLLERR|EPOLLHUP;
return E_SUCCESS;
}
CAMutex CASocketGroupEpoll::m_csFD_SET [private] |
Definition at line 205 of file CASocketGroupEpoll.hpp.
SINT32 CASocketGroupEpoll::m_hEPFD [private] |
Definition at line 200 of file CASocketGroupEpoll.hpp.
Referenced by add(), CASocketGroupEpoll(), remove(), select(), and ~CASocketGroupEpoll().
Definition at line 204 of file CASocketGroupEpoll.hpp.
Referenced by getFirstSignaledSocketData(), and getNextSignaledSocketData().
SINT32 CASocketGroupEpoll::m_iNumOfReadyFD [private] |
Definition at line 203 of file CASocketGroupEpoll.hpp.
Referenced by getFirstSignaledSocketData(), getNextSignaledSocketData(), isSignaled(), and select().
struct epoll_event* CASocketGroupEpoll::m_pEpollEvent [private] |
Definition at line 202 of file CASocketGroupEpoll.hpp.
Referenced by add(), CASocketGroupEpoll(), remove(), setPoolForWrite(), and ~CASocketGroupEpoll().
struct epoll_event* CASocketGroupEpoll::m_pEvents [private] |
Definition at line 201 of file CASocketGroupEpoll.hpp.
Referenced by CASocketGroupEpoll(), getFirstSignaledSocketData(), getNextSignaledSocketData(), isSignaled(), select(), and ~CASocketGroupEpoll().
1.7.6.1