|
Mixe for Privacy and Anonymity in the Internet
|
00001 /* 00002 Copyright (c) 2000, The JAP-Team 00003 All rights reserved. 00004 Redistribution and use in source and binary forms, with or without modification, 00005 are permitted provided that the following conditions are met: 00006 00007 - Redistributions of source code must retain the above copyright notice, 00008 this list of conditions and the following disclaimer. 00009 00010 - Redistributions in binary form must reproduce the above copyright notice, 00011 this list of conditions and the following disclaimer in the documentation and/or 00012 other materials provided with the distribution. 00013 00014 - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors 00015 may be used to endorse or promote products derived from this software without specific 00016 prior written permission. 00017 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 00020 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00021 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 00022 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00023 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00024 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00025 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00027 */ 00028 #ifndef __CASOCKETGROUP__ 00029 #define __CASOCKETGROUP__ 00030 #include "CAMuxSocket.hpp" 00031 #include "CAMutex.hpp" 00032 /*#ifdef HAVE_EPOLL 00033 #include "CASocketGroupEpoll.hpp" 00034 typedef CASocketGroupEpoll CASocketGroup; 00035 #else*/ 00036 class CASocketGroup 00037 { 00038 public: 00039 CASocketGroup(bool bWrite); 00040 ~CASocketGroup() 00041 { 00042 #ifdef HAVE_POLL 00043 delete[] m_pollfd; 00044 m_pollfd = NULL; 00045 #endif 00046 } 00047 00048 inline SINT32 setPoolForWrite(bool bWrite); 00049 SINT32 add(CASocket&s) 00050 { 00051 m_csFD_SET.lock(); 00052 #ifndef HAVE_POLL 00053 #ifndef _WIN32 00054 if(m_max<(s.getSocket())+1) 00055 m_max=(s.getSocket())+1; 00056 #endif 00057 #pragma warning( push ) 00058 #pragma warning( disable : 4127 ) //Disable: Bedingter Ausdruck ist konstant 00059 FD_SET(s.getSocket(),&m_fdset); 00060 #pragma warning( pop ) 00061 #else 00062 SINT sock=s.getSocket(); 00063 m_pollfd[sock].fd=sock; 00064 m_pollfd[sock].revents=0; 00065 if(m_max<(sock+1)) 00066 m_max=sock+1; 00067 //CAMsg::printMsg(LOG_DEBUG,"CASocketGroup::add() - socket: %d\n",sock); 00068 #endif 00069 m_csFD_SET.unlock(); 00070 return E_SUCCESS; 00071 } 00072 00073 SINT32 add(CAMuxSocket&s) 00074 { 00075 m_csFD_SET.lock(); 00076 #ifndef HAVE_POLL 00077 #ifndef _WIN32 00078 if(m_max<(s.getSocket())+1) 00079 m_max=(s.getSocket())+1; 00080 #endif 00081 #pragma warning( push ) 00082 #pragma warning( disable : 4127 ) //Disable: Bedingter Ausdruck ist konstant 00083 FD_SET(s.getSocket(),&m_fdset); 00084 #pragma warning( pop ) 00085 #else 00086 SINT sock=s.getSocket(); 00087 m_pollfd[sock].fd=sock; 00088 m_pollfd[sock].revents=0; 00089 if(m_max<(sock+1)) 00090 m_max=sock+1; 00091 //CAMsg::printMsg(LOG_DEBUG,"CASocketGroup::add() - socket: %d\n",sock); 00092 #endif 00093 m_csFD_SET.unlock(); 00094 return E_SUCCESS; 00095 } 00096 00097 SINT32 remove(CASocket&s); 00098 SINT32 remove(CAMuxSocket&s); 00099 SINT32 select(); 00100 SINT32 select(UINT32 time_ms); 00101 00102 bool isSignaled(CASocket&s) 00103 { 00104 #ifndef HAVE_POLL 00105 return FD_ISSET(s.getSocket(),&m_signaled_set)!=0; 00106 #else 00107 return m_pollfd[s.getSocket()].revents!=0; 00108 #endif 00109 } 00110 00111 bool isSignaled(CASocket*ps) 00112 { 00113 #ifndef HAVE_POLL 00114 return FD_ISSET(ps->getSocket(),&m_signaled_set)!=0; 00115 #else 00116 return m_pollfd[ps->getSocket()].revents!=0; 00117 #endif 00118 } 00119 00120 bool isSignaled(CAMuxSocket&s) 00121 { 00122 #ifndef HAVE_POLL 00123 return FD_ISSET(s.getSocket(),&m_signaled_set)!=0; 00124 #else 00125 return m_pollfd[s.getSocket()].revents!=0; 00126 #endif 00127 } 00128 00129 private: 00130 #ifndef HAVE_POLL 00131 fd_set m_fdset; 00132 fd_set m_signaled_set; 00133 fd_set* m_set_read,*m_set_write; 00134 #ifndef _WIN32 00135 SINT32 m_max; 00136 #endif 00137 #else 00138 volatile struct pollfd* m_pollfd; 00139 volatile SINT32 m_max; 00140 #endif 00141 CAMutex m_csFD_SET; 00142 }; 00143 #endif 00144 //#endif
1.7.6.1