EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
APIServerListener Class Reference

Handles listening for new clients. More...

#include "APIServerListener.h"

Public Member Functions

 APIServerListener (boost::asio::io_context &io)
 
 ~APIServerListener ()
 

Private Member Functions

void StartAccept ()
 
void HandleAccept (std::tr1::shared_ptr< APIServerConnection > connection)
 

Private Attributes

boost::asio::ip::tcp::acceptor * _acceptor
 

Detailed Description

Handles listening for new clients.

Asynchronously listens for new clients and creates new connections for them to process them

Author
Aknor Jaden
Date
July 2011

Definition at line 41 of file APIServerListener.h.

Constructor & Destructor Documentation

APIServerListener::APIServerListener ( boost::asio::io_context &  io)

Definition at line 31 of file APIServerListener.cpp.

References _acceptor, sConfig, sLog, and StartAccept().

32 {
33  _acceptor = new boost::asio::ip::tcp::acceptor(io, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), sConfig.net.apiServerPort));
34  sLog.Log("API Server Init", "listening on port %u", (sConfig.net.apiServerPort));
35  StartAccept();
36 }
#define sConfig
A macro for easier access to the singleton.
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
boost::asio::ip::tcp::acceptor * _acceptor

Here is the call graph for this function:

APIServerListener::~APIServerListener ( )

Definition at line 38 of file APIServerListener.cpp.

References _acceptor.

39 {
40  delete _acceptor;
41 }
boost::asio::ip::tcp::acceptor * _acceptor

Member Function Documentation

void APIServerListener::HandleAccept ( std::tr1::shared_ptr< APIServerConnection connection)
private

Definition at line 53 of file APIServerListener.cpp.

References StartAccept().

Referenced by StartAccept().

54 {
55  connection->Process();
56  StartAccept();
57 }

Here is the call graph for this function:

Here is the caller graph for this function:

void APIServerListener::StartAccept ( )
private

Definition at line 43 of file APIServerListener.cpp.

References _acceptor, APIServerConnection::create(), and HandleAccept().

Referenced by APIServerListener(), and HandleAccept().

44 {
45  boost::asio::executor e = _acceptor->get_executor();
46  boost::asio::execution_context &e_context = e.context();
47  boost::asio::io_context &context_instance = static_cast<boost::asio::io_context&>(e_context);
48 
49  std::tr1::shared_ptr<APIServerConnection> connection = APIServerConnection::create(context_instance);
50  _acceptor->async_accept(connection->socket(), std::bind(&APIServerListener::HandleAccept, this, connection));
51 }
static std::tr1::shared_ptr< APIServerConnection > create(boost::asio::io_context &io)
void HandleAccept(std::tr1::shared_ptr< APIServerConnection > connection)
boost::asio::ip::tcp::acceptor * _acceptor

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

boost::asio::ip::tcp::acceptor* APIServerListener::_acceptor
private

Definition at line 51 of file APIServerListener.h.

Referenced by APIServerListener(), StartAccept(), and ~APIServerListener().


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