30 _pthread((pthread_t)-1),
31 _fThreadIsValid(false),
63 if (fSingleSocketRecv)
73 if (fSingleSocketRecv)
80 for (
size_t i = 0; i < 4; i++)
169 for (
size_t index = 0; index <
_socks.size(); index++)
198 void* pRetValFromThread = NULL;
203 pthread_join(
_pthread, &pRetValFromThread);
227 int nHighestSockValue = 0;
231 size_t nSocketCount =
_socks.size();
240 for (
size_t index = 0; index < nSocketCount; index++)
243 int sock =
_socks[index]->GetSocketHandle();
246 nHighestSockValue = (sock > nHighestSockValue) ? sock : nHighestSockValue;
250 ret = ::select(nHighestSockValue+1, &
set, NULL, NULL, NULL);
255 for (
size_t index = 0; index < nSocketCount; index++)
257 int indexconverted = (index +
_rotation) % nSocketCount;
258 int sock =
_socks[indexconverted]->GetSocketHandle();
262 if (FD_ISSET(sock, &
set))
264 pReadySocket =
_socks[indexconverted];
269 ASSERT(pReadySocket != NULL);
277 size_t nSocketCount =
_socks.size();
278 bool fMultiSocketMode = (nSocketCount > 1);
279 int recvflags = fMultiSocketMode ? MSG_DONTWAIT : 0;
282 char szIPRemote[100] = {};
283 char szIPLocal[100] = {};
284 bool allowed_to_pass =
true;
287 int sendsocketcount = 0;
299 if (fMultiSocketMode)
338 szIPRemote[0] =
'\0';
346 if (allowed_to_pass ==
false)
351 if ((ret < 0) || (allowed_to_pass ==
false))
const uint32_t MAX_STUN_MESSAGE_SIZE
bool IsValidSocketRole(SocketRole sr)
std::vector< CStunSocket * > _socks
CDataStream & GetStream()
CStunMessageReader _reader
void UninitThreadBuffers()
CStunSocket * _arrSendSockets
socklen_t GetSockAddrLength() const
HRESULT InitThreadBuffers()
CRefCountedBuffer _spBufferOut
HRESULT WaitForStopAndClose()
CRefCountedBuffer _spBufferReader
ssize_t recvfromex(int sockfd, void *buf, size_t len, int flags, CSocketAddress *pSrcAddr, CSocketAddress *pDstAddr)
void LogMsg(uint32_t level, const char *pszFormat,...)
static HRESULT GetLocalHost(uint16_t family, CSocketAddress *pAddr)
CRefCountedBuffer _spBufferIn
HRESULT Init(CStunSocket *arrayOfFourSockets, TransportAddressSet *pTSA, IStunAuth *pAuth, SocketRole rolePrimaryRecv, boost::shared_ptr< RateLimiter > &_spRateLimiter)
#define UNREFERENCED_VARIABLE(unrefparam)
HRESULT ProcessRequestAndSendResponse()
#define ERRNO_TO_HRESULT(err)
#define ChkIf(expr, hrerror)
ReaderParseState AddBytes(const uint8_t *pData, uint32_t size)
CSocketAddress addrRemote
What local IP address the message was received on (useful if the socket binded to INADDR_ANY) ...
CSocketAddress addrLocal
which socket id did the message arrive on
boost::shared_ptr< RateLimiter > _spLimiter
int GetSocketHandle() const
ReaderParseState GetState()
SocketRole GetRole() const
static void * ThreadFunction(void *pThis)
const sockaddr * GetSockAddr() const
HRESULT ToStringBuffer(char *pszAddrBytes, size_t length) const
CStunMessageReader * pReader
the address of the node that sent us the message
static HRESULT ProcessRequest(const StunMessageIn &msgIn, StunMessageOut &msgOut, TransportAddressSet *pAddressSet, IStunAuth *pAuth)
const uint32_t LL_VERBOSE
CRefCountedPtr< IStunAuth > _spAuth
CStunSocket * WaitForSocketData()
uint16_t GetFamily() const
CRefCountedBuffer spBufferOut
boost::shared_ptr< CBuffer > CRefCountedBuffer
void Attach(CRefCountedBuffer &buffer, bool fForWriting)
bool IsIPAddressZero() const
HRESULT SignalForStop(bool fPostMessages)
#define ChkIfA(expr, hrerror)
bool fConnectionOriented
reader containing a valid stun message
const CSocketAddress & GetLocalAddress() const