Mixe for Privacy and Anonymity in the Internet
CASocket.hpp
Go to the documentation of this file.
1 #ifndef __CASOCKET__
2 #define __CASOCKET__
3 /*
4 Copyright (c) 2000, The JAP-Team
5 All rights reserved.
6 Redistribution and use in source and binary forms, with or without modification,
7 are permitted provided that the following conditions are met:
8 
9  - Redistributions of source code must retain the above copyright notice,
10  this list of conditions and the following disclaimer.
11 
12  - Redistributions in binary form must reproduce the above copyright notice,
13  this list of conditions and the following disclaimer in the documentation and/or
14  other materials provided with the distribution.
15 
16  - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors
17  may be used to endorse or promote products derived from this software without specific
18  prior written permission.
19 
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
22 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
24 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
26 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29 */
30 #include "CASocketAddr.hpp"
31 #include "CAClientSocket.hpp"
32 #include "CAMutex.hpp"
33 #include "CAMsg.hpp"
34 
36 
38  {
39  public:
40  CASocket(bool bIsReserved=false);
42 
43  static SINT32 init()
44  {
45  m_pcsClose=new CAMutex();
46  return E_SUCCESS;
47  }
48 
49  static SINT32 cleanup()
50  {
51  delete m_pcsClose;
52  m_pcsClose=NULL;
53  return E_SUCCESS;
54  }
55 
56  virtual SINT32 create();
57  virtual SINT32 create(bool a_bShowTypicalError);
58  virtual SINT32 create(SINT32 type);
59 
60  virtual SINT32 listen(const CASocketAddr& psa);
61  virtual SINT32 listen(UINT16 port);
62  virtual SINT32 accept(CASocket &s);
63 
64  virtual SINT32 connect(const CASocketAddr& psa)
65  {
66  return connect(psa,1,0);
67  }
68  virtual SINT32 connect(const CASocketAddr& psa,UINT32 retry,UINT32 sWaitTime);
69  virtual SINT32 connect(const CASocketAddr& psa,UINT32 msTimeOut);
70 
71  virtual SINT32 close();
72 /* it seems that this function is not used:
73  virtual SINT32 close(UINT32 mode);*/
74  virtual SINT32 send(const UINT8* buff,UINT32 len);
75  virtual SINT32 sendFully(const UINT8* buff,UINT32 len);
76  virtual SINT32 sendFullyTimeOut(const UINT8* buff,UINT32 len, UINT32 msTimeOut, UINT32 msTimeOutSingleSend);
77  virtual SINT32 sendTimeOut(const UINT8* buff,UINT32 len,UINT32 msTimeOut);
78  virtual SINT32 receive(UINT8* buff,UINT32 len);
79  virtual SINT32 receiveFullyT(UINT8* buff,UINT32 len,UINT32 msTimeOut);
80  virtual SINT32 receiveLine(UINT8* line, UINT32 maxLen, UINT32 msTimeOut);
81  virtual SINT32 peek(UINT8* buff,UINT32 len);
88  {
89  return m_Socket;
90  }
91 
92 
93  virtual SINT32 getLocalIP(UINT8 r_Ip[4]);
94  virtual SINT32 getLocalPort();
95  virtual SINT32 getPeerIP(UINT8 ip[4]);
96  virtual SINT32 getPeerPort();
97  virtual SINT32 setReuseAddr(bool b);
98  //SINT32 setRecvLowWat(UINT32 r);
99  //SINT32 setSendLowWat(UINT32 r);
100  //SINT32 getSendLowWat();
101  virtual SINT32 setSendTimeOut(UINT32 msTimeOut);
102  virtual SINT32 getSendTimeOut();
103  virtual SINT32 setRecvBuff(UINT32 r);
104  virtual SINT32 getRecvBuff();
105  virtual SINT32 setSendBuff(SINT32 r);
106  virtual SINT32 getSendBuff();
107  virtual SINT32 setKeepAlive(bool b);
108  virtual SINT32 setKeepAlive(UINT32 sec);
109  virtual SINT32 setNonBlocking(bool b);
110  virtual SINT32 getNonBlocking(bool* b);
111 
117  {
119  return E_SUCCESS;
120  }
121 
127  static SINT32 getMaxOpenSockets();
129  {
130  return m_u32NormalSocketsOpen;
131  }
132  virtual bool isClosed()
133  {
134  return m_bSocketIsClosed;
135  }
136 
137  protected:
139 /* CASocket* getSocket()
140  {
141  return this;
142  }
143 */
145  volatile bool m_bSocketIsClosed; //this is a flag, which shows, if the m_Socket is valid
146  //we should not set m_Socket to -1 or so after close,
147  //because the Socket value ist needed sometimes even after close!!!
148  // (because it is used as a Key in lookups for instance as a HashValue etc.)
149 
151  CASingleSocketGroup *m_pSingleSocketGroupRead; //A single socke group which contains this socket for helping in reading from this socket...
152 
153 
154  private:
155 
156  virtual SINT32 setSocket(SOCKET s);
157  virtual SINT32 create(SINT32 type, bool a_bShowTypicalError);
158 
162  volatile static UINT32 m_u32NormalSocketsOpen; //how many "normal" sockets are open
163  static UINT32 m_u32MaxNormalSockets; //how many "normal" sockets are allowed at max
165  };
166 #endif
#define SOCKET
Definition: StdAfx.h:460
unsigned short UINT16
Definition: basetypedefs.h:133
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
This is an abstract class for representing a socket address used in CASocket, CADatagramSocket and CA...
CASocket(bool bIsReserved=false)
Definition: CASocket.cpp:49
virtual SINT32 receive(UINT8 *buff, UINT32 len)
Will receive some bytes from the socket.
Definition: CASocket.cpp:645
static CAMutex * m_pcsClose
Definition: CASocket.hpp:159
virtual SINT32 getPeerPort()
Definition: CASocket.cpp:830
virtual SINT32 listen(const CASocketAddr &psa)
Starts listening on address psa.
Definition: CASocket.cpp:142
virtual SINT32 send(const UINT8 *buff, UINT32 len)
Sends some data over the network.
Definition: CASocket.cpp:400
virtual SINT32 getNonBlocking(bool *b)
Definition: CASocket.cpp:972
bool m_bIsReservedSocket
Definition: CASocket.hpp:164
static SINT32 cleanup()
Definition: CASocket.hpp:49
static SINT32 init()
Definition: CASocket.hpp:43
virtual SINT32 setKeepAlive(bool b)
Enables/disables the socket keep-alive option.
Definition: CASocket.cpp:906
static UINT32 m_u32MaxNormalSockets
Definition: CASocket.hpp:163
virtual SINT32 getSendTimeOut()
Definition: CASocket.cpp:891
virtual SINT32 setSendTimeOut(UINT32 msTimeOut)
Definition: CASocket.cpp:883
virtual SINT32 setRecvBuff(UINT32 r)
Definition: CASocket.cpp:846
SOCKET getSocket()
Returns the number of the Socket used.
Definition: CASocket.hpp:87
virtual SINT32 receiveFullyT(UINT8 *buff, UINT32 len, UINT32 msTimeOut)
Trys to receive all bytes.
Definition: CASocket.cpp:677
virtual SINT32 getSendBuff()
Definition: CASocket.cpp:873
static SINT32 setMaxNormalSockets(UINT32 u)
Sets the max number of allowed "normal" sockets.
Definition: CASocket.hpp:116
virtual bool isClosed()
Definition: CASocket.hpp:132
SOCKET m_Socket
Definition: CASocket.hpp:150
static SINT32 getMaxOpenSockets()
Tries to find out how many socket we can open by open as many socket as possible witthout errors.
Definition: CASocket.cpp:983
virtual SINT32 getPeerIP(UINT8 ip[4])
Definition: CASocket.cpp:820
volatile bool m_bSocketIsClosed
check
Definition: CASocket.hpp:145
CASingleSocketGroup * m_pSingleSocketGroupRead
Definition: CASocket.hpp:151
virtual SINT32 receiveLine(UINT8 *line, UINT32 maxLen, UINT32 msTimeOut)
Definition: CASocket.cpp:714
virtual SINT32 peek(UINT8 *buff, UINT32 len)
Will peek some bytes from the socket read queue.
Definition: CASocket.cpp:770
virtual SINT32 sendTimeOut(const UINT8 *buff, UINT32 len, UINT32 msTimeOut)
Sends some data over the network.
Definition: CASocket.cpp:442
virtual SINT32 setNonBlocking(bool b)
Definition: CASocket.cpp:947
virtual SINT32 setReuseAddr(bool b)
Definition: CASocket.cpp:839
virtual SINT32 sendFully(const UINT8 *buff, UINT32 len)
Sends all data over the network.
Definition: CASocket.cpp:587
virtual SINT32 setSendBuff(SINT32 r)
Returns < 0 on error, otherwise the new sendbuffersize (which may be less than r)
Definition: CASocket.cpp:862
virtual SINT32 accept(CASocket &s)
Accepts a new connection.
Definition: CASocket.cpp:192
virtual SINT32 getRecvBuff()
Definition: CASocket.cpp:852
virtual SINT32 sendFullyTimeOut(const UINT8 *buff, UINT32 len, UINT32 msTimeOut, UINT32 msTimeOutSingleSend)
Sends all data over the network.
Definition: CASocket.cpp:488
virtual SINT32 setSocket(SOCKET s)
Definition: CASocket.cpp:57
virtual SINT32 create()
Definition: CASocket.cpp:73
virtual SINT32 getLocalIP(UINT8 r_Ip[4])
LERNGRUPPE Returns the source address of the socket.
Definition: CASocket.cpp:801
static UINT32 countOpenSockets()
Definition: CASocket.hpp:128
virtual SINT32 close()
Definition: CASocket.cpp:351
virtual SINT32 connect(const CASocketAddr &psa)
Definition: CASocket.hpp:64
~CASocket()
Definition: CASocket.hpp:41
virtual SINT32 getLocalPort()
Definition: CASocket.cpp:811
static volatile UINT32 m_u32NormalSocketsOpen
The following two variables are use to realise "reserved" sockets.
Definition: CASocket.hpp:162
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
UINT8 type
Definition: typedefs.hpp:1
UINT16 len
Definition: typedefs.hpp:0