|
Mixe for Privacy and Anonymity in the Internet
|
#include <CASocketGroup.hpp>
Public Member Functions | |
| CASocketGroup (bool bWrite) | |
| ~CASocketGroup () | |
| SINT32 | setPoolForWrite (bool bWrite) |
| 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. | |
| 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 |
Definition at line 36 of file CASocketGroup.hpp.
| CASocketGroup::CASocketGroup | ( | bool | bWrite | ) |
Definition at line 37 of file CASocketGroup.cpp.
References m_fdset, m_max, m_signaled_set, and setPoolForWrite().
{
#ifndef HAVE_POLL
FD_ZERO(&m_fdset);
FD_ZERO(&m_signaled_set);
#ifndef _WIN32
m_max=0;
#endif
#else
m_pollfd=new struct pollfd[MAX_POLLFD];
memset((void*)m_pollfd,0,sizeof(struct pollfd)*MAX_POLLFD);
m_max=0;
#endif
setPoolForWrite(bWrite);
}
| CASocketGroup::~CASocketGroup | ( | ) | [inline] |
Definition at line 40 of file CASocketGroup.hpp.
{
#ifdef HAVE_POLL
delete[] m_pollfd;
m_pollfd = NULL;
#endif
}
| SINT32 CASocketGroup::add | ( | CASocket & | s | ) | [inline] |
Definition at line 49 of file CASocketGroup.hpp.
References E_SUCCESS, CASocket::getSocket(), CAMutex::lock(), m_csFD_SET, m_fdset, m_max, and CAMutex::unlock().
Referenced by CAChain::addToSocketGroup(), fm_loopAcceptUsers(), fm_loopReadFromMix(), lm_loopReadFromMix(), CALastMixA::loop(), CALocalProxy::loop(), CAMiddleMix::loop(), mm_loopReadFromMixAfter(), mm_loopReadFromMixBefore(), CAMuxSocket::receive(), CASocket::receiveFullyT(), and CASocket::receiveLine().
{
m_csFD_SET.lock();
#ifndef HAVE_POLL
#ifndef _WIN32
if(m_max<(s.getSocket())+1)
m_max=(s.getSocket())+1;
#endif
#pragma warning( push )
#pragma warning( disable : 4127 ) //Disable: Bedingter Ausdruck ist konstant
FD_SET(s.getSocket(),&m_fdset);
#pragma warning( pop )
#else
SINT sock=s.getSocket();
m_pollfd[sock].fd=sock;
m_pollfd[sock].revents=0;
if(m_max<(sock+1))
m_max=sock+1;
//CAMsg::printMsg(LOG_DEBUG,"CASocketGroup::add() - socket: %d\n",sock);
#endif
m_csFD_SET.unlock();
return E_SUCCESS;
}
| SINT32 CASocketGroup::add | ( | CAMuxSocket & | s | ) | [inline] |
Definition at line 73 of file CASocketGroup.hpp.
References E_SUCCESS, CAMuxSocket::getSocket(), CAMutex::lock(), m_csFD_SET, m_fdset, m_max, and CAMutex::unlock().
{
m_csFD_SET.lock();
#ifndef HAVE_POLL
#ifndef _WIN32
if(m_max<(s.getSocket())+1)
m_max=(s.getSocket())+1;
#endif
#pragma warning( push )
#pragma warning( disable : 4127 ) //Disable: Bedingter Ausdruck ist konstant
FD_SET(s.getSocket(),&m_fdset);
#pragma warning( pop )
#else
SINT sock=s.getSocket();
m_pollfd[sock].fd=sock;
m_pollfd[sock].revents=0;
if(m_max<(sock+1))
m_max=sock+1;
//CAMsg::printMsg(LOG_DEBUG,"CASocketGroup::add() - socket: %d\n",sock);
#endif
m_csFD_SET.unlock();
return E_SUCCESS;
}
| bool CASocketGroup::isSignaled | ( | CASocket & | s | ) | [inline] |
Definition at line 102 of file CASocketGroup.hpp.
References CASocket::getSocket(), and m_signaled_set.
Referenced by fm_loopAcceptUsers(), CALastMixA::loop(), and CALocalProxy::loop().
{
#ifndef HAVE_POLL
return FD_ISSET(s.getSocket(),&m_signaled_set)!=0;
#else
return m_pollfd[s.getSocket()].revents!=0;
#endif
}
| bool CASocketGroup::isSignaled | ( | CASocket * | ps | ) | [inline] |
Definition at line 111 of file CASocketGroup.hpp.
References CASocket::getSocket(), and m_signaled_set.
{
#ifndef HAVE_POLL
return FD_ISSET(ps->getSocket(),&m_signaled_set)!=0;
#else
return m_pollfd[ps->getSocket()].revents!=0;
#endif
}
| bool CASocketGroup::isSignaled | ( | CAMuxSocket & | s | ) | [inline] |
Definition at line 120 of file CASocketGroup.hpp.
References CAMuxSocket::getSocket(), and m_signaled_set.
{
#ifndef HAVE_POLL
return FD_ISSET(s.getSocket(),&m_signaled_set)!=0;
#else
return m_pollfd[s.getSocket()].revents!=0;
#endif
}
| SINT32 CASocketGroup::remove | ( | CASocket & | s | ) |
Definition at line 80 of file CASocketGroup.cpp.
References E_SUCCESS, CASocket::getSocket(), CAMutex::lock(), m_csFD_SET, m_fdset, and CAMutex::unlock().
Referenced by fm_loopAcceptUsers(), CALastMixA::loop(), CALocalProxy::loop(), and CAChain::removeFromSocketGroup().
{
m_csFD_SET.lock();
#ifndef HAVE_POLL
#pragma warning( push )
#pragma warning( disable : 4127 ) //Disable: Bedingter Ausdruck ist konstant
FD_CLR(s.getSocket(),&m_fdset);
#pragma warning (pop)
#else
SINT sock=s.getSocket();
m_pollfd[sock].fd=-1;
//CAMsg::printMsg(LOG_DEBUG,"CASocketGroup::remove() - socket: %d\n",sock);
#endif
m_csFD_SET.unlock();
return E_SUCCESS;
}
Definition at line 97 of file CASocketGroup.cpp.
References E_SUCCESS, CAMuxSocket::getSocket(), CAMutex::lock(), m_csFD_SET, m_fdset, and CAMutex::unlock().
{
m_csFD_SET.lock();
#ifndef HAVE_POLL
#pragma warning( push )
#pragma warning( disable : 4127 ) //Disable: Bedingter Ausdruck ist konstant
FD_CLR(s.getSocket(),&m_fdset);
#pragma warning (pop)
#else
SINT sock=s.getSocket();
m_pollfd[sock].fd=-1;
//CAMsg::printMsg(LOG_DEBUG,"CASocketGroup::remove() - socket: %d\n",sock);
#endif
m_csFD_SET.unlock();
return E_SUCCESS;
}
Definition at line 114 of file CASocketGroup.cpp.
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 fm_loopAcceptUsers(), fm_loopReadFromMix(), lm_loopReadFromMix(), CALastMixA::loop(), CALastMixB::loop(), CALocalProxy::loop(), mm_loopReadFromMixAfter(), mm_loopReadFromMixBefore(), CAMuxSocket::receive(), CASocket::receiveFullyT(), CASocket::receiveLine(), select(), and CASingleSocketGroup::select_once().
{
#ifndef HAVE_POLL
m_csFD_SET.lock();
memcpy(&m_signaled_set,&m_fdset,sizeof(fd_set));
m_csFD_SET.unlock();
#ifdef _DEBUG
#ifdef _WIN32
int ret=::select(0,m_set_read,m_set_write,NULL,NULL);
#else
int ret=::select(m_max,m_set_read,m_set_write,NULL,NULL);
#endif
if(ret==SOCKET_ERROR)
{
CAMsg::printMsg(LOG_DEBUG,"SocketGroup Select-Fehler: %i\n",GET_NET_ERROR);
}
return ret;
#else
#ifdef _WIN32
return ::select(0,m_set_read,m_set_write,NULL,NULL);
#else
return ::select(m_max,m_set_read,m_set_write,NULL,NULL);
#endif
#endif
#else
m_csFD_SET.lock();
SINT32 ret=::poll((struct pollfd*)m_pollfd,m_max,-1);
m_csFD_SET.unlock();
return ret;
#endif
}
| SINT32 CASocketGroup::select | ( | UINT32 | time_ms | ) |
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 153 of file CASocketGroup.cpp.
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().
{
SINT32 ret;
#ifndef HAVE_POLL
m_csFD_SET.lock();
memcpy(&m_signaled_set,&m_fdset,sizeof(fd_set));
m_csFD_SET.unlock();
timeval ti;
ti.tv_sec=0;
ti.tv_usec=time_ms*1000;
#ifdef _WIN32
if(m_signaled_set.fd_count==0)
{
Sleep(time_ms);
ret=E_TIMEDOUT;
}
else
ret=::select(0,m_set_read,m_set_write,NULL,&ti);
#else
ret=::select(m_max,m_set_read,m_set_write,NULL,&ti);
#endif
#else
m_csFD_SET.lock();
ret=::poll((struct pollfd*)m_pollfd,m_max,time_ms);
m_csFD_SET.unlock();
#endif
if(ret==0)
{
return E_TIMEDOUT;
}
if(ret==SOCKET_ERROR)
{
ret=GET_NET_ERROR;
#ifdef _DEBUG
CAMsg::printMsg(LOG_DEBUG,"SocketGroup Select-Fehler: %i\n",ret);
#endif
if(ret==EINTR)
return E_TIMEDOUT;
return E_UNKNOWN;
}
return ret;
}
| SINT32 CASocketGroup::setPoolForWrite | ( | bool | bWrite | ) | [inline] |
Definition at line 53 of file CASocketGroup.cpp.
References E_SUCCESS, m_set_read, m_set_write, m_signaled_set, and MAX_POLLFD.
Referenced by CASocketGroup().
{
#ifndef HAVE_POLL
if(!bWrite)
{
m_set_read=&m_signaled_set;
m_set_write=NULL;
}
else
{
m_set_read=NULL;
m_set_write=&m_signaled_set;
}
#else
for(int i=0;i<MAX_POLLFD;i++)
{
if(bWrite)
m_pollfd[i].events=POLLOUT;
else
m_pollfd[i].events=POLLIN;
m_pollfd[i].fd=-1;
}
#endif
return E_SUCCESS;
}
CAMutex CASocketGroup::m_csFD_SET [private] |
Definition at line 141 of file CASocketGroup.hpp.
fd_set CASocketGroup::m_fdset [private] |
Definition at line 131 of file CASocketGroup.hpp.
Referenced by add(), CASocketGroup(), remove(), and select().
SINT32 CASocketGroup::m_max [private] |
Definition at line 135 of file CASocketGroup.hpp.
Referenced by add(), CASocketGroup(), and select().
fd_set* CASocketGroup::m_set_read [private] |
Definition at line 133 of file CASocketGroup.hpp.
Referenced by select(), and setPoolForWrite().
fd_set * CASocketGroup::m_set_write [private] |
Definition at line 133 of file CASocketGroup.hpp.
Referenced by select(), and setPoolForWrite().
fd_set CASocketGroup::m_signaled_set [private] |
Definition at line 132 of file CASocketGroup.hpp.
Referenced by CASocketGroup(), isSignaled(), select(), and setPoolForWrite().
1.7.6.1