My Project
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ParaEngine::CNPLTCPConnection Class Reference

boost::asio is used for NPL jabber client's tcp connections. More...

#include <NPL_TCPConnection.h>

Inheritance diagram for ParaEngine::CNPLTCPConnection:

Public Types

typedef CParaRingBuffer< std::string > RingBuffer_Type
 

Public Member Functions

 CNPLTCPConnection (boost::asio::io_service &io_service, const LogSink &logInstance, const std::string &server, int port=-1)
 Constructs a new ConnectionTCPBase object. More...
 
 CNPLTCPConnection (boost::asio::io_service &io_service, ConnectionDataHandler *cdh, const LogSink &logInstance, const std::string &server, int port=-1)
 Constructs a new ConnectionTCPBase object. More...
 
virtual ~CNPLTCPConnection ()
 Virtual destructor.
 
virtual bool send (const std::string &data)
 
virtual ConnectionError receive ()
 
virtual void disconnect ()
 
virtual void cleanup ()
 
virtual void getStatistics (long int &totalIn, long int &totalOut)
 
virtual ConnectionError recv (int timeout=-1)
 
virtual ConnectionError connect ()
 
virtual ConnectionBase * newInstance () const
 
void NotifyDisconnect (ConnectionError error)
 this function can be called from the io thread to notify disconnection in the main thread. More...
 
bool HasNotification ()
 whether we have notification messages to send. More...
 
int HandleNotification ()
 handle all notifications. More...
 
void Reset (const std::string &server, int port)
 reset this tcp connection such as changing server and port. More...
 

Protected Member Functions

void handle_resolve (const boost::system::error_code &err, tcp::resolver::iterator endpoint_iterator)
 
void handle_connect (const boost::system::error_code &error, tcp::resolver::iterator endpoint_iterator)
 
void handle_read (const boost::system::error_code &error, std::size_t bytes_transferred)
 
void handle_write (const boost::system::error_code &error)
 
void handle_disconnect ()
 
CNPLTCPConnectionoperator= (const CNPLTCPConnection &)
 
void init (const std::string &server, int port)
 

Protected Attributes

const LogSink & m_logInstance
 
char * m_buf
 
const int m_bufsize
 
long int m_totalBytesIn
 
long int m_totalBytesOut
 
std::string m_strPort
 
tcp::socket m_socket
 
tcp::resolver m_resolver
 
boost::asio::io_service * m_pIOService
 dispatcher IO service object for the connection socket. More...
 
bool m_bNotifyDisconnect
 true to notify disconnection
 
ConnectionError m_nDisconnectError
 disconnection error message. More...
 
ParaEngine::mutex m_mutex
 
RingBuffer_Type m_queueOutput
 the output message queue. More...
 
RingBuffer_Type m_queueInput
 the input message queue. More...
 

Detailed Description

boost::asio is used for NPL jabber client's tcp connections.

all NPL_TCPConnection (s) share a single dispatcher io service(one background thread) for DNS resolve, socket connections, and all send and receive message dispatching f.

Constructor & Destructor Documentation

§ CNPLTCPConnection() [1/2]

CNPLTCPConnection::CNPLTCPConnection ( boost::asio::io_service &  io_service,
const LogSink &  logInstance,
const std::string &  server,
int  port = -1 
)

Constructs a new ConnectionTCPBase object.

Parameters
logInstanceThe log target. Obtain it from ClientBase::logInstance().
serverA server to connect to.
portThe port to connect to. The default of -1 means that XMPP SRV records will be used to find out about the actual host:port.
Note
To properly use this object, you have to set a ConnectionDataHandler using registerConnectionDataHandler(). This is not necessary if this object is part of a 'connection chain', e.g. with ConnectionHTTPProxy.

§ CNPLTCPConnection() [2/2]

CNPLTCPConnection::CNPLTCPConnection ( boost::asio::io_service &  io_service,
ConnectionDataHandler *  cdh,
const LogSink &  logInstance,
const std::string &  server,
int  port = -1 
)

Constructs a new ConnectionTCPBase object.

Parameters
cdhAn ConnectionDataHandler-derived object that will handle incoming data.
logInstanceThe log target. Obtain it from ClientBase::logInstance().
serverA server to connect to.
portThe port to connect to. The default of -1 means that SRV records will be used to find out about the actual host:port.

Member Function Documentation

§ HandleNotification()

int CNPLTCPConnection::HandleNotification ( )

handle all notifications.

Returns
: the number of notifications returned.

§ HasNotification()

bool CNPLTCPConnection::HasNotification ( )

whether we have notification messages to send.

§ NotifyDisconnect()

void CNPLTCPConnection::NotifyDisconnect ( ConnectionError  error)

this function can be called from the io thread to notify disconnection in the main thread.

§ Reset()

void ParaEngine::CNPLTCPConnection::Reset ( const std::string &  server,
int  port 
)

reset this tcp connection such as changing server and port.

Member Data Documentation

§ m_nDisconnectError

ConnectionError ParaEngine::CNPLTCPConnection::m_nDisconnectError
protected

disconnection error message.

§ m_pIOService

boost::asio::io_service* ParaEngine::CNPLTCPConnection::m_pIOService
protected

dispatcher IO service object for the connection socket.

§ m_queueInput

RingBuffer_Type ParaEngine::CNPLTCPConnection::m_queueInput
protected

the input message queue.

a queue that is filled by incoming messages (the receiving thread) and processed by main thread at regular interval.

§ m_queueOutput

RingBuffer_Type ParaEngine::CNPLTCPConnection::m_queueOutput
protected

the output message queue.

a queue that is filled by the main thread and send out by a worker thread.


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