gloox  1.0.28
Public Member Functions | Protected Attributes | List of all members
ConnectionBase Class Referenceabstract

#include <connectionbase.h>

Inheritance diagram for ConnectionBase:
Inheritance graph
[legend]

Public Member Functions

 ConnectionBase (ConnectionDataHandler *cdh)
 
virtual ~ConnectionBase ()
 
virtual ConnectionError connect ()=0
 
virtual ConnectionError recv (int timeout=-1)=0
 
virtual bool send (const std::string &data)=0
 
virtual ConnectionError receive ()=0
 
virtual void disconnect ()=0
 
virtual void cleanup ()
 
ConnectionState state () const
 
void registerConnectionDataHandler (ConnectionDataHandler *cdh)
 
void setServer (const std::string &server, int port=-1)
 
const std::string & server () const
 
int port () const
 
virtual int localPort () const
 
virtual const std::string localInterface () const
 
virtual void getStatistics (long int &totalIn, long int &totalOut)=0
 
virtual ConnectionBasenewInstance () const =0
 

Protected Attributes

ConnectionDataHandlerm_handler
 
ConnectionState m_state
 
std::string m_server
 
int m_port
 

Detailed Description

An abstract base class for a connection.

You should not need to use this class directly.

Author
Jakob Schröter js@ca.nosp@m.maya.nosp@m..net
Since
0.9

Definition at line 34 of file connectionbase.h.

Constructor & Destructor Documentation

◆ ConnectionBase()

Constructor.

Parameters
cdhAn object derived from ConnectionDataHandler that will receive received data.

Definition at line 42 of file connectionbase.h.

◆ ~ConnectionBase()

virtual ~ConnectionBase ( )
inlinevirtual

Virtual destructor.

Definition at line 49 of file connectionbase.h.

Member Function Documentation

◆ cleanup()

virtual void cleanup ( )
inlinevirtual

This function is called after a disconnect to clean up internal state. It is also called by ConnectionBase's destructor.

Reimplemented in ConnectionTLS, ConnectionTCPBase, ConnectionSOCKS5Proxy, ConnectionHTTPProxy, and ConnectionBOSH.

Definition at line 89 of file connectionbase.h.

◆ connect()

virtual ConnectionError connect ( )
pure virtual

Used to initiate the connection.

Returns
Returns the connection state.

Implemented in ConnectionTLS, ConnectionTCPServer, ConnectionTCPClient, ConnectionSOCKS5Proxy, ConnectionHTTPProxy, and ConnectionBOSH.

◆ disconnect()

virtual void disconnect ( )
pure virtual

Disconnects an established connection. NOOP if no active connection exists.

Implemented in ConnectionTLS, ConnectionTCPBase, ConnectionSOCKS5Proxy, ConnectionHTTPProxy, and ConnectionBOSH.

◆ getStatistics()

virtual void getStatistics ( long int &  totalIn,
long int &  totalOut 
)
pure virtual

Returns current connection statistics.

Parameters
totalInThe total number of bytes received.
totalOutThe total number of bytes sent.

Implemented in ConnectionTLS, ConnectionTCPBase, ConnectionSOCKS5Proxy, ConnectionHTTPProxy, and ConnectionBOSH.

◆ localInterface()

virtual const std::string localInterface ( ) const
inlinevirtual

Returns the locally bound IP address.

Returns
The locally bound IP address.

Reimplemented in ConnectionTCPBase.

Definition at line 133 of file connectionbase.h.

◆ localPort()

virtual int localPort ( ) const
inlinevirtual

Returns the local port.

Returns
The local port.

Reimplemented in ConnectionTCPBase.

Definition at line 127 of file connectionbase.h.

◆ newInstance()

virtual ConnectionBase* newInstance ( ) const
pure virtual

This function returns a new instance of the current ConnectionBase-derived object. The idea is to be able to 'clone' ConnectionBase-derived objects without knowing of what type they are exactly.

Returns
A new Connection* instance.

Implemented in ConnectionTLSServer, ConnectionTLS, ConnectionTCPServer, ConnectionTCPClient, ConnectionSOCKS5Proxy, ConnectionHTTPProxy, and ConnectionBOSH.

◆ port()

int port ( ) const
inline

Returns the currently set port.

Returns
The server port.

Definition at line 121 of file connectionbase.h.

◆ receive()

virtual ConnectionError receive ( )
pure virtual

Use this function to put the connection into 'receive mode', i.e. this function returns only when the connection is terminated.

Returns
Returns a value indicating the disconnection reason.

Implemented in ConnectionTLS, ConnectionTCPBase, ConnectionSOCKS5Proxy, ConnectionHTTPProxy, and ConnectionBOSH.

◆ recv()

virtual ConnectionError recv ( int  timeout = -1)
pure virtual

Use this periodically to receive data from the socket.

Parameters
timeoutThe timeout to use for select in microseconds. Default of -1 means blocking.
Returns
The state of the connection.

Implemented in ConnectionTLS, ConnectionTCPServer, ConnectionTCPClient, ConnectionSOCKS5Proxy, ConnectionHTTPProxy, and ConnectionBOSH.

◆ registerConnectionDataHandler()

void registerConnectionDataHandler ( ConnectionDataHandler cdh)
inline

Use this function to register a new ConnectionDataHandler. There can be only one ConnectionDataHandler at any one time.

Parameters
cdhThe new ConnectionDataHandler.

Definition at line 102 of file connectionbase.h.

◆ send()

virtual bool send ( const std::string &  data)
pure virtual

Use this function to send a string of data over the wire. The function returns only after all data has been sent.

Parameters
dataThe data to send.
Returns
True if the data has been sent (no guarantee of receipt), false in case of an error.

Implemented in ConnectionTLS, ConnectionTCPBase, ConnectionSOCKS5Proxy, ConnectionHTTPProxy, and ConnectionBOSH.

◆ server()

const std::string& server ( ) const
inline

Returns the currently set server/IP.

Returns
The server host/IP.

Definition at line 115 of file connectionbase.h.

◆ setServer()

void setServer ( const std::string &  server,
int  port = -1 
)
inline

Sets the server to connect to.

Parameters
serverThe server to connect to. Either IP or fully qualified domain name.
portThe port to connect to.

Definition at line 109 of file connectionbase.h.

◆ state()

ConnectionState state ( ) const
inline

Returns the current connection state.

Returns
The state of the connection.

Definition at line 95 of file connectionbase.h.

Member Data Documentation

◆ m_handler

ConnectionDataHandler* m_handler
protected

A handler for incoming data and connect/disconnect events.

Definition at line 152 of file connectionbase.h.

◆ m_port

int m_port
protected

Holds the port to connect to.

Definition at line 161 of file connectionbase.h.

◆ m_server

std::string m_server
protected

Holds the server's name/address.

Definition at line 158 of file connectionbase.h.

◆ m_state

ConnectionState m_state
protected

Holds the current connection state.

Definition at line 155 of file connectionbase.h.


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