reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
FakeSelectSocketDescriptor.cxx
Go to the documentation of this file.
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/compat.hxx>
9#include <rutil/Log.hxx>
10#include <rutil/Logger.hxx>
11#include "rutil/ResipAssert.h"
12
16
17using namespace flowmanager;
18using namespace std;
19
20#define RESIPROCATE_SUBSYSTEM FlowManagerSubsystem::FLOWMANAGER
21
23{
24#ifdef WIN32
25 sockaddr socketAddr;
26 mSocket = (int)::socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
27
28 sockaddr_in loopback;
29 memset(&loopback, 0, sizeof(loopback));
30 loopback.sin_family = AF_INET;
31 loopback.sin_port = 0;
32 loopback.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
33 unsigned long noBlock = 1;
34 ioctlsocket( mSocket, FIONBIO , &noBlock );
35 ::bind( mSocket, reinterpret_cast<sockaddr*>(&loopback), sizeof(loopback));
36 memset(&socketAddr, 0, sizeof(socketAddr));
37 int len = sizeof(socketAddr);
38 int error = getsockname(mSocket, (sockaddr *)&socketAddr, &len);
39 resip_assert(error == 0);
40 error= connect(mSocket, &socketAddr, sizeof(socketAddr));
41 resip_assert(error == 0);
42#else
43 if(pipe(mPipe) < 0)
44 {
45 throw FlowManagerException("Failed to create pipe", __FILE__, __LINE__);
46 }
47#endif
48}
49
51{
52#ifdef WIN32
53 closesocket(mSocket);
54#else
55 close(mPipe[0]);
56 close(mPipe[1]);
57#endif
58}
59
60unsigned int
62{
63#ifdef WIN32
64 return mSocket;
65#else
66 return mPipe[0];
67#endif
68}
69
70void
72{
73 static char fakeData[] = "*";
74#ifdef WIN32
75 int count = ::send(mSocket, fakeData, 1, 0);
76 resip_assert(count == 1);
77#else
78 size_t res = ::write(mPipe[1], fakeData, 1);
79 resip_assert(res == 1);
80#endif
81}
82
83void
85{
86#ifdef WIN32
87 char rdBuf[1];
88 ::recv(mSocket, rdBuf, 1, 0);
89#else
90 char rdBuf[1];
91 if(::read(mPipe[0], rdBuf, 1) < 0)
92 {
93 WarningLog(<< "read error: " << resip::strError(errno));
94 }
95#endif
96}
97
98
99/* ====================================================================
100
101 Copyright (c) 2007-2008, Plantronics, Inc.
102 All rights reserved.
103
104 Redistribution and use in source and binary forms, with or without
105 modification, are permitted provided that the following conditions are
106 met:
107
108 1. Redistributions of source code must retain the above copyright
109 notice, this list of conditions and the following disclaimer.
110
111 2. Redistributions in binary form must reproduce the above copyright
112 notice, this list of conditions and the following disclaimer in the
113 documentation and/or other materials provided with the distribution.
114
115 3. Neither the name of Plantronics nor the names of its contributors
116 may be used to endorse or promote products derived from this
117 software without specific prior written permission.
118
119 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
120 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
121 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
122 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
123 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
124 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
125 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
126 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
127 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
128 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
129 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
130
131 ==================================================================== */
#define WarningLog(args_)
Definition Logger.hxx:134
#define resip_assert(x)
This file needs to work for both C and C++ code.
This class is used to raise exceptions in the flow manager.
This file is used to handle compatibility fixes/tweaks so reSIProcate can function on multiple platfo...
This class is used during media sessions that use Dtls-Srtp for a media transport.
Definition ErrorCode.hxx:4
std::string strError(int err)
Definition compat.hxx:274