Mixe for Privacy and Anonymity in the Internet
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
CASocket Class Reference

#include <CASocket.hpp>

Inheritance diagram for CASocket:
Collaboration diagram for CASocket:

Public Member Functions

 CASocket (bool bIsReserved=false)
 
 ~CASocket ()
 
virtual SINT32 create ()
 
virtual SINT32 create (bool a_bShowTypicalError)
 
virtual SINT32 create (SINT32 type)
 
virtual SINT32 listen (const CASocketAddr &psa)
 Starts listening on address psa. More...
 
virtual SINT32 listen (UINT16 port)
 
virtual SINT32 accept (CASocket &s)
 Accepts a new connection. More...
 
virtual SINT32 connect (const CASocketAddr &psa)
 
virtual SINT32 connect (const CASocketAddr &psa, UINT32 retry, UINT32 sWaitTime)
 Tries to connect to the peer described by psa. More...
 
virtual SINT32 connect (const CASocketAddr &psa, UINT32 msTimeOut)
 Tries to connect to peer psa. More...
 
virtual SINT32 close ()
 
virtual SINT32 send (const UINT8 *buff, UINT32 len)
 Sends some data over the network. More...
 
virtual SINT32 sendFully (const UINT8 *buff, UINT32 len)
 Sends all data over the network. More...
 
virtual SINT32 sendFullyTimeOut (const UINT8 *buff, UINT32 len, UINT32 msTimeOut, UINT32 msTimeOutSingleSend)
 Sends all data over the network. More...
 
virtual SINT32 sendTimeOut (const UINT8 *buff, UINT32 len, UINT32 msTimeOut)
 Sends some data over the network. More...
 
virtual SINT32 receive (UINT8 *buff, UINT32 len)
 Will receive some bytes from the socket. More...
 
virtual SINT32 receiveFullyT (UINT8 *buff, UINT32 len, UINT32 msTimeOut)
 Trys to receive all bytes. More...
 
virtual SINT32 receiveLine (UINT8 *line, UINT32 maxLen, UINT32 msTimeOut)
 
virtual SINT32 peek (UINT8 *buff, UINT32 len)
 Will peek some bytes from the socket read queue. More...
 
SOCKET getSocket ()
 Returns the number of the Socket used. More...
 
virtual SINT32 getLocalIP (UINT8 r_Ip[4])
 LERNGRUPPE Returns the source address of the socket. More...
 
virtual SINT32 getLocalPort ()
 
virtual SINT32 getPeerIP (UINT8 ip[4])
 
virtual SINT32 getPeerPort ()
 
virtual SINT32 setReuseAddr (bool b)
 
virtual SINT32 setSendTimeOut (UINT32 msTimeOut)
 
virtual SINT32 getSendTimeOut ()
 
virtual SINT32 setRecvBuff (UINT32 r)
 
virtual SINT32 getRecvBuff ()
 
virtual SINT32 setSendBuff (SINT32 r)
 Returns < 0 on error, otherwise the new sendbuffersize (which may be less than r) More...
 
virtual SINT32 getSendBuff ()
 
virtual SINT32 setKeepAlive (bool b)
 Enables/disables the socket keep-alive option. More...
 
virtual SINT32 setKeepAlive (UINT32 sec)
 Enables the socket keep-alive option with a given ping time (in seconds). More...
 
virtual SINT32 setNonBlocking (bool b)
 
virtual SINT32 getNonBlocking (bool *b)
 
virtual bool isClosed ()
 
- Public Member Functions inherited from CAClientSocket
virtual ~CAClientSocket ()
 
SINT32 receiveFully (UINT8 *buff, UINT32 len)
 Receives all len bytes. More...
 

Static Public Member Functions

static SINT32 init ()
 
static SINT32 cleanup ()
 
static SINT32 setMaxNormalSockets (UINT32 u)
 Sets the max number of allowed "normal" sockets. More...
 
static SINT32 getMaxOpenSockets ()
 Tries to find out how many socket we can open by open as many socket as possible witthout errors. More...
 
static UINT32 countOpenSockets ()
 

Protected Attributes

volatile bool m_bSocketIsClosed
 check More...
 
SOCKET m_Socket
 
CASingleSocketGroupm_pSingleSocketGroupRead
 

Private Member Functions

virtual SINT32 setSocket (SOCKET s)
 
virtual SINT32 create (SINT32 type, bool a_bShowTypicalError)
 

Private Attributes

bool m_bIsReservedSocket
 

Static Private Attributes

static CAMutexm_pcsClose =NULL
 
static volatile UINT32 m_u32NormalSocketsOpen =0
 The following two variables are use to realise "reserved" sockets. More...
 
static UINT32 m_u32MaxNormalSockets =0xFFFFFFFF
 

Detailed Description

Definition at line 37 of file CASocket.hpp.

Constructor & Destructor Documentation

◆ CASocket()

CASocket::CASocket ( bool  bIsReserved = false)

Definition at line 49 of file CASocket.cpp.

50  {
51  m_Socket=0;
52  m_bSocketIsClosed=true;
53  m_bIsReservedSocket=bIsReservedSocket;
55  }
bool m_bIsReservedSocket
Definition: CASocket.hpp:164
SOCKET m_Socket
Definition: CASocket.hpp:150
volatile bool m_bSocketIsClosed
check
Definition: CASocket.hpp:145
CASingleSocketGroup * m_pSingleSocketGroupRead
Definition: CASocket.hpp:151

References m_bIsReservedSocket, m_bSocketIsClosed, m_pSingleSocketGroupRead, and m_Socket.

◆ ~CASocket()

CASocket::~CASocket ( )
inline

Definition at line 41 of file CASocket.hpp.

41 {close();}
virtual SINT32 close()
Definition: CASocket.cpp:351

References close().

Here is the call graph for this function:

Member Function Documentation

◆ accept()

SINT32 CASocket::accept ( CASocket s)
virtual

Accepts a new connection.

The new socket is returned in s.

Return values
E_SUCCESSif successful
E_SOCKETCLOSEDif the listening socket was closed
E_SOCKET_LIMITif the could not create a new socket for the new connection
E_UNKNOWNotherwise

Definition at line 192 of file CASocket.cpp.

193  {
194  if(m_bSocketIsClosed) //the accept socket should not be closed!!
195  return E_SOCKETCLOSED;
196  if(!s.m_bSocketIsClosed) //but the new socket should be closed!!!
197  return E_UNKNOWN;
199  {
200  CAMsg::printMsg(LOG_CRIT,"CASocket::accept() -- Could not create a new normal Socket -- allowed number of normal sockets exeded!\n");
201  return E_SOCKET_LIMIT;
202  }
203  SOCKET sock=::accept(m_Socket,NULL,NULL);
204  if (sock == SOCKET_ERROR)
205  {
206  s.setSocket(0);
208  return E_SOCKETCLOSED;
209  return E_UNKNOWN;
210  }
211  s.setSocket(sock);
212  m_pcsClose->lock();
214  s.m_bSocketIsClosed=false;
215  m_pcsClose->unlock();
216  //CAMsg::printMsg(LOG_DEBUG,"Opened socket: %d\n", s.m_Socket);
217 
218  return E_SUCCESS;
219  }
#define GET_NET_ERROR
Definition: StdAfx.h:469
#define SOCKET_ERROR
Definition: StdAfx.h:464
#define ERR_INTERN_SOCKET_CLOSED
Definition: StdAfx.h:477
#define SOCKET
Definition: StdAfx.h:460
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
static CAMutex * m_pcsClose
Definition: CASocket.hpp:159
static UINT32 m_u32MaxNormalSockets
Definition: CASocket.hpp:163
virtual SINT32 accept(CASocket &s)
Accepts a new connection.
Definition: CASocket.cpp:192
virtual SINT32 setSocket(SOCKET s)
Definition: CASocket.cpp:57
static volatile UINT32 m_u32NormalSocketsOpen
The following two variables are use to realise "reserved" sockets.
Definition: CASocket.hpp:162
#define E_SOCKETCLOSED
Definition: errorcodes.hpp:11
#define E_SOCKET_LIMIT
Definition: errorcodes.hpp:16
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_UNKNOWN
Definition: errorcodes.hpp:3

References E_SOCKET_LIMIT, E_SOCKETCLOSED, E_SUCCESS, E_UNKNOWN, ERR_INTERN_SOCKET_CLOSED, GET_NET_ERROR, CAMutex::lock(), m_bSocketIsClosed, m_pcsClose, m_Socket, m_u32MaxNormalSockets, m_u32NormalSocketsOpen, CAMsg::printMsg(), setSocket(), SOCKET, SOCKET_ERROR, and CAMutex::unlock().

Referenced by CAMuxSocket::accept(), and CALocalProxy::loop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanup()

static SINT32 CASocket::cleanup ( )
inlinestatic

Definition at line 49 of file CASocket.hpp.

50  {
51  delete m_pcsClose;
52  m_pcsClose=NULL;
53  return E_SUCCESS;
54  }

References E_SUCCESS, and m_pcsClose.

Referenced by CALibProxytest::cleanup().

Here is the caller graph for this function:

◆ close()

SINT32 CASocket::close ( )
virtual

Reimplemented in CATLSClientSocket.

Definition at line 351 of file CASocket.cpp.

352  {
353  SINT32 ret;
354 
356  {
357  return E_SUCCESS;
358  }
359 
360  ret = m_pcsClose->lock();
361  if (ret != E_SUCCESS)
362  {
363  CAMsg::printMsg(LOG_CRIT,
364  "Could not get lock for closing socket! Error code: %d\n", ret);
365  return ret;
366  }
367 
368  if (!m_bSocketIsClosed)
369  {
370  shutdown(m_Socket,SHUT_RDWR); //call shutdown here because some OSes seems to ned it to
371  //wakeup other threads which block in read() or write()
372  ret=::closesocket(m_Socket);
374  {
376  }
377  //CAMsg::printMsg(LOG_DEBUG,"Open Sockets: %d\n", m_u32NormalSocketsOpen);
378  //CAMsg::printMsg(LOG_DEBUG,"Closed socket: %d\n", m_Socket);
379  setSocket(0);
380  m_bSocketIsClosed=true;
381  }
382 
383  if (ret != E_SUCCESS)
384  {
385  ret = GET_NET_ERROR;
386  }
387 
388  m_pcsClose->unlock();
389  return ret;
390  }
#define closesocket(s)
Definition: StdAfx.h:463
signed int SINT32
Definition: basetypedefs.h:132

References closesocket, E_SUCCESS, GET_NET_ERROR, CAMutex::lock(), m_bIsReservedSocket, m_bSocketIsClosed, m_pcsClose, m_Socket, m_u32NormalSocketsOpen, CAMsg::printMsg(), setSocket(), and CAMutex::unlock().

Referenced by CAMuxSocket::accept(), CAFirstMix::clean(), CALastMix::clean(), CALocalProxy::clean(), CAMuxSocket::close(), CATLSClientSocket::close(), CAChain::closeChainInternal(), connect(), CATLSClientSocket::connect(), getMaxOpenSockets(), CAInfoService::getPaymentInstance(), listen(), CALocalProxy::loop(), CALastMixA::loop(), CALastMixB::loop(), CAInfoService::sendCascadeHelo(), CAInfoService::sendMixHelo(), CAInfoService::sendStatus(), CACmdLnOptions::setListenerInterfaces(), CACmdLnOptions::setTargetInterfaces(), CAChain::~CAChain(), and ~CASocket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect() [1/3]

virtual SINT32 CASocket::connect ( const CASocketAddr psa)
inlinevirtual

Definition at line 64 of file CASocket.hpp.

65  {
66  return connect(psa,1,0);
67  }
virtual SINT32 connect(const CASocketAddr &psa)
Definition: CASocket.hpp:64

Referenced by CAMuxSocket::connect(), CATLSClientSocket::connect(), connect(), CAInfoService::getPaymentInstance(), CALastMixA::loop(), CALastMixB::loop(), CAInfoService::sendCascadeHelo(), CAInfoService::sendMixHelo(), CAInfoService::sendStatus(), and CACmdLnOptions::setTargetInterfaces().

Here is the caller graph for this function:

◆ connect() [2/3]

SINT32 CASocket::connect ( const CASocketAddr psa,
UINT32  msTimeOut 
)
virtual

Tries to connect to peer psa.

Parameters
psa- peer
msTimeOut- abort after msTimeOut milli seconds

Reimplemented in CATLSClientSocket.

Definition at line 270 of file CASocket.cpp.

271  {
273  {
274  return E_UNKNOWN;
275  }
276 #ifdef _DEBUG
277  sockets++;
278 #endif
279  bool bWasNonBlocking=false;
280  getNonBlocking(&bWasNonBlocking);
281  setNonBlocking(true);
282  int err=0;
283  const LPSOCKADDR addr=(const LPSOCKADDR)psa.LPSOCKADDR();
284  int addr_len=psa.getSize();
285 
286  err=::connect(m_Socket,addr,addr_len);
287  if(err==0)
288  return E_SUCCESS;
289  err=GET_NET_ERROR;
290 #ifdef _WIN32
291  if(err!=WSAEWOULDBLOCK)
292  return E_SOCKET_CONNECT;
293 #else
294  if(err!=EINPROGRESS)
295  {
296  return E_SOCKET_CONNECT;
297  }
298 #endif
299 
300 #ifndef HAVE_POLL
301  struct timeval tval;
302  tval.tv_sec=msTimeOut/1000;
303  tval.tv_usec=(msTimeOut%1000)*1000;
304  fd_set readSet,writeSet;
305  FD_ZERO(&readSet);
306  FD_ZERO(&writeSet);
307  #pragma warning( push )
308  #pragma warning( disable : 4127 ) //Disable: Bedingter Ausdruck ist konstant
309  FD_SET(m_Socket,&readSet);
310  FD_SET(m_Socket,&writeSet);
311  #pragma warning( pop )
312  err=::select(m_Socket+1,&readSet,&writeSet,NULL,&tval);
313 #else
314  struct pollfd opollfd;
315  opollfd.fd=m_Socket;
316  opollfd.events=POLLIN|POLLOUT;
317  err=::poll(&opollfd,1,msTimeOut);
318 #endif
319  if (err<1) //timeout or error Note: we do not check for !=1 here because for some strange reasons FreeBSD 8.0-rc2 returns: 2 - Why?
320  {
321  err = GET_NET_ERROR;
322  close();
323  SET_NET_ERROR(err);
324 
325  if (GET_NET_ERROR == EINPROGRESS)
326  {
327  return E_UNKNOWN;
328  }
329 
330  return E_SOCKET_CONNECT;
331  }
332  socklen_t len=sizeof(err);
333  err=0;
334  if (::getsockopt(m_Socket,SOL_SOCKET,SO_ERROR,(char*)&err,&len)<0||err!=0) //error by connect
335  {
336  err = GET_NET_ERROR;
337  close();
338  SET_NET_ERROR(err);
339 
340  if (GET_NET_ERROR == EINPROGRESS)
341  {
342  return E_UNKNOWN;
343  }
344 
345  return E_SOCKET_CONNECT;
346  }
347  setNonBlocking(bWasNonBlocking);
348  return E_SUCCESS;
349  }
SOCKADDR * LPSOCKADDR
Definition: StdAfx.h:459
int socklen_t
Definition: StdAfx.h:393
#define SET_NET_ERROR(x)
Definition: StdAfx.h:470
virtual SINT32 getType() const =0
The type (family) of socket for which this address is useful.
virtual const SOCKADDR * LPSOCKADDR() const =0
Casts to a SOCKADDR struct.
virtual SINT32 getSize() const =0
The size of the SOCKADDR struct needed by function of CASocket and other.
virtual SINT32 getNonBlocking(bool *b)
Definition: CASocket.cpp:972
virtual SINT32 setNonBlocking(bool b)
Definition: CASocket.cpp:947
virtual SINT32 create()
Definition: CASocket.cpp:73
#define E_SOCKET_CONNECT
Definition: errorcodes.hpp:17
UINT16 len
Definition: typedefs.hpp:0

References close(), connect(), create(), E_SOCKET_CONNECT, E_SUCCESS, E_UNKNOWN, GET_NET_ERROR, getNonBlocking(), CASocketAddr::getSize(), CASocketAddr::getType(), len, CASocketAddr::LPSOCKADDR(), m_bSocketIsClosed, m_Socket, SET_NET_ERROR, and setNonBlocking().

Here is the call graph for this function:

◆ connect() [3/3]

SINT32 CASocket::connect ( const CASocketAddr psa,
UINT32  retry,
UINT32  time 
)
virtual

Tries to connect to the peer described by psa.

Parameters
psa- peer
retry- number of retries
time- time between retries in seconds

Definition at line 227 of file CASocket.cpp.

228  {
229 // CAMsg::printMsg(LOG_DEBUG,"Socket:connect\n");
231  {
232  return E_UNKNOWN;
233  }
234 #ifdef _DEBUG
235  sockets++;
236 #endif
237  int err=0;
238  const SOCKADDR* addr=psa.LPSOCKADDR();
239  int addr_len=psa.getSize();
240  for(UINT32 i=0;i<retry;i++)
241  {
242 // CAMsg::printMsg(LOG_DEBUG,"Socket:connect-connect\n");
243  err=::connect(m_Socket,addr,addr_len);
244 // CAMsg::printMsg(LOG_DEBUG,"Socket:connect-connect-finished err: %i\n",err);
245  if(err!=0)
246  {
247  err=GET_NET_ERROR;
248  #ifdef _DEBUG
249  CAMsg::printMsg(LOG_DEBUG,"Con-Error: %i\n",err);
250  #endif
252  return E_UNKNOWN; //Should be better.....
253  #ifdef _DEBUG
254  CAMsg::printMsg(LOG_DEBUG,"Cannot connect... retrying\n");
255  #endif
256  sSleep((UINT16)time);
257  }
258  else
259  return E_SUCCESS;
260  }
261  return err;
262  }
SINT32 sSleep(UINT32 sec)
Sleeps sec Seconds.
Definition: CAUtil.cpp:425
#define ERR_INTERN_CONNREFUSED
Definition: StdAfx.h:475
#define ERR_INTERN_TIMEDOUT
Definition: StdAfx.h:474
struct sockaddr SOCKADDR
Definition: StdAfx.h:458
unsigned short UINT16
Definition: basetypedefs.h:133
unsigned int UINT32
Definition: basetypedefs.h:131

References connect(), create(), E_SUCCESS, E_UNKNOWN, ERR_INTERN_CONNREFUSED, ERR_INTERN_TIMEDOUT, GET_NET_ERROR, CASocketAddr::getSize(), CASocketAddr::LPSOCKADDR(), m_bSocketIsClosed, m_Socket, CAMsg::printMsg(), and sSleep().

Here is the call graph for this function:

◆ countOpenSockets()

static UINT32 CASocket::countOpenSockets ( )
inlinestatic

Definition at line 128 of file CASocket.hpp.

129  {
130  return m_u32NormalSocketsOpen;
131  }

References m_u32NormalSocketsOpen.

◆ create() [1/4]

SINT32 CASocket::create ( )
virtual

Definition at line 73 of file CASocket.cpp.

74  {
75  return create(AF_INET, true);
76  }

Referenced by CAMuxSocket::accept(), connect(), create(), CACmdLnOptions::createSockets(), getMaxOpenSockets(), CAFirstMix::init(), CALocalProxy::init(), CAMiddleMix::init(), listen(), CALastMixA::loop(), CALastMixB::loop(), CACmdLnOptions::parse(), and CAFirstMixChannelList::test().

Here is the caller graph for this function:

◆ create() [2/4]

SINT32 CASocket::create ( bool  a_bShowTypicalError)
virtual

Definition at line 83 of file CASocket.cpp.

84 {
85  return create(AF_INET, a_bShowTypicalError);
86 }

References create().

Here is the call graph for this function:

◆ create() [3/4]

SINT32 CASocket::create ( SINT32  type)
virtual

Definition at line 78 of file CASocket.cpp.

79 {
80  return create(type, true);
81 }
UINT8 type
Definition: typedefs.hpp:1

References create(), and type.

Here is the call graph for this function:

◆ create() [4/4]

SINT32 CASocket::create ( SINT32  type,
bool  a_bShowTypicalError 
)
privatevirtual
Todo:
Not thread safe!

Definition at line 89 of file CASocket.cpp.

90  {
93  {
95  {
96  s=::socket(type,SOCK_STREAM,0);
97  //CAMsg::printMsg(LOG_DEBUG,"Opened socket: %d\n", m_Socket);
98  }
99  else
100  {
101  CAMsg::printMsg(LOG_CRIT,"Could not create a new normal Socket -- allowed number of normal sockets exceeded!\n");
102  return E_SOCKET_LIMIT;
103  }
104  }
105  else
106  return E_UNKNOWN;
107  if(s==INVALID_SOCKET)
108  {
109  setSocket(0);
110  int er=GET_NET_ERROR;
111  if (a_bShowTypicalError)
112  {
113  if(er==EMFILE)
114  {
115  CAMsg::printMsg(LOG_CRIT,"Could not create a new Socket!\n");
116  }
117  else
118  {
119  CAMsg::printMsg(LOG_CRIT,"Could not create a new Socket! - Error: %s (%i)\n",
120  GET_NET_ERROR_STR(er), er);
121  }
122  }
123  return E_SOCKET_CREATE;
124  }
125  m_bSocketIsClosed=false;
126  m_pcsClose->lock();
128  {
130  }
131  m_pcsClose->unlock();
132  setSocket(s);
133  return E_SUCCESS;
134  }
#define INVALID_SOCKET
Definition: StdAfx.h:465
#define GET_NET_ERROR_STR(x)
Definition: StdAfx.h:471
#define E_SOCKET_CREATE
Definition: errorcodes.hpp:12

References E_SOCKET_CREATE, E_SOCKET_LIMIT, E_SUCCESS, E_UNKNOWN, GET_NET_ERROR, GET_NET_ERROR_STR, INVALID_SOCKET, CAMutex::lock(), m_bIsReservedSocket, m_bSocketIsClosed, m_pcsClose, m_u32MaxNormalSockets, m_u32NormalSocketsOpen, CAMsg::printMsg(), setSocket(), SOCKET, type, and CAMutex::unlock().

Here is the call graph for this function:

◆ getLocalIP()

SINT32 CASocket::getLocalIP ( UINT8  r_Ip[4])
virtual

LERNGRUPPE Returns the source address of the socket.

Returns
r_Ip the source IP address
Return values
E_SUCCESSupon success
SOCKET_ERRORotherwise
Todo:
: Question: Correct for Unix domain sockets?

Definition at line 801 of file CASocket.cpp.

802 {
803  struct sockaddr_in addr;
804  socklen_t namelen=sizeof(struct sockaddr_in);
805  if(getsockname(m_Socket,(struct sockaddr*)&addr,&namelen)==SOCKET_ERROR)
806  return SOCKET_ERROR;
807  memcpy(r_Ip,&addr.sin_addr,4);
808  return E_SUCCESS;
809 }

References E_SUCCESS, m_Socket, and SOCKET_ERROR.

Referenced by CALastMixA::loop().

Here is the caller graph for this function:

◆ getLocalPort()

SINT32 CASocket::getLocalPort ( )
virtual

Definition at line 811 of file CASocket.cpp.

812  {
813  struct sockaddr_in addr;
814  socklen_t namelen=sizeof(struct sockaddr_in);
815  if(getsockname(m_Socket,(struct sockaddr*)&addr,&namelen)==SOCKET_ERROR)
816  return SOCKET_ERROR;
817  return ntohs(addr.sin_port);
818  }

References m_Socket, and SOCKET_ERROR.

Referenced by CALocalProxy::loop(), and CALastMixA::loop().

Here is the caller graph for this function:

◆ getMaxOpenSockets()

SINT32 CASocket::getMaxOpenSockets ( )
static

Tries to find out how many socket we can open by open as many socket as possible witthout errors.

If we can open more than 10.000 sockets we stop the test and return 10000.

Return values
maxnumbers of sockets we can have open at the same time
E_UNKNOWNin case of some unexpected error

Definition at line 983 of file CASocket.cpp.

984 {
985  CASocket* parSocket=new CASocket[10001];
986  UINT32 maxSocket=0;
987  for(UINT32 t=0;t<10001;t++)
988  {
989  if(parSocket[t].create(false)!=E_SUCCESS)
990  {
991  maxSocket=t;
992  break;
993  }
994  }
995  for(UINT32 t=0;t<maxSocket;t++)
996  {
997  parSocket[t].close();
998  }
999  delete []parSocket;
1000  parSocket = NULL;
1001  return maxSocket;
1002 }

References close(), create(), and E_SUCCESS.

Here is the call graph for this function:

◆ getNonBlocking()

SINT32 CASocket::getNonBlocking ( bool *  b)
virtual

Definition at line 972 of file CASocket.cpp.

973  {
974  #ifndef _WIN32
975  int flags=fcntl(m_Socket,F_GETFL,0);
976  *b=((flags&O_NONBLOCK)==O_NONBLOCK);
977  return E_SUCCESS;
978  #else
979  return SOCKET_ERROR;
980  #endif
981  }
UINT16 flags
Definition: typedefs.hpp:1

References E_SUCCESS, flags, m_Socket, and SOCKET_ERROR.

Referenced by connect(), CAHttpClient::parseHTTPHeader(), sendFullyTimeOut(), and sendTimeOut().

Here is the caller graph for this function:

◆ getPeerIP()

SINT32 CASocket::getPeerIP ( UINT8  ip[4])
virtual

Definition at line 820 of file CASocket.cpp.

821  {
822  struct sockaddr_in addr;
823  socklen_t namelen=sizeof(struct sockaddr_in);
824  if(getpeername(m_Socket,(struct sockaddr*)&addr,&namelen)==SOCKET_ERROR)
825  return SOCKET_ERROR;
826  memcpy(ip,&addr.sin_addr,4);
827  return E_SUCCESS;
828  }

References E_SUCCESS, m_Socket, and SOCKET_ERROR.

Referenced by isAllowedToPassRestrictions().

Here is the caller graph for this function:

◆ getPeerPort()

SINT32 CASocket::getPeerPort ( )
virtual

Definition at line 830 of file CASocket.cpp.

831  {
832  struct sockaddr_in addr;
833  socklen_t namelen=sizeof(struct sockaddr_in);
834  if(getpeername(m_Socket,(struct sockaddr*)&addr,&namelen)==SOCKET_ERROR)
835  return SOCKET_ERROR;
836  return ntohs(addr.sin_port);
837  }

References m_Socket, and SOCKET_ERROR.

Referenced by CAFirstMixChannelList::add().

Here is the caller graph for this function:

◆ getRecvBuff()

SINT32 CASocket::getRecvBuff ( )
virtual

Definition at line 852 of file CASocket.cpp.

853  {
854  int val;
855  socklen_t size=sizeof(val);
856  if(getsockopt(m_Socket,SOL_SOCKET,SO_RCVBUF,(char*)&val,&size)==SOCKET_ERROR)
857  return E_UNKNOWN;
858  else
859  return val;
860  }

References E_UNKNOWN, m_Socket, and SOCKET_ERROR.

Referenced by CAFirstMix::init().

Here is the caller graph for this function:

◆ getSendBuff()

SINT32 CASocket::getSendBuff ( )
virtual

Definition at line 873 of file CASocket.cpp.

874  {
875  SINT32 val;
876  socklen_t size=sizeof(val);
877  if(getsockopt(m_Socket,SOL_SOCKET,SO_SNDBUF,(char*)&val,&size)==SOCKET_ERROR)
878  return E_UNKNOWN;
879  else
880  return val;
881  }

References E_UNKNOWN, m_Socket, and SOCKET_ERROR.

Referenced by CAFirstMix::init(), and setSendBuff().

Here is the caller graph for this function:

◆ getSendTimeOut()

SINT32 CASocket::getSendTimeOut ( )
virtual

Definition at line 891 of file CASocket.cpp.

892  {
893  timeval val;
894  socklen_t size=sizeof(val);
895  if(getsockopt(m_Socket,SOL_SOCKET,SO_SNDTIMEO,(char*)&val,&size)==SOCKET_ERROR)
896  return E_UNKNOWN;
897  else
898  return val.tv_sec*1000+val.tv_usec/1000;
899  }

References E_UNKNOWN, m_Socket, and SOCKET_ERROR.

Referenced by sendFullyTimeOut(), and sendTimeOut().

Here is the caller graph for this function:

◆ getSocket()

SOCKET CASocket::getSocket ( )
inlinevirtual

Returns the number of the Socket used.

Which will be always the same number, even after close(), until the Socket is recreated using create()

Returns
number of the associated socket

Implements CAClientSocket.

Definition at line 87 of file CASocket.hpp.

88  {
89  return m_Socket;
90  }

References m_Socket.

Referenced by CASocketGroup::add(), CASocketGroupEpoll::add(), CAMuxSocket::getSocket(), CASocketGroup::isSignaled(), CASocketGroupEpoll::isSignaled(), CASocketGroup::remove(), CASocketGroupEpoll::remove(), and CASingleSocketGroup::select_once().

Here is the caller graph for this function:

◆ init()

static SINT32 CASocket::init ( )
inlinestatic

Definition at line 43 of file CASocket.hpp.

44  {
45  m_pcsClose=new CAMutex();
46  return E_SUCCESS;
47  }

References E_SUCCESS, and m_pcsClose.

Referenced by CALibProxytest::init().

Here is the caller graph for this function:

◆ isClosed()

virtual bool CASocket::isClosed ( )
inlinevirtual

Definition at line 132 of file CASocket.hpp.

133  {
134  return m_bSocketIsClosed;
135  }

References m_bSocketIsClosed.

Referenced by CAFirstMix::doUserLogin_internal(), and CAMuxSocket::receive().

Here is the caller graph for this function:

◆ listen() [1/2]

SINT32 CASocket::listen ( const CASocketAddr psa)
virtual

Starts listening on address psa.

Return values
E_SUCCESS,ifsuccessful
E_SOCKET_LISTEN,ifcall to listen() returns an error
E_SOCKET_BIND,ifcall to bind() returns an error
E_UNKNOWN,otherwise

Definition at line 142 of file CASocket.cpp.

143  {
144  UINT32 iError;
145  SINT32 type=psa.getType();
147  return E_UNKNOWN;
148 #ifdef HAVE_UNIX_DOMAIN_PROTOCOL
149  //we have to delete the file before...
150  if(psa.getType()==AF_LOCAL)
151  {
152  UINT8* path=((CASocketAddrUnix&)psa).getPath();
153  if(path!=NULL)
154  {
155  SINT32 ret=::unlink((char*)path);
156  if(ret!=0)
157  CAMsg::printMsg(LOG_ERR,"CASocket::listen() -- could not unlink unix domain socket file name %s -- a call to bind or listen may fail...\n",path);
158  delete[] path;
159  path = NULL;
160  }
161  }
162 #endif
163  if(::bind(m_Socket,psa.LPSOCKADDR(),psa.getSize())==SOCKET_ERROR)
164  {
165  iError = GET_NET_ERROR;
166  close();
167  SET_NET_ERROR(iError);
168  return E_SOCKET_BIND;
169  }
170  if(::listen(m_Socket,SOMAXCONN)==SOCKET_ERROR)
171  {
172  iError = GET_NET_ERROR;
173  close();
174  SET_NET_ERROR(iError);
175  return E_SOCKET_LISTEN;
176  }
177  return E_SUCCESS;
178  }
#define AF_LOCAL
Definition: StdAfx.h:482
unsigned char UINT8
Definition: basetypedefs.h:135
This is a class for Unix Domain Protocol Sockat Addresses.
virtual SINT32 listen(const CASocketAddr &psa)
Starts listening on address psa.
Definition: CASocket.cpp:142
#define E_SOCKET_LISTEN
Definition: errorcodes.hpp:13
#define E_SOCKET_BIND
Definition: errorcodes.hpp:15

References AF_LOCAL, close(), create(), E_SOCKET_BIND, E_SOCKET_LISTEN, E_SUCCESS, E_UNKNOWN, GET_NET_ERROR, CASocketAddr::getSize(), CASocketAddr::getType(), CASocketAddr::LPSOCKADDR(), m_bSocketIsClosed, m_Socket, CAMsg::printMsg(), SET_NET_ERROR, SOCKET_ERROR, and type.

Referenced by CAMuxSocket::accept(), CACmdLnOptions::createSockets(), CALocalProxy::init(), and listen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ listen() [2/2]

SINT32 CASocket::listen ( UINT16  port)
virtual

Definition at line 180 of file CASocket.cpp.

181  {
182  CASocketAddrINet oSocketAddrINet(port);
183  return listen(oSocketAddrINet);
184  }
This class represents a socket address for Internet (IP) connections.

References listen().

Here is the call graph for this function:

◆ peek()

SINT32 CASocket::peek ( UINT8 buff,
UINT32  len 
)
virtual

Will peek some bytes from the socket read queue.

May block or not depending on whatever this socket was set to blocking or non-blocking mode. Warning: If socket is in blocking mode and peek() is called, peek() will block until some data is available, EVEN IF AN OTHER THREAD WILL CLOSE THIS SOCKET!

Parameters
buffthe buffer which get the peeked data
lensize of buff
Returns
SOCKET_ERROR if an error occured
Return values
E_AGAIN,ifsocket was in non-blocking mode and receive would block or a timeout was reached
0if socket was gracefully closed
Returns
the number of bytes received (always >0)

Definition at line 770 of file CASocket.cpp.

771  {
772  int ret;
773  int ef=0;
774  do
775  {
776  ret=::recv(m_Socket,(char*)buff,len,MSG_NOSIGNAL|MSG_PEEK);
777  }
778  while(ret==SOCKET_ERROR&&(ef=GET_NET_ERROR)==EINTR);
779  if(ret==SOCKET_ERROR)
780  {
781  if(ef==ERR_INTERN_WOULDBLOCK)
782  return E_AGAIN;
783  }
784 #ifdef _DEBUG
785  if(ret==SOCKET_ERROR)
786  CAMsg::printMsg(LOG_DEBUG,"CASocket peek() error %d (%s)\n",ef,GET_NET_ERROR_STR(ef));
787 #endif
788  return ret;
789  }
#define ERR_INTERN_WOULDBLOCK
Definition: StdAfx.h:476
#define MSG_NOSIGNAL
Definition: StdAfx.h:408
#define E_AGAIN
Definition: errorcodes.hpp:9

References E_AGAIN, ERR_INTERN_WOULDBLOCK, GET_NET_ERROR, GET_NET_ERROR_STR, len, m_Socket, MSG_NOSIGNAL, CAMsg::printMsg(), and SOCKET_ERROR.

Here is the call graph for this function:

◆ receive()

SINT32 CASocket::receive ( UINT8 buff,
UINT32  len 
)
virtual

Will receive some bytes from the socket.

May block or not depending on whatever this socket was set to blocking or non-blocking mode. Warning: If socket is in blocking mode and receive is called, receive will block until some data is available, EVEN IF AN OTHER THREAD WILL CLOSE THIS SOCKET!

Parameters
buffthe buffer which get the received data
lensize of buff
Returns
SOCKET_ERROR if an error occured
Return values
E_AGAIN,ifsocket was in non-blocking mode and receive would block or a timeout was reached
0if socket was gracefully closed
Returns
the number of bytes received (always >0)

Implements CAClientSocket.

Reimplemented in CATLSClientSocket.

Definition at line 645 of file CASocket.cpp.

646  {
647  int ret;
648  int ef=0;
649  do
650  {
651  ret=::recv(m_Socket,(char*)buff,len,MSG_NOSIGNAL);
652  }
653  while(ret==SOCKET_ERROR&&(ef=GET_NET_ERROR)==EINTR);
654  if(ret==SOCKET_ERROR)
655  {
656  if(ef==ERR_INTERN_WOULDBLOCK)
657  return E_AGAIN;
658  }
659 #ifdef _DEBUG
660  if(ret==SOCKET_ERROR)
661  CAMsg::printMsg(LOG_DEBUG,"CASocket Receive error %d (%s)\n",ef,GET_NET_ERROR_STR(ef));
662 #endif
663  return ret;
664  }

References E_AGAIN, ERR_INTERN_WOULDBLOCK, GET_NET_ERROR, GET_NET_ERROR_STR, len, m_Socket, MSG_NOSIGNAL, CAMsg::printMsg(), and SOCKET_ERROR.

Referenced by CAHttpClient::getContent(), CALocalProxy::loop(), CALastMixA::loop(), CAHttpClient::parseHTTPHeader(), CAChain::processDownstream(), CAMuxSocket::receive(), receiveFullyT(), and receiveLine().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ receiveFullyT()

SINT32 CASocket::receiveFullyT ( UINT8 buff,
UINT32  len,
UINT32  msTimeOut 
)
virtual

Trys to receive all bytes.

If after the timeout value has elapsed, not all bytes are received the error E_TIMEDOUT is returned.

Parameters
buffbyte array, where the received bytes would be stored
lenon input holds the number of bytes which should be read,
msTimeOutthe timout in milli seconds
Return values
E_TIMEDOUTif not all byts could be read
E_UNKNOWNif an error occured
E_SUCCESSif all bytes could be read

Definition at line 677 of file CASocket.cpp.

678  {
679  SINT32 ret;
680  UINT32 pos=0;
681  UINT64 currentTime,endTime;
682  getcurrentTimeMillis(currentTime);
683  set64(endTime,currentTime);
684  add64(endTime,msTimeOut);
685 // CASingleSocketGroup oSG(false);
686 // oSG.add(*this);
687  for(;;)
688  {
689  ret = m_pSingleSocketGroupRead->select(msTimeOut);
690  if(ret==1)
691  {
692  ret=receive(buff+pos,len);
693  if(ret<=0)
694  return E_UNKNOWN;
695  pos+=ret;
696  len-=ret;
697  }
698  else if(ret==E_TIMEDOUT)
699  {
700  return E_TIMEDOUT;
701  }
702  if(len==0)
703  return E_SUCCESS;
704  getcurrentTimeMillis(currentTime);
705  if(!isLesser64(currentTime,endTime))
706  {
708  return E_TIMEDOUT;
709  }
710  msTimeOut=diff64(endTime,currentTime);
711  }
712  }
SINT32 getcurrentTimeMillis(UINT64 &u64Time)
Gets the current Systemtime in milli seconds.
Definition: CAUtil.cpp:252
UINT32 diff64(const UINT64 &bigop, const UINT64 &smallop)
Definition: CAUtil.hpp:398
void add64(UINT64 &op1, UINT32 op2)
Definition: CAUtil.hpp:375
bool isLesser64(UINT64 &smallOp1, UINT64 &bigOp2)
Definition: CAUtil.hpp:442
void set64(UINT64 &op1, UINT32 op2)
Definition: CAUtil.hpp:321
virtual SINT32 receive(UINT8 *buff, UINT32 len)
Will receive some bytes from the socket.
Definition: CASocket.cpp:645
#define E_TIMEDOUT
Definition: errorcodes.hpp:10

References add64(), diff64(), E_SUCCESS, E_TIMEDOUT, E_UNKNOWN, getcurrentTimeMillis(), isLesser64(), len, m_pSingleSocketGroupRead, receive(), CASocketGroup::select(), set64(), and SET_NET_ERROR.

Referenced by CAFirstMix::doUserLogin_internal(), CAMuxSocket::receiveFully(), CAInfoService::sendCascadeHelo(), CAInfoService::sendMixHelo(), CAAccountingBIInterface::settle(), and CAAccountingBIInterface::settleAll().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ receiveLine()

SINT32 CASocket::receiveLine ( UINT8 line,
UINT32  maxLen,
UINT32  msTimeOut 
)
virtual

Definition at line 714 of file CASocket.cpp.

715 {
716  UINT32 i = 0;
717  UINT8 byte = 0;
718  SINT32 ret = 0;
719  UINT64 currentTime, endTime;
720  getcurrentTimeMillis(currentTime);
721  set64(endTime,currentTime);
722  add64(endTime,msTimeOut);
723 // CASingleSocketGroup oSG(false);
724 // oSG.add(*this);
725  do
726  {
727  ret = m_pSingleSocketGroupRead->select(msTimeOut);
728  if(ret == 1)
729  {
730  ret = receive(&byte, 1);
731  if(byte == '\r' || byte == '\n')
732  {
733  line[i++] = 0;
734  }
735  else
736  {
737  line[i++] = byte;
738  }
739  }
740  else if(ret == E_TIMEDOUT)
741  {
742  return E_TIMEDOUT;
743  }
744  getcurrentTimeMillis(currentTime);
745  if(!isLesser64(currentTime,endTime))
746  {
748  return E_TIMEDOUT;
749  }
750  msTimeOut=diff64(endTime,currentTime);
751  }
752  while(byte != '\n' && i<maxLen && ret > 0);
753 
754  return ret;
755 }

References add64(), diff64(), E_TIMEDOUT, getcurrentTimeMillis(), isLesser64(), m_pSingleSocketGroupRead, receive(), CASocketGroup::select(), set64(), and SET_NET_ERROR.

Here is the call graph for this function:

◆ send()

SINT32 CASocket::send ( const UINT8 buff,
UINT32  len 
)
virtual

Sends some data over the network.

This may block, if socket is in blocking mode.

Parameters
buffthe buffer of data to send
lencontent length
Return values
E_AGAINif non blocking socket would block or a timeout was reached
E_UNKNOWNif an error occured
Returns
number of bytes send

Reimplemented in CATLSClientSocket.

Definition at line 400 of file CASocket.cpp.

401  {
402  if(len==0)
403  return 0; //nothing to send
404  int ret;
405  SINT32 ef=0;
406  do
407  {
408  ret=::send(m_Socket,(char*)buff,len,MSG_NOSIGNAL);
409  #ifdef _DEBUG
410  if(ret==SOCKET_ERROR)
411  CAMsg::printMsg(LOG_DEBUG,"Fehler beim Socket-send: %i (Socket: %i)\n",GET_NET_ERROR,m_Socket);
412  #endif
413  }
414  while(ret==SOCKET_ERROR&&(ef=GET_NET_ERROR)==EINTR);
415  if(ret==SOCKET_ERROR)
416  {
417  if(ef==ERR_INTERN_WOULDBLOCK)
418  {
419  #ifdef _DEBUG
420  CAMsg::printMsg(LOG_DEBUG,"Fehler beim Socket-send: E_AGAIN\n");
421  #endif
422  return E_AGAIN;
423  }
424  #ifdef _DEBUG
425  CAMsg::printMsg(LOG_DEBUG,"Fehler beim Socket-send:E_UNKNOWN (ef=%i)\n",ef);
426  #endif
427  return E_UNKNOWN;
428  }
429  return ret;
430  }
virtual SINT32 send(const UINT8 *buff, UINT32 len)
Sends some data over the network.
Definition: CASocket.cpp:400

References E_AGAIN, E_UNKNOWN, ERR_INTERN_WOULDBLOCK, GET_NET_ERROR, len, m_Socket, MSG_NOSIGNAL, CAMsg::printMsg(), and SOCKET_ERROR.

Referenced by CALocalProxy::loop(), CALastMixA::loop(), CAFirstMixB::loop(), CALastMix::processKeyExchange(), CAMiddleMix::processKeyExchange(), sendFully(), sendFullyTimeOut(), sendTimeOut(), CAFirstMixA::sendToUsers(), and CAChain::sendUpstreamDataInternal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendFully()

SINT32 CASocket::sendFully ( const UINT8 buff,
UINT32  len 
)
virtual

Sends all data over the network.

This may block until all data is send.

Parameters
buff- the buffer of data to send
len- content length
Return values
E_UNKNOWN,ifan error occured
E_SUCCESS,ifsuccessful

Implements CAClientSocket.

Reimplemented in CATLSClientSocket.

Definition at line 587 of file CASocket.cpp.

588  {
589  if(len==0)
590  return E_SUCCESS; //nothing to send
591  SINT32 ret;
592  CASingleSocketGroup* pSingleSocketGroup = NULL;
593  SINT32 retval = E_UNKNOWN;
594  for(;;)
595  {
596  ret=send(buff,len);
597  if((UINT32)ret==len)
598  return E_SUCCESS;
599  else if(ret==E_AGAIN)
600  {
601  if (pSingleSocketGroup == NULL)
602  {
603  pSingleSocketGroup = new CASingleSocketGroup(true);
604  pSingleSocketGroup->add(*this);
605  }
606 
607  ret= pSingleSocketGroup->select(1000);
608  if(ret>=0||ret==E_TIMEDOUT)
609  continue;
610  #ifdef _DEBUG
611  CAMsg::printMsg(LOG_DEBUG,"CASocket::sendFully() - error near select_once() ret=%i\n",ret);
612  #endif
613  retval=E_UNKNOWN;
614  break;
615  }
616  else if(ret<0)
617  {
618  #ifdef _DEBUG
619  CAMsg::printMsg(LOG_DEBUG,"CASocket::sendFully() - send returned %i\n",ret);
620  #endif
621  retval=E_UNKNOWN;
622  break;
623  }
624  len-=ret;
625  buff+=ret;
626  }
627  if (pSingleSocketGroup != NULL)
628  delete pSingleSocketGroup;
629  return retval;
630 }
SINT32 add(SOCKET &s)

References CASocketGroup::add(), E_AGAIN, E_SUCCESS, E_TIMEDOUT, E_UNKNOWN, len, CAMsg::printMsg(), CASocketGroup::select(), and send().

Referenced by CALocalProxy::processKeyExchange(), CAMuxSocket::send(), and sendFullyTimeOut().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendFullyTimeOut()

SINT32 CASocket::sendFullyTimeOut ( const UINT8 buff,
UINT32  len,
UINT32  msTimeOut,
UINT32  msTimeOutSingleSend 
)
virtual

Sends all data over the network.

This may block until all data is send.

Parameters
buff- the buffer of data to send
len- content length
Return values
E_UNKNOWN,ifan error occured
E_TIMEDOUTif the timeout was reached
E_SUCCESS,ifsuccessful

Definition at line 488 of file CASocket.cpp.

489 {
490  if(len==0)
491  {
492  return E_SUCCESS; //nothing to send
493  }
494 
495  SINT32 ret;
496  SINT32 aktTimeOut=0;
497  UINT64 startupTime, currentMillis;
498  CASingleSocketGroup* pSingleSocketGroup = NULL;
499 
500  bool bWasNonBlocking;
501  getNonBlocking(&bWasNonBlocking);
502  aktTimeOut=getSendTimeOut();
503  getcurrentTimeMillis(startupTime);
504 
505  if(bWasNonBlocking)
506  {
507  //we are in non-blocking mode
508 #ifdef _DEBUG
509  CAMsg::printMsg(LOG_DEBUG, "CASocket::sendFullyTimeOut() -->non-blocking case\n");
510 #endif
511  return sendFully(buff, len);
512  }
513  else if (setSendTimeOut(msTimeOutSingleSend)!=E_SUCCESS)
514  {
515  // it is not possible to set the socket timeout
516  CAMsg::printMsg(LOG_ERR,"CASocket::sendFullyTimeOut() - could not set socket timeout!\n");
517  return sendFully(buff, len);
518  }
519  else
520  {
521  SINT32 retval = E_UNKNOWN;
522  for(;;)
523  {
524  getcurrentTimeMillis(currentMillis);
525  if (currentMillis >= (startupTime + msTimeOut))
526  {
527  #ifdef DEBUG
528  CAMsg::printMsg(LOG_DEBUG,"CASocket::sendFullyTimeOut() - timed out!\n");
529  #endif
530  setSendTimeOut(aktTimeOut);
532  retval=E_TIMEDOUT;
533  break;
534  }
535 
536  ret=send(buff,len);
537 #ifdef DEBUG
538  CAMsg::printMsg(LOG_DEBUG, "CASocket::sendFullyTimeOut() - send returned %i (expected: %u)!\n",ret,len);
539 #endif
540  if((UINT32)ret==len)
541  {
542  setSendTimeOut(aktTimeOut);
543  retval=E_SUCCESS;
544  break;
545  }
546  else if(ret==E_AGAIN)
547  {
548  if (pSingleSocketGroup == NULL)
549  {
550  pSingleSocketGroup = new CASingleSocketGroup(true);
551  pSingleSocketGroup->add(*this);
552  }
553  ret= pSingleSocketGroup->select(1000);
554  if(ret>=0||ret==E_TIMEDOUT)
555  continue;
556  #ifdef _DEBUG
557  CAMsg::printMsg(LOG_DEBUG,"CASocket::sendTimeOutFully() - error near select_once() ret=%i\n",ret);
558  #endif
559  setSendTimeOut(aktTimeOut);
560  retval=E_UNKNOWN;
561  break;
562  }
563  else if(ret<0)
564  {
565  #ifdef _DEBUG
566  CAMsg::printMsg(LOG_DEBUG,"CASocket::sendTimeOutFully() - send returned %i\n",ret);
567  #endif
568  setSendTimeOut(aktTimeOut);
569  retval=E_UNKNOWN;
570  break;
571  }
572  len-=ret;
573  buff+=ret;
574  }
575  if (pSingleSocketGroup != NULL)
576  delete pSingleSocketGroup;
577  return retval;
578  }
579 }
virtual SINT32 getSendTimeOut()
Definition: CASocket.cpp:891
virtual SINT32 setSendTimeOut(UINT32 msTimeOut)
Definition: CASocket.cpp:883
virtual SINT32 sendFully(const UINT8 *buff, UINT32 len)
Sends all data over the network.
Definition: CASocket.cpp:587

References CASocketGroup::add(), E_AGAIN, E_SUCCESS, E_TIMEDOUT, E_UNKNOWN, getcurrentTimeMillis(), getNonBlocking(), getSendTimeOut(), len, CAMsg::printMsg(), CASocketGroup::select(), send(), sendFully(), SET_NET_ERROR, and setSendTimeOut().

Referenced by CAFirstMix::doUserLogin_internal(), CAInfoService::sendCascadeHelo(), CAHttpClient::sendGetRequest(), CAInfoService::sendMixHelo(), CAHttpClient::sendPostRequest(), and CAInfoService::sendStatus().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendTimeOut()

SINT32 CASocket::sendTimeOut ( const UINT8 buff,
UINT32  len,
UINT32  msTimeOut 
)
virtual

Sends some data over the network.

Using a Timeout if socket is in blocking mode. Otherwise E_AGAIN may returned

Parameters
buffthe buffer to send
lencontent length
msTimeOutMaximum MilliSeconds to wait
Return values
E_AGAINif Operation would block on a non-blocking socket
E_TIMEDOUTif the timeout was reached
Returns
number of bytes send, or -1 in case of an error /FIXME really buggy!!!!

Definition at line 442 of file CASocket.cpp.

443 {
444  SINT32 ret;
445  SINT32 aktTimeOut=0;
446  bool bWasNonBlocking;
447  getNonBlocking(&bWasNonBlocking);
448  if(bWasNonBlocking) //we are in non-blocking mode
449  {
450  ret=send(buff,len);
451  }
452  else
453  {
454  aktTimeOut=getSendTimeOut();
455  if(aktTimeOut>0&&(UINT32)aktTimeOut==msTimeOut) //we already have the right timeout
456  {
457  ret=send(buff,len);
458  }
459  else if(aktTimeOut<0||setSendTimeOut(msTimeOut)!=E_SUCCESS)
460  {//do it complicate but still to simple!!!! more work TODO
461  setNonBlocking(true);
462  ret=send(buff,len);
463  if(ret==E_AGAIN)
464  {
465  CAMsg::printMsg(LOG_DEBUG,"Send again...\n");
466  msSleep((UINT16)msTimeOut);
467  ret=send(buff,len);
468  }
469  setNonBlocking(bWasNonBlocking);
470  }
471  else
472  {
473  ret=send(buff,len);
474  setSendTimeOut(aktTimeOut);
475  }
476  }
477  return ret;
478 }
SINT32 msSleep(UINT32 ms)
Sleeps ms milliseconds.
Definition: CAUtil.cpp:406

References E_AGAIN, E_SUCCESS, getNonBlocking(), getSendTimeOut(), len, msSleep(), CAMsg::printMsg(), send(), setNonBlocking(), and setSendTimeOut().

Referenced by CALastMixA::loop(), and CALastMixB::loop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setKeepAlive() [1/2]

SINT32 CASocket::setKeepAlive ( bool  b)
virtual

Enables/disables the socket keep-alive option.

Parameters
btrue if option should be enabled, false otherwise
Returns
E_SUCCESS if no error occured
E_UNKOWN otherwise

Definition at line 906 of file CASocket.cpp.

907  {
908  int val=0;
909  if(b) val=1;
910  if(setsockopt(m_Socket,SOL_SOCKET,SO_KEEPALIVE,(char*)&val,sizeof(val))==SOCKET_ERROR)
911  {
912  int errnum=GET_NET_ERROR;
913  CAMsg::printMsg(LOG_ERR, "Could not set KEEP_ALIVE options. Reason: %s (%i)\n", GET_NET_ERROR_STR(errnum), errnum);
914  return E_UNKNOWN;
915  }
916  return E_SUCCESS;
917  }

References E_SUCCESS, E_UNKNOWN, GET_NET_ERROR, GET_NET_ERROR_STR, m_Socket, CAMsg::printMsg(), and SOCKET_ERROR.

Referenced by CAFirstMix::doUserLogin_internal(), CAFirstMix::init(), CALastMix::init(), CAMiddleMix::init(), and setKeepAlive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setKeepAlive() [2/2]

SINT32 CASocket::setKeepAlive ( UINT32  sec)
virtual

Enables the socket keep-alive option with a given ping time (in seconds).

Parameters
secthe time intervall(in seconds) of a keep-alive message
Returns
E_SUCCESS if no error occured
E_UNKOWN otherwise

Definition at line 924 of file CASocket.cpp.

925  {
926  if(setKeepAlive(true)!=E_SUCCESS)
927  {
928  return E_UNKNOWN;
929  }
930 
931 #ifdef HAVE_TCP_KEEPALIVE
932  int val=sec;
933  if(setsockopt(m_Socket,IPPROTO_TCP,TCP_KEEPALIVE,(char*)&val,sizeof(val))==SOCKET_ERROR)
934  {
935  CAMsg::printMsg(LOG_ERR,"Socket option TCP-KEEP-ALIVE was not set! Reason: %s (%i)\n",
937  return E_UNKNOWN;
938  }
939  return E_SUCCESS;
940 #else
941  CAMsg::printMsg(LOG_INFO,"Socket option TCP-KEEP-ALIVE was not set as it is not available on this machine.\n");
942  return E_UNKNOWN;
943 #endif
944  }
virtual SINT32 setKeepAlive(bool b)
Enables/disables the socket keep-alive option.
Definition: CASocket.cpp:906

References E_SUCCESS, E_UNKNOWN, GET_NET_ERROR, GET_NET_ERROR_STR, m_Socket, CAMsg::printMsg(), setKeepAlive(), and SOCKET_ERROR.

Here is the call graph for this function:

◆ setMaxNormalSockets()

static SINT32 CASocket::setMaxNormalSockets ( UINT32  u)
inlinestatic

Sets the max number of allowed "normal" sockets.

Return values
E_SUCCESSif call was successful
E_UNKNOWNotherwise

Definition at line 116 of file CASocket.hpp.

117  {
119  return E_SUCCESS;
120  }

References E_SUCCESS, and m_u32MaxNormalSockets.

Referenced by main().

Here is the caller graph for this function:

◆ setNonBlocking()

SINT32 CASocket::setNonBlocking ( bool  b)
virtual

Definition at line 947 of file CASocket.cpp.

948  {
949  if(b)
950  {
951  #ifndef _WIN32
952  int flags=fcntl(m_Socket,F_GETFL,0);
953  fcntl(m_Socket,F_SETFL,flags|O_NONBLOCK);
954  #else
955  unsigned long flags=1;
956  ioctlsocket(m_Socket,FIONBIO,&flags);
957  #endif
958  }
959  else
960  {
961  #ifndef _WIN32
962  int flags=fcntl(m_Socket,F_GETFL,0);
963  fcntl(m_Socket,F_SETFL,flags&~O_NONBLOCK);
964  #else
965  unsigned long flags=0;
966  ioctlsocket(m_Socket,FIONBIO,&flags);
967  #endif
968  }
969  return E_SUCCESS;
970  }
#define ioctlsocket(a, b, c)
Definition: StdAfx.h:462

References E_SUCCESS, flags, ioctlsocket, and m_Socket.

Referenced by connect(), CAFirstMix::doUserLogin_internal(), CAFirstMix::init(), CALastMix::init(), CALastMixA::loop(), CALastMixB::loop(), CAHttpClient::parseHTTPHeader(), sendTimeOut(), CAAccountingBIInterface::settle(), and CAAccountingBIInterface::settleAll().

Here is the caller graph for this function:

◆ setRecvBuff()

SINT32 CASocket::setRecvBuff ( UINT32  r)
virtual

Definition at line 846 of file CASocket.cpp.

847  {
848  int val=r;
849  return setsockopt(m_Socket,SOL_SOCKET,SO_RCVBUF,(char*)&val,sizeof(val));
850  }

References m_Socket.

Referenced by CAFirstMix::init(), CALastMix::init(), CALocalProxy::init(), CAMiddleMix::init(), CALastMixA::loop(), CALastMixB::loop(), CAInfoService::sendMixHelo(), and CACmdLnOptions::setTargetInterfaces().

Here is the caller graph for this function:

◆ setReuseAddr()

SINT32 CASocket::setReuseAddr ( bool  b)
virtual

Definition at line 839 of file CASocket.cpp.

840  {
841  int val=0;
842  if(b) val=1;
843  return setsockopt(m_Socket,SOL_SOCKET,SO_REUSEADDR,(char*)&val,sizeof(val));
844  }

References m_Socket.

Referenced by CAMuxSocket::accept(), CACmdLnOptions::createSockets(), and CALocalProxy::init().

Here is the caller graph for this function:

◆ setSendBuff()

SINT32 CASocket::setSendBuff ( SINT32  r)
virtual

Returns < 0 on error, otherwise the new sendbuffersize (which may be less than r)

Definition at line 862 of file CASocket.cpp.

863  {
864  if(r<0)
865  return E_UNKNOWN;
866  SINT32 val=r;
867  SINT32 ret=setsockopt(m_Socket,SOL_SOCKET,SO_SNDBUF,(char*)&val,sizeof(val));
868  if(ret!=0)
869  return E_UNKNOWN;
870  return getSendBuff();
871  }
virtual SINT32 getSendBuff()
Definition: CASocket.cpp:873

References E_UNKNOWN, getSendBuff(), and m_Socket.

Referenced by CAFirstMix::init(), CALastMix::init(), CALocalProxy::init(), CAMiddleMix::init(), CALastMixA::loop(), CALastMixB::loop(), and CACmdLnOptions::setTargetInterfaces().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSendTimeOut()

SINT32 CASocket::setSendTimeOut ( UINT32  msTimeOut)
virtual

Definition at line 883 of file CASocket.cpp.

884  {
885  timeval t;
886  t.tv_sec=msTimeOut/1000;
887  t.tv_usec=(msTimeOut%1000)*1000;
888  return setsockopt(m_Socket,SOL_SOCKET,SO_SNDTIMEO,(char*)&t,sizeof(t));
889  }

References m_Socket.

Referenced by sendFullyTimeOut(), and sendTimeOut().

Here is the caller graph for this function:

◆ setSocket()

SINT32 CASocket::setSocket ( SOCKET  s)
privatevirtual

Definition at line 57 of file CASocket.cpp.

58  {
60  m_Socket = s;
61  if (s != 0)
62  {
65  }
66  else
67  {
69  }
70  return E_SUCCESS;
71  }

References CASocketGroup::add(), E_SUCCESS, m_pSingleSocketGroupRead, and m_Socket.

Referenced by accept(), close(), and create().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_bIsReservedSocket

bool CASocket::m_bIsReservedSocket
private

Definition at line 164 of file CASocket.hpp.

Referenced by CASocket(), close(), and create().

◆ m_bSocketIsClosed

volatile bool CASocket::m_bSocketIsClosed
protected

check

end check

Definition at line 145 of file CASocket.hpp.

Referenced by accept(), CASocket(), close(), connect(), create(), isClosed(), and listen().

◆ m_pcsClose

CAMutex * CASocket::m_pcsClose =NULL
staticprivate

Definition at line 159 of file CASocket.hpp.

Referenced by accept(), cleanup(), close(), create(), and init().

◆ m_pSingleSocketGroupRead

CASingleSocketGroup* CASocket::m_pSingleSocketGroupRead
protected

Definition at line 151 of file CASocket.hpp.

Referenced by CASocket(), receiveFullyT(), receiveLine(), and setSocket().

◆ m_Socket

SOCKET CASocket::m_Socket
protected

◆ m_u32MaxNormalSockets

UINT32 CASocket::m_u32MaxNormalSockets =0xFFFFFFFF
staticprivate

Definition at line 163 of file CASocket.hpp.

Referenced by accept(), create(), and setMaxNormalSockets().

◆ m_u32NormalSocketsOpen

volatile UINT32 CASocket::m_u32NormalSocketsOpen =0
staticprivate

The following two variables are use to realise "reserved" sockets.

The rational behind is to ensure that we could allway crate "reserved" socket why we may fail to create normal sockets because of to many open files related restrictions

Definition at line 162 of file CASocket.hpp.

Referenced by accept(), close(), countOpenSockets(), and create().


The documentation for this class was generated from the following files: