Mixe for Privacy and Anonymity in the Internet
CAClientSocket.cpp
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 
29 #include "StdAfx.h"
30 #include "CAClientSocket.hpp"
31 #include "CASingleSocketGroup.hpp"
32 
34 {
35  SINT32 ret;
36  UINT32 pos = 0;
37 #ifdef __BUILD_AS_SHADOW_PLUGIN__
38  CASingleSocketGroup* pSocketGroup = new CASingleSocketGroup(false);
39  pSocketGroup->add(getSocket());
40 #endif
41  do
42  {
43 #ifdef __BUILD_AS_SHADOW_PLUGIN__
44  pSocketGroup->select();
45 #endif
46  ret = receive(buff + pos, len);
47  if (ret <= 0)
48  {
49  if (ret == E_AGAIN)
50  {
51 #ifndef __BUILD_AS_SHADOW_PLUGIN__
52  msSleep(100);
53 #endif
54  continue;
55  }
56  else
57  {
58 #ifdef __BUILD_AS_SHADOW_PLUGIN__
59  delete pSocketGroup;
60 #endif
61  return E_UNKNOWN;
62  }
63  }
64  pos += ret;
65  len -= ret;
66  } while (len > 0);
67 #ifdef __BUILD_AS_SHADOW_PLUGIN__
68  delete pSocketGroup;
69 #endif
70  return E_SUCCESS;
71 }
72 
SINT32 msSleep(UINT32 ms)
Sleeps ms milliseconds.
Definition: CAUtil.cpp:406
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
virtual SINT32 receive(UINT8 *buff, UINT32 len)=0
Will receive some bytes from the socket.
virtual SOCKET getSocket()=0
Returns the number of the Socket used.
SINT32 receiveFully(UINT8 *buff, UINT32 len)
Receives all len bytes.
SINT32 add(SOCKET &s)
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_AGAIN
Definition: errorcodes.hpp:9
#define E_UNKNOWN
Definition: errorcodes.hpp:3
UINT16 len
Definition: typedefs.hpp:0