EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TCPServer< X > Class Template Reference

Connection-type-dependent version of TCP server. More...

#include "TCPServer.h"

Inheritance diagram for TCPServer< X >:
Collaboration diagram for TCPServer< X >:

Public Member Functions

 ~TCPServer ()
 Deletes all stored connections. More...
 
X * PopConnection ()
 Pops connection from queue. More...
 
- Public Member Functions inherited from BaseTCPServer
 BaseTCPServer ()
 Creates empty TCP server. More...
 
virtual ~BaseTCPServer ()
 Cleans server up. More...
 
uint16 GetPort () const
 
bool IsOpen () const
 
bool Open (uint16 port, char *errbuf=0)
 Start listening on specified port. More...
 
void Close ()
 Stops started listening. More...
 

Protected Member Functions

void AddConnection (X *con)
 Adds connection to the queue. More...
 
- Protected Member Functions inherited from BaseTCPServer
void StartLoop ()
 Starts worker thread. More...
 
void WaitLoop ()
 Waits for worker thread to terminate. More...
 
virtual bool Process ()
 Does periodical stuff to keep the server alive. More...
 
void ListenNewConnections ()
 Accepts all new connections. More...
 
virtual void CreateNewConnection (Socket *sock, uint32 rIP, uint16 rPort)=0
 Processes new connection. More...
 
void TCPServerLoop ()
 Loop for worker threads. More...
 

Protected Attributes

Mutex mMQueue
 
std::queue< X * > mQueue
 
- Protected Attributes inherited from BaseTCPServer
Mutex mMSock
 
SocketmSock
 
uint16 mPort
 
Mutex mMLoopRunning
 

Additional Inherited Members

- Static Protected Member Functions inherited from BaseTCPServer
static void * TCPServerLoop (void *arg)
 Loop for worker threads. More...
 

Detailed Description

template<typename X>
class TCPServer< X >

Connection-type-dependent version of TCP server.

Author
Zhur, Bloody.Rabbit

Definition at line 136 of file TCPServer.h.

Constructor & Destructor Documentation

template<typename X>
TCPServer< X >::~TCPServer ( )
inline

Deletes all stored connections.

Definition at line 142 of file TCPServer.h.

143  {
144  MutexLock lock( mMQueue );
145 
146  X* conn(nullptr);
147  while( ( conn = PopConnection() ) )
148  SafeDelete( conn );
149  }
A lock for a Lockable object.
Definition: Lock.h:70
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
X * PopConnection()
Pops connection from queue.
Definition: TCPServer.h:156
Mutex mMQueue
Definition: TCPServer.h:184

Member Function Documentation

template<typename X>
void TCPServer< X >::AddConnection ( X *  con)
inlineprotected

Adds connection to the queue.

Parameters
[in]conConnection to be added to the queue.

Definition at line 176 of file TCPServer.h.

177  {
178  MutexLock lock( mMQueue );
179 
180  mQueue.push( con );
181  }
A lock for a Lockable object.
Definition: Lock.h:70
Mutex mMQueue
Definition: TCPServer.h:184
std::queue< X * > mQueue
Definition: TCPServer.h:186
template<typename X>
X* TCPServer< X >::PopConnection ( )
inline

Pops connection from queue.

Returns
Popped connection.

Definition at line 156 of file TCPServer.h.

Referenced by main(), and TCPServer< EVETCPConnection >::~TCPServer().

157  {
158  MutexLock lock( mMQueue );
159 
160  X* ret(nullptr);
161  if( !mQueue.empty() )
162  {
163  ret = mQueue.front();
164  mQueue.pop();
165  }
166 
167  return ret;
168  }
A lock for a Lockable object.
Definition: Lock.h:70
Mutex mMQueue
Definition: TCPServer.h:184
std::queue< X * > mQueue
Definition: TCPServer.h:186

Here is the caller graph for this function:

Member Data Documentation

template<typename X>
Mutex TCPServer< X >::mMQueue
protected
template<typename X>
std::queue<X*> TCPServer< X >::mQueue
protected

Connection queue.

Definition at line 186 of file TCPServer.h.

Referenced by TCPServer< EVETCPConnection >::AddConnection(), and TCPServer< EVETCPConnection >::PopConnection().


The documentation for this class was generated from the following file: