|
Mixe for Privacy and Anonymity in the Internet
|
00001 #ifndef __CASOCKET__ 00002 #define __CASOCKET__ 00003 /* 00004 Copyright (c) 2000, The JAP-Team 00005 All rights reserved. 00006 Redistribution and use in source and binary forms, with or without modification, 00007 are permitted provided that the following conditions are met: 00008 00009 - Redistributions of source code must retain the above copyright notice, 00010 this list of conditions and the following disclaimer. 00011 00012 - Redistributions in binary form must reproduce the above copyright notice, 00013 this list of conditions and the following disclaimer in the documentation and/or 00014 other materials provided with the distribution. 00015 00016 - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors 00017 may be used to endorse or promote products derived from this software without specific 00018 prior written permission. 00019 00020 00021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 00022 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00023 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 00024 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00025 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00026 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00027 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00028 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00029 */ 00030 #include "CASocketAddr.hpp" 00031 #include "CAClientSocket.hpp" 00032 #include "CAMutex.hpp" 00033 #include "CAMsg.hpp" 00034 class CASocket:public CAClientSocket 00035 { 00036 public: 00037 CASocket(bool bIsReserved=false); 00038 ~CASocket(){close();} 00039 00040 virtual SINT32 create(); 00041 virtual SINT32 create(bool a_bShowTypicalError); 00042 virtual SINT32 create(int type); 00043 00044 virtual SINT32 listen(const CASocketAddr& psa); 00045 virtual SINT32 listen(UINT16 port); 00046 virtual SINT32 accept(CASocket &s); 00047 00048 virtual SINT32 connect(const CASocketAddr& psa) 00049 { 00050 return connect(psa,1,0); 00051 } 00052 virtual SINT32 connect(const CASocketAddr& psa,UINT32 retry,UINT32 sWaitTime); 00053 virtual SINT32 connect(const CASocketAddr& psa,UINT32 msTimeOut); 00054 00055 virtual SINT32 close(); 00056 /* it seems that this function is not used: 00057 virtual SINT32 close(UINT32 mode);*/ 00058 virtual SINT32 send(const UINT8* buff,UINT32 len); 00059 virtual SINT32 sendFully(const UINT8* buff,UINT32 len); 00060 virtual SINT32 sendFullyTimeOut(const UINT8* buff,UINT32 len, UINT32 msTimeOut, UINT32 msTimeOutSingleSend); 00061 virtual SINT32 sendTimeOut(const UINT8* buff,UINT32 len,UINT32 msTimeOut); 00062 virtual SINT32 receive(UINT8* buff,UINT32 len); 00063 virtual SINT32 receiveFullyT(UINT8* buff,UINT32 len,UINT32 msTimeOut); 00064 virtual SINT32 receiveLine(UINT8* line, UINT32 maxLen, UINT32 msTimeOut); 00070 SOCKET getSocket() 00071 { 00072 return m_Socket; 00073 } 00074 00075 00076 virtual SINT32 getLocalIP(UINT8 r_Ip[4]); 00077 virtual SINT32 getLocalPort(); 00078 virtual SINT32 getPeerIP(UINT8 ip[4]); 00079 virtual SINT32 getPeerPort(); 00080 virtual SINT32 setReuseAddr(bool b); 00081 //SINT32 setRecvLowWat(UINT32 r); 00082 //SINT32 setSendLowWat(UINT32 r); 00083 //SINT32 getSendLowWat(); 00084 virtual SINT32 setSendTimeOut(UINT32 msTimeOut); 00085 virtual SINT32 getSendTimeOut(); 00086 virtual SINT32 setRecvBuff(UINT32 r); 00087 virtual SINT32 getRecvBuff(); 00088 virtual SINT32 setSendBuff(SINT32 r); 00089 virtual SINT32 getSendBuff(); 00090 virtual SINT32 setKeepAlive(bool b); 00091 virtual SINT32 setKeepAlive(UINT32 sec); 00092 virtual SINT32 setNonBlocking(bool b); 00093 virtual SINT32 getNonBlocking(bool* b); 00094 00099 static SINT32 setMaxNormalSockets(UINT32 u) 00100 { 00101 m_u32MaxNormalSockets=u; 00102 return E_SUCCESS; 00103 } 00104 00110 static SINT32 getMaxOpenSockets(); 00111 static UINT32 countOpenSockets() 00112 { 00113 return m_u32NormalSocketsOpen; 00114 } 00115 virtual bool isClosed() 00116 { 00117 return m_bSocketIsClosed; 00118 } 00119 00120 protected: 00122 /* CASocket* getSocket() 00123 { 00124 return this; 00125 } 00126 */ 00128 volatile bool m_bSocketIsClosed; //this is a flag, which shows, if the m_Socket is valid 00129 //we should not set m_Socket to -1 or so after close, 00130 //because the Socket value ist needed sometimes even after close!!! 00131 // (because it is used as a Key in lookups for instance as a HashValue etc.) 00132 00133 SOCKET m_Socket; 00134 private: 00135 SINT32 create(int type, bool a_bShowTypicalError); 00136 00137 CAMutex m_csClose; 00140 volatile static UINT32 m_u32NormalSocketsOpen; //how many "normal" sockets are open 00141 static UINT32 m_u32MaxNormalSockets; //how many "normal" sockets are allowed at max 00142 bool m_bIsReservedSocket; 00143 }; 00144 #endif
1.7.6.1