Mixe for Privacy and Anonymity in the Internet
CASocketGroup.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2000, The JAP-Team
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6 
7  - Redistributions of source code must retain the above copyright notice,
8  this list of conditions and the following disclaimer.
9 
10  - Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation and/or
12  other materials provided with the distribution.
13 
14  - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors
15  may be used to endorse or promote products derived from this software without specific
16  prior written permission.
17 
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
20 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
27 */
28 #ifndef __CASOCKETGROUP__
29 #define __CASOCKETGROUP__
30 #include "CAMuxSocket.hpp"
31 #include "CAMutex.hpp"
32 /*#ifdef HAVE_EPOLL
33  #include "CASocketGroupEpoll.hpp"
34  typedef CASocketGroupEpoll CASocketGroup;
35 #else*/
37  {
38  public:
39  CASocketGroup(bool bWrite);
41  {
42  #ifdef HAVE_POLL
43  delete[] m_pollfd;
44  m_pollfd = NULL;
45  #endif
46  }
47 
48  inline SINT32 setPoolForWrite(bool bWrite);
49 
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  }
72 
73 
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  }
97 
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  }
121 
124  SINT32 select();
125  SINT32 select(UINT32 time_ms);
126 
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  }
135 
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  }
144 
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  }
153 
154  private:
155  #ifndef HAVE_POLL
156  fd_set m_fdset;
159  #ifndef _WIN32
161  #endif
162  #else
163  volatile struct pollfd* m_pollfd;
164  volatile SINT32 m_max;
165  #endif
167  };
168 #endif
169 //#endif
#define SOCKET
Definition: StdAfx.h:460
signed int SINT32
Definition: basetypedefs.h:132
signed int SINT
Definition: basetypedefs.h:156
unsigned int UINT32
Definition: basetypedefs.h:131
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
SOCKET getSocket()
Definition: CAMuxSocket.hpp:92
SINT32 add(CAMuxSocket &s)
fd_set * m_set_write
bool isSignaled(CAMuxSocket &s)
SINT32 add(CASocket &s)
SINT32 setPoolForWrite(bool bWrite)
bool isSignaled(CASocket &s)
SINT32 add(SOCKET &s)
bool isSignaled(CASocket *ps)
SINT32 remove(CASocket &s)
fd_set * m_set_read
CASocketGroup(bool bWrite)
SOCKET getSocket()
Returns the number of the Socket used.
Definition: CASocket.hpp:87
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2