Stun Server  Compliant with the latest RFCs including 5389, 5769, and 5780
discover the local host's own external IP address
stunsocketthread.h
Go to the documentation of this file.
1 /*
2  Copyright 2011 John Selbie
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 
18 
19 #ifndef STUNSOCKETTHREAD_H
20 #define STUNSOCKETTHREAD_H
21 
22 #include "stunsocket.h"
23 #include "ratelimiter.h"
24 
25 
26 class CStunServer;
27 
28 
30 {
31 
32 public:
35 
36  HRESULT Init(CStunSocket* arrayOfFourSockets, TransportAddressSet* pTSA, IStunAuth* pAuth, SocketRole rolePrimaryRecv, boost::shared_ptr<RateLimiter>& _spRateLimiter);
37  HRESULT Start();
38 
39  HRESULT SignalForStop(bool fPostMessages);
41 
42 
43 
44 private:
45 
46  // this is the function that runs in a thread
47  void Run();
48 
49  static void* ThreadFunction(void* pThis);
50 
52 
53  CStunSocket* _arrSendSockets; // matches CStunServer::_arrSockets
54  std::vector<CStunSocket*> _socks; // sockets for receiving on
55 
57  pthread_t _pthread;
59 
60  int _rotation;
61 
63 
65 
66  // pre-allocated objects for the thread
68  CRefCountedBuffer _spBufferReader; // buffer internal to the reader
69  CRefCountedBuffer _spBufferIn; // buffer we receive requests on
70  CRefCountedBuffer _spBufferOut; // buffer we send response on
73 
74  boost::shared_ptr<RateLimiter> _spLimiter;
75 
77  void UninitThreadBuffers();
78 
80 
81  void ClearSocketArray();
82 
83 };
84 
85 
86 
87 
88 #endif /* STUNSOCKETTHREAD_H */
89 
std::vector< CStunSocket * > _socks
StunMessageOut _msgOut
CStunMessageReader _reader
CStunSocket * _arrSendSockets
CRefCountedBuffer _spBufferOut
CRefCountedBuffer _spBufferReader
CRefCountedBuffer _spBufferIn
TransportAddressSet _tsa
HRESULT Init(CStunSocket *arrayOfFourSockets, TransportAddressSet *pTSA, IStunAuth *pAuth, SocketRole rolePrimaryRecv, boost::shared_ptr< RateLimiter > &_spRateLimiter)
HRESULT ProcessRequestAndSendResponse()
boost::shared_ptr< RateLimiter > _spLimiter
static void * ThreadFunction(void *pThis)
SocketRole
Definition: socketrole.h:22
int32_t HRESULT
Definition: hresult.h:22
StunMessageIn _msgIn
CRefCountedPtr< IStunAuth > _spAuth
CStunSocket * WaitForSocketData()
boost::shared_ptr< CBuffer > CRefCountedBuffer
Definition: buffer.h:65
HRESULT SignalForStop(bool fPostMessages)