Otclient  14/8/2020
Connection Class Reference

#include <connection.h>

Inheritance diagram for Connection:
Collaboration diagram for Connection:

Public Member Functions

 Connection ()
 
 ~Connection ()
 
void connect (const std::string &host, uint16 port, const std::function< void()> &connectCallback)
 
void close ()
 
void write (uint8 *buffer, size_t size)
 
void read (uint16 bytes, const RecvCallback &callback)
 
void read_until (const std::string &what, const RecvCallback &callback)
 
void read_some (const RecvCallback &callback)
 
void setErrorCallback (const ErrorCallback &errorCallback)
 
int getIp ()
 
boost::system::error_code getError ()
 
bool isConnecting ()
 
bool isConnected ()
 
ticks_t getElapsedTicksSinceLastRead ()
 
ConnectionPtr asConnection ()
 
- Public Member Functions inherited from LuaObject
 LuaObject ()
 
virtual ~LuaObject ()
 
template<typename T >
void connectLuaField (const std::string &field, const std::function< T > &f, bool pushFront=false)
 
template<typename... T>
int luaCallLuaField (const std::string &field, const T &... args)
 
template<typename R , typename... T>
callLuaField (const std::string &field, const T &... args)
 
template<typename... T>
void callLuaField (const std::string &field, const T &... args)
 
bool hasLuaField (const std::string &field)
 Returns true if the lua field exists. More...
 
template<typename T >
void setLuaField (const std::string &key, const T &value)
 Sets a field in this lua object. More...
 
template<typename T >
getLuaField (const std::string &key)
 Gets a field from this lua object. More...
 
void releaseLuaFieldsTable ()
 Release fields table reference. More...
 
void luaSetField (const std::string &key)
 Sets a field from this lua object, the value must be on the stack. More...
 
void luaGetField (const std::string &key)
 Gets a field from this lua object, the result is pushed onto the stack. More...
 
void luaGetMetatable ()
 Get object's metatable. More...
 
void luaGetFieldsTable ()
 Gets the table containing all stored fields of this lua object, the result is pushed onto the stack. More...
 
int getUseCount ()
 
std::string getClassName ()
 Returns the derived class name, its the same name used in Lua. More...
 
LuaObjectPtr asLuaObject ()
 
void operator= (const LuaObject &)
 
- Public Member Functions inherited from stdext::shared_object
 shared_object ()
 
virtual ~shared_object ()
 
void add_ref ()
 
void dec_ref ()
 
refcount_t ref_count ()
 
template<typename T >
stdext::shared_object_ptr< T > static_self_cast ()
 
template<typename T >
stdext::shared_object_ptr< T > dynamic_self_cast ()
 
template<typename T >
stdext::shared_object_ptr< T > const_self_cast ()
 

Static Public Member Functions

static void poll ()
 
static void terminate ()
 

Protected Member Functions

void internal_connect (asio::ip::basic_resolver< asio::ip::tcp >::iterator endpointIterator)
 
void internal_write ()
 
void onResolve (const boost::system::error_code &error, asio::ip::tcp::resolver::iterator endpointIterator)
 
void onConnect (const boost::system::error_code &error)
 
void onCanWrite (const boost::system::error_code &error)
 
void onWrite (const boost::system::error_code &error, size_t writeSize, std::shared_ptr< asio::streambuf > outputStream)
 
void onRecv (const boost::system::error_code &error, size_t recvSize)
 
void onTimeout (const boost::system::error_code &error)
 
void handleError (const boost::system::error_code &error)
 

Protected Attributes

std::function< void()> m_connectCallback
 
ErrorCallback m_errorCallback
 
RecvCallback m_recvCallback
 
asio::deadline_timer m_readTimer
 
asio::deadline_timer m_writeTimer
 
asio::deadline_timer m_delayedWriteTimer
 
asio::ip::tcp::resolver m_resolver
 
asio::ip::tcp::socket m_socket
 
std::shared_ptr< asio::streambuf > m_outputStream
 
asio::streambuf m_inputStream
 
bool m_connected
 
bool m_connecting
 
boost::system::error_code m_error
 
stdext::timer m_activityTimer
 

Static Protected Attributes

static std::list< std::shared_ptr< asio::streambuf > > m_outputStreams
 

Friends

class Server
 

Detailed Description

Definition at line 31 of file connection.h.

Constructor & Destructor Documentation

◆ Connection()

Connection::Connection ( )

Definition at line 34 of file connection.cpp.

◆ ~Connection()

Connection::~Connection ( )

Definition at line 45 of file connection.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ asConnection()

ConnectionPtr Connection::asConnection ( )
inline

Definition at line 66 of file connection.h.

Here is the caller graph for this function:

◆ close()

void Connection::close ( )

Definition at line 66 of file connection.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect()

void Connection::connect ( const std::string &  host,
uint16  port,
const std::function< void()> &  connectCallback 
)

Definition at line 93 of file connection.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getElapsedTicksSinceLastRead()

ticks_t Connection::getElapsedTicksSinceLastRead ( )
inline

Definition at line 64 of file connection.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getError()

boost::system::error_code Connection::getError ( )
inline

Definition at line 61 of file connection.h.

◆ getIp()

int Connection::getIp ( )

Definition at line 309 of file connection.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleError()

void Connection::handleError ( const boost::system::error_code &  error)
protected

Definition at line 297 of file connection.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ internal_connect()

void Connection::internal_connect ( asio::ip::basic_resolver< asio::ip::tcp >::iterator  endpointIterator)
protected

Definition at line 108 of file connection.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ internal_write()

void Connection::internal_write ( )
protected

Definition at line 140 of file connection.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isConnected()

bool Connection::isConnected ( )
inline

Definition at line 63 of file connection.h.

Here is the caller graph for this function:

◆ isConnecting()

bool Connection::isConnecting ( )
inline

Definition at line 62 of file connection.h.

Here is the caller graph for this function:

◆ onCanWrite()

void Connection::onCanWrite ( const boost::system::error_code &  error)
protected

Definition at line 241 of file connection.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onConnect()

void Connection::onConnect ( const boost::system::error_code &  error)
protected

Definition at line 218 of file connection.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onRecv()

void Connection::onRecv ( const boost::system::error_code &  error,
size_t  recvSize 
)
protected

Definition at line 267 of file connection.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onResolve()

void Connection::onResolve ( const boost::system::error_code &  error,
asio::ip::tcp::resolver::iterator  endpointIterator 
)
protected

Definition at line 205 of file connection.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onTimeout()

void Connection::onTimeout ( const boost::system::error_code &  error)
protected

Definition at line 289 of file connection.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onWrite()

void Connection::onWrite ( const boost::system::error_code &  error,
size_t  writeSize,
std::shared_ptr< asio::streambuf >  outputStream 
)
protected

Definition at line 252 of file connection.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ poll()

void Connection::poll ( )
static

Definition at line 53 of file connection.cpp.

Here is the caller graph for this function:

◆ read()

void Connection::read ( uint16  bytes,
const RecvCallback &  callback 
)

Definition at line 157 of file connection.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_some()

void Connection::read_some ( const RecvCallback &  callback)

Definition at line 190 of file connection.cpp.

Here is the call graph for this function:

◆ read_until()

void Connection::read_until ( const std::string &  what,
const RecvCallback &  callback 
)

Definition at line 173 of file connection.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setErrorCallback()

void Connection::setErrorCallback ( const ErrorCallback &  errorCallback)
inline

Definition at line 58 of file connection.h.

Here is the caller graph for this function:

◆ terminate()

void Connection::terminate ( )
static

Definition at line 60 of file connection.cpp.

Here is the caller graph for this function:

◆ write()

void Connection::write ( uint8 buffer,
size_t  size 
)

Definition at line 117 of file connection.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ Server

friend class Server
friend

Definition at line 97 of file connection.h.

Member Data Documentation

◆ m_activityTimer

stdext::timer Connection::m_activityTimer
protected

Definition at line 95 of file connection.h.

◆ m_connectCallback

std::function<void()> Connection::m_connectCallback
protected

Definition at line 79 of file connection.h.

◆ m_connected

bool Connection::m_connected
protected

Definition at line 92 of file connection.h.

◆ m_connecting

bool Connection::m_connecting
protected

Definition at line 93 of file connection.h.

◆ m_delayedWriteTimer

asio::deadline_timer Connection::m_delayedWriteTimer
protected

Definition at line 85 of file connection.h.

◆ m_error

boost::system::error_code Connection::m_error
protected

Definition at line 94 of file connection.h.

◆ m_errorCallback

ErrorCallback Connection::m_errorCallback
protected

Definition at line 80 of file connection.h.

◆ m_inputStream

asio::streambuf Connection::m_inputStream
protected

Definition at line 91 of file connection.h.

◆ m_outputStream

std::shared_ptr<asio::streambuf> Connection::m_outputStream
protected

Definition at line 90 of file connection.h.

◆ m_outputStreams

std::list< std::shared_ptr< asio::streambuf > > Connection::m_outputStreams
staticprotected

Definition at line 89 of file connection.h.

◆ m_readTimer

asio::deadline_timer Connection::m_readTimer
protected

Definition at line 83 of file connection.h.

◆ m_recvCallback

RecvCallback Connection::m_recvCallback
protected

Definition at line 81 of file connection.h.

◆ m_resolver

asio::ip::tcp::resolver Connection::m_resolver
protected

Definition at line 86 of file connection.h.

◆ m_socket

asio::ip::tcp::socket Connection::m_socket
protected

Definition at line 87 of file connection.h.

◆ m_writeTimer

asio::deadline_timer Connection::m_writeTimer
protected

Definition at line 84 of file connection.h.


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