/[resiprocate]/main/reflow/FakeSelectSocketDescriptor.cxx
ViewVC logotype

Contents of /main/reflow/FakeSelectSocketDescriptor.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7729 - (show annotations) (download)
Fri May 9 19:19:21 2008 UTC (11 years, 8 months ago) by sgodin
File MIME type: text/plain
File size: 3546 byte(s)
-merged b-recon-20080504 with main - summary:
  - added the new reflow and recon projects
  - changes to configure to support new projects and
    ask if repro should be built or not
  - updated ASIO to 1.0.0
  - added VS2005 project files and solutions for reTurn
  - moved/merged dtls_wrapper project into reflow

1 #if defined(WIN32)
2 #include <winsock2.h>
3 #include <WS2TCPIP.H>
4 #else
5 #include <netinet/in.h>
6 #endif
7
8 #include <rutil/Log.hxx>
9 #include <rutil/Logger.hxx>
10 #include <assert.h>
11
12 #include "FlowManagerSubsystem.hxx"
13 #include "FakeSelectSocketDescriptor.hxx"
14
15 using namespace flowmanager;
16 using namespace std;
17
18 #define RESIPROCATE_SUBSYSTEM FlowManagerSubsystem::FLOWMANAGER
19
20 FakeSelectSocketDescriptor::FakeSelectSocketDescriptor()
21 {
22 #ifdef WIN32
23 sockaddr socketAddr;
24 mSocket = ::socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
25
26 sockaddr_in loopback;
27 memset(&loopback, 0, sizeof(loopback));
28 loopback.sin_family = AF_INET;
29 loopback.sin_port = 0;
30 loopback.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
31 unsigned long noBlock = 1;
32 ioctlsocket( mSocket, FIONBIO , &noBlock );
33 ::bind( mSocket, reinterpret_cast<sockaddr*>(&loopback), sizeof(loopback));
34 memset(&socketAddr, 0, sizeof(socketAddr));
35 int len = sizeof(socketAddr);
36 int error = getsockname(mSocket, (sockaddr *)&socketAddr, &len);
37 assert(error == 0);
38 error= connect(mSocket, &socketAddr, sizeof(socketAddr));
39 assert(error == 0);
40 #else
41 pipe(mPipe);
42 #endif
43 }
44
45 FakeSelectSocketDescriptor::~FakeSelectSocketDescriptor()
46 {
47 #ifdef WIN32
48 closesocket(mSocket);
49 #else
50 close(mPipe[0]);
51 close(mPipe[1]);
52 #endif
53 }
54
55 unsigned int
56 FakeSelectSocketDescriptor::getSocketDescriptor()
57 {
58 #ifdef WIN32
59 return mSocket;
60 #else
61 return mPipe[0];
62 #endif
63 }
64
65 void
66 FakeSelectSocketDescriptor::send()
67 {
68 static char fakeData[] = "*";
69 #ifdef WIN32
70 int count = ::send(mSocket, fakeData, 1, 0);
71 assert(count == 1);
72 #else
73 size_t res = ::write(mPipe[1], fakeData, 1);
74 assert(res == 1);
75 #endif
76 }
77
78 void
79 FakeSelectSocketDescriptor::receive()
80 {
81 #ifdef WIN32
82 char rdBuf[1];
83 ::recv(mSocket, rdBuf, 1, 0);
84 #else
85 char rdBuf[1];
86 ::read(mPipe[0], rdBuf, 1);
87 #endif
88 }
89
90
91 /* ====================================================================
92
93 Copyright (c) 2007-2008, Plantronics, Inc.
94 All rights reserved.
95
96 Redistribution and use in source and binary forms, with or without
97 modification, are permitted provided that the following conditions are
98 met:
99
100 1. Redistributions of source code must retain the above copyright
101 notice, this list of conditions and the following disclaimer.
102
103 2. Redistributions in binary form must reproduce the above copyright
104 notice, this list of conditions and the following disclaimer in the
105 documentation and/or other materials provided with the distribution.
106
107 3. Neither the name of Plantronics nor the names of its contributors
108 may be used to endorse or promote products derived from this
109 software without specific prior written permission.
110
111 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
112 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
113 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
114 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
115 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
116 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
117 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
118 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
119 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
120 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
121 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
122
123 ==================================================================== */

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27