gloox  1.0.28
Public Member Functions | List of all members
ConnectionTCPBase Class Reference

#include <connectiontcpbase.h>

Inheritance diagram for ConnectionTCPBase:
Inheritance graph
[legend]

Public Member Functions

 ConnectionTCPBase (const LogSink &logInstance, const std::string &server, int port=-1)
 
 ConnectionTCPBase (ConnectionDataHandler *cdh, const LogSink &logInstance, const std::string &server, int port=-1)
 
virtual ~ConnectionTCPBase ()
 
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)
 
int socket () const
 
void setSocket (int socket)
 
virtual int localPort () const
 
virtual const std::string localInterface () const
 
- Public Member Functions inherited from ConnectionBase
 ConnectionBase (ConnectionDataHandler *cdh)
 
virtual ~ConnectionBase ()
 
virtual ConnectionError connect ()=0
 
virtual ConnectionError recv (int timeout=-1)=0
 
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 ConnectionBasenewInstance () const =0
 

Additional Inherited Members

- Protected Attributes inherited from ConnectionBase
ConnectionDataHandlerm_handler
 
ConnectionState m_state
 
std::string m_server
 
int m_port
 

Detailed Description

This is a base class for a simple TCP 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 44 of file connectiontcpbase.h.

Constructor & Destructor Documentation

◆ ConnectionTCPBase() [1/2]

ConnectionTCPBase ( 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.

Definition at line 53 of file connectiontcpbase.cpp.

◆ ConnectionTCPBase() [2/2]

ConnectionTCPBase ( 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.

Definition at line 62 of file connectiontcpbase.cpp.

◆ ~ConnectionTCPBase()

~ConnectionTCPBase ( )
virtual

Virtual destructor

Definition at line 79 of file connectiontcpbase.cpp.

Member Function Documentation

◆ cleanup()

void cleanup ( )
virtual

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

Reimplemented from ConnectionBase.

Definition at line 167 of file connectiontcpbase.cpp.

◆ disconnect()

void disconnect ( )
virtual

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

Implements ConnectionBase.

Definition at line 86 of file connectiontcpbase.cpp.

◆ getStatistics()

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

Returns current connection statistics.

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

Implements ConnectionBase.

Definition at line 161 of file connectiontcpbase.cpp.

◆ localInterface()

const std::string localInterface ( ) const
virtual

Returns the locally bound IP address.

Returns
The locally bound IP address.

Reimplemented from ConnectionBase.

Definition at line 203 of file connectiontcpbase.cpp.

◆ localPort()

int localPort ( ) const
virtual

Returns the local port.

Returns
The local port.

Reimplemented from ConnectionBase.

Definition at line 193 of file connectiontcpbase.cpp.

◆ receive()

ConnectionError receive ( )
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.

Implements ConnectionBase.

Definition at line 112 of file connectiontcpbase.cpp.

◆ send()

bool send ( const std::string &  data)
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.

Implements ConnectionBase.

Definition at line 123 of file connectiontcpbase.cpp.

◆ setSocket()

void setSocket ( int  socket)
inline

This function allows to set an existing socket with an established connection to use in this connection. You will still need to call connect() in order to negotiate the XMPP stream. You should not set a new socket after having called connect().

Parameters
socketThe existing socket.

Definition at line 103 of file connectiontcpbase.h.

◆ socket()

int socket ( ) const
inline

Gives access to the raw socket of this connection. Use it wisely. You can select()/poll() it and use ConnectionTCPBase::recv( -1 ) to fetch the data.

Returns
The socket of the active connection, or -1 if no connection is established.

Definition at line 95 of file connectiontcpbase.h.


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